diff --git a/CHANGELOG.md b/CHANGELOG.md index aa8387ad7..c912cb6fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to Bambuddy will be documented in this file. ### Security - **Vite 7 → 8 major bump** — Bambuddy's frontend now builds with Vite 8 (`^7.3.2` → `^8.0.16`) and the matching plugin-react release (`@vitejs/plugin-react` `^5.1.1` → `^5.2.0`). Headline architectural change: Vite 8 swaps Rollup for **Rolldown** as the default bundler — same plugin contract, Rust-backed core, slightly different chunk layout / output bytes (no functional regression). The bump also lifts the transitive `esbuild` floor to 0.28.1, which closes the last open advisory in the audit chain. **Bambuddy-side surface audited:** `vite.config.ts` uses only stable contracts that survived the v8 cut — `defineConfig`, the `Connect` type, the custom `serveGcodeViewer` `configureServer` middleware plugin (proxies `/gcode-viewer/*` to the repo's sibling `gcode_viewer/` directory in dev), the `server.proxy` with WebSocket upgrade for `/api/v1/ws`, `build.outDir`/`emptyOutDir`/`chunkSizeWarningLimit`, and `resolve.alias` for `@`. `base: '/'` regression guard from #1221 is unaffected. No SSR, no library mode, no CSS preprocessors, no exotic plugins. `vitest@4.1.8` already accepts vite 8 in its peer range (`^6 || ^7 || ^8`); no test-runner bump required. **Node:** vite 8 requires `^20.19.0 || >=22.12.0`; CI Node 20.x line satisfies this. **What this is NOT:** plugin-react v6 — that line requires `babel-plugin-react-compiler` + `@rolldown/plugin-babel` as peers and is a separate scope. `npm run build`, `npm run lint`, `npx vitest run` all clean; `npm audit` clean. - **Frontend dependency bumps** — Routine version updates across the runtime, build, and test dependency surface. **Runtime:** `dompurify` 3.4.0 → 3.4.10. `package.json` floor raised from `^3.4.0` to `^3.4.10` so fresh installs cannot land on the deprecated 3.4.4 release. Three call sites use string-output sanitisation (`frontend/src/pages/MakerworldPage.tsx`, `frontend/src/pages/ProjectDetailPage.tsx`, `frontend/src/components/ProjectPageModal.tsx`); release notes 3.4.1 → 3.4.10 reviewed for behavioural changes — 3.4.4 widened the default allow-list with `selectedcontent` + `command` + `commandfor` (all valid modern HTML, harmless for our two default-allow-list call sites), and `ProjectPageModal` is unaffected anyway because it sets an explicit `ALLOWED_TAGS` / `ALLOWED_ATTR` whitelist. **Build / lint / test tooling (transitive, dev-only):** `@babel/core` 7.29.0 → 7.29.7 (pulled by `@vitejs/plugin-react` and `eslint-plugin-react-hooks`), `vite` 7.3.2 → 7.3.5, `markdown-it` 14.1.1 → 14.2.0 (pulled by `@tiptap/extension-link` → `@tiptap/pm` → `prosemirror-markdown`; Bambuddy never calls `markdown-it.render` directly so the change is transparent), `js-yaml` 4.1.1 → 4.2.0 (pulled by `eslint`), `form-data` 4.0.5 → 4.0.6 + `ws` 8.20.1 → 8.21.0 (both pulled by `jsdom` in the test runtime). All bumps inside existing semver ranges except `dompurify`. No source changes required. +- **`dompurify` 3.4.10 → 3.4.11** — Follow-up patch closes a moderate-severity advisory affecting `setConfig()` callers: the previous hook clone-guard added in 3.4.7 could be bypassed via `setConfig()`, leaving a permanent `ALLOWED_ATTR` pollution that the next `sanitize()` call inherited. **Bambuddy's exposure is nil** — `git grep DOMPurify.setConfig` returns zero hits across the entire codebase; all three sanitisation sites (`frontend/src/pages/MakerworldPage.tsx`, `frontend/src/pages/ProjectDetailPage.tsx`, `frontend/src/components/ProjectPageModal.tsx`) call `DOMPurify.sanitize(html)` or `DOMPurify.sanitize(html, {ALLOWED_TAGS, ALLOWED_ATTR})` directly, never through `setConfig()`. The bump is taken as defence-in-depth to keep XSS-sensitive surface area current and to silence `npm audit` so future audit-fix runs don't auto-bundle unintended changes. **Mechanical lockfile bump only:** the existing `^3.4.10` range already permitted 3.4.11, so `package.json` is unchanged; `package-lock.json` updates the resolved URL + integrity hash for the one entry. Verification: `npm audit` reports 0 vulnerabilities, `MakerworldPage.test.tsx`'s 12 DOMPurify sanitisation cases pass, `npm run build` clean. ### Added - **Centralised sidebar layout + per-page hide toggles (#1673, contributed by @EdwardChamberlain)** — Sidebar item ordering and visibility move from inline `Layout.tsx` state to a dedicated module so the same persistence rules apply whether the user is reordering with drag-and-drop, toggling an item off, or accepting the admin-pushed default. New `frontend/src/utils/sidebarLayout.ts` owns the localStorage round-trip (`sidebarOrder` + `sidebarHiddenSystemItems` keys), the `SIDEBAR_LAYOUT_CHANGED_EVENT` cross-tab refresh broadcast, and the `isExternalSidebarItemId` helper that distinguishes the new `ext-*` external link prefix from built-in nav. **Hide / show toggle:** every built-in sidebar entry (Printers / Inventory / Archives / Queue / Projects / File Manager / Makerworld / Profiles / Maintenance / Statistics — Settings is intentionally non-hideable) now carries an eye icon in the Sidebar settings card; click it to drop that entry from the rendered sidebar. Hidden IDs persist per-user via localStorage so personal taste survives reloads without leaking to other users on a shared install. Re-show by clicking the eye again. The previous drag-to-reorder UX is retired in this PR — the hide list + admin default order cover the same "I never use the Stats page" / "give me Files first" needs without the affordance ambiguity of the rearrange handle. **Admin default order:** new `default_sidebar_order` setting (validated server-side at `backend/app/schemas/settings.py:533+`) holds a JSON object `{order: string[], hiddenSystemItemIds: string[]}` that admins set once from Settings → General → Sidebar (Set Default toggle). On first login per user, `Layout.tsx`'s `useEffect` reads the admin default, filters it against the current `defaultNavItems` + valid external IDs (so a deleted external link or a removed built-in doesn't strand in someone's stored order), applies it locally, and records a per-user `sidebarDefaultApplied_` localStorage flag so the default is one-shot — later user-driven changes aren't clobbered on every login. **Settings card:** `ExternalLinksSettings.tsx` is the single source of truth for the Sidebar card (`card-sidebar-links`) in Settings → General. The header now carries the **Set Default** toggle (visible only when the caller holds `settings:write`), a **Reset** button (clears both `sidebarOrder` + `sidebarHiddenSystemItems` to defaults), and the **Add Link** button (opens the external-link create modal). The body lists every sidebar item — built-in or external — with the eye toggle inline on each row. The header row uses `flex-wrap` on the outer container and the right-side control group so the Add Link button doesn't overflow the card's right edge when Column 3 sits at its narrow `lg:max-w-sm` (384px) width. **Settings → General reordering (post-merge polish):** the **Updates** card moved to the top of Column 3 (above the new Sidebar card); the **Data Management** card moved to the bottom of Column 2 (after Library Auto-Purge) so the General tab balances better with the new Sidebar card taking column 3's vertical real estate. Anchor IDs `card-updates`, `card-data`, `card-sidebar-links` are preserved so deep-links + the in-app `registerSettingsSearch` index still resolve. **Layout merge edge case:** the PR's refactor of `Layout.tsx::isHidden` accidentally dropped the dev-side notifications gate (`!authEnabled || !advancedAuthStatus?.advanced_auth_enabled || settings?.user_notifications_enabled === false`) and its `advancedAuthStatus` useQuery. The merged shape keeps three gates in priority order — `hiddenSystemItemIds.includes(id)` first (cheapest, explicit user intent), then the array-aware `navPermissions` check from #1755 (granular `*:read_own` / `*:read_all` tiers), then the notifications-specific gate — so a user without advanced auth doesn't suddenly see the Notifications entry. **Backend:** `default_sidebar_order` settings field accepts both shapes (plain array OR `{order, hiddenSystemItemIds}` object) for backward compat with installs that saved an array under an earlier draft of this work. Validator rejects any `hiddenSystemItemIds` that isn't a `list[str]` with 422. **Tests:** 17 new backend cases in `test_sidebar_settings.py` pinning the validator (empty / JSON-array / JSON-object / mixed-types / hostile shapes). Frontend: 5 new `Layout.test.tsx` cases pinning the hide-toggle behaviour (hidden ID drops the entry, hidden ID for Settings is ignored — `settings` is non-hideable, eye-click round-trips through localStorage, `SIDEBAR_LAYOUT_CHANGED_EVENT` triggers a re-read across tabs) and 255 added/changed lines in `SettingsPage.test.tsx` covering the admin-default toggle and the eye-icon visibility column. **i18n:** new keys in the `externalLinks.*` namespace (sidebarLayout / sidebarLayoutDescription / visibleInSidebar / hiddenFromSidebar / requiredInSidebar / setDefault / etc.), full translations in all 10 non-en locales (de / es / fr / it / ja / ko / pt-BR / tr / zh-CN / zh-TW). Parity check 5168 leaves per locale. Vitest test timeout raised in `vitest.config.ts` to absorb the `userEvent.setup({delay: null})` cases in the heavier `SettingsPage` flows. Full vitest run green; ESLint clean; `npm run build` clean; ruff clean. diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 2bb94b0d1..7484d2d1a 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -4087,9 +4087,9 @@ "peer": true }, "node_modules/dompurify": { - "version": "3.4.10", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.10.tgz", - "integrity": "sha512-0xzNv0e7oYC6yyuOGZIABPM4qtg3QxLFniDNPP4ZP90wR8Yq3zgwpRbrNiT4N3IKqDbbYFEJLV+JWEs19aZ//w==", + "version": "3.4.11", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.4.11.tgz", + "integrity": "sha512-zhlUV12GsaRzMsf9q5M254YhA4+VuF0fG+QFqu6aYpoGlKtz+w8//jBcGVYBgQkR5GHjUomejY84AV+/uPbWdw==", "optionalDependencies": { "@types/trusted-types": "^2.0.7" } diff --git a/static/assets/index-CwNq-tBU.js b/static/assets/index-DG0IKlJR.js similarity index 99% rename from static/assets/index-CwNq-tBU.js rename to static/assets/index-DG0IKlJR.js index 73eecb5bf..5723b0faf 100644 --- a/static/assets/index-CwNq-tBU.js +++ b/static/assets/index-DG0IKlJR.js @@ -8538,8 +8538,8 @@ void main() { ${s} ${e?a:`bg-red-500/20 text-red-400 hover:bg-red-500/30`} `,title:F(`printers:control`)?j(`printers.stop`):j(`printers.permission.noControl`),children:[(0,G.jsx)(eu,{className:`w-3 h-3`}),j(`printers.stop`)]})})()]})]})]})})(),(Yt?.length>0||W.vt_tray.length>0)&&r===`expanded`&&(()=>{let t=Yt.filter(e=>e.tray.length>1),n=Yt.filter(e=>e.tray.length===1),r=e.nozzle_count===2||W?.temperatures?.nozzle_2!==void 0,i=`min-w-14`,g=e=>{let t=Math.max(1,e),n=`calc(${t} * 3.5rem + ${Math.max(0,t-1)} * 0.25rem + 1rem)`;return{flex:`1 1 ${n}`,minWidth:n}};return(0,G.jsxs)(`div`,{className:`mt-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.filaments`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[t.map(t=>{let n=qt[String(t.id)],_=t.id>=128?t.id-128:t.id,v=n===void 0?_:n,y=v===1,b=v===0;return(0,G.jsxs)(`div`,{style:g(4),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex w-full min-h-7 items-center justify-between gap-2 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,G.jsx)(Kq,{ams:t,printerId:e.id,label:Lq(t.id,t.tray.length),amsLabels:zt,canEdit:F(`printers:update`),onSaved:Bt,children:(0,G.jsx)(`span`,{className:`block truncate text-[10px] text-white font-medium cursor-default select-none`,children:zt?.[t.id]||Lq(t.id,t.tray.length)})}),r&&(y||b)&&(0,G.jsx)(Aq,{side:y?`L`:`R`})]}),(t.humidity!=null||t.temp!=null)&&(0,G.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1.5`,children:[t.humidity!=null&&(0,G.jsx)(Fq,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>lt({amsId:t.id,amsLabel:Lq(t.id,t.tray.length),mode:`humidity`}),compact:!0}),t.temp!=null&&(0,G.jsx)(`div`,{className:`mr-1`,children:(0,G.jsx)(Iq,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>lt({amsId:t.id,amsLabel:Lq(t.id,t.tray.length),mode:`temperature`}),compact:!0})}),W.supports_drying&&(t.module_type===`n3f`||t.module_type===`n3s`)&&F(`printers:control`)&&(0,G.jsx)(`button`,{disabled:!!(t.dry_sf_reason?.length&&t.dry_time===0),onClick:e=>{if(t.dry_time>0)wn.mutate(t.id);else if(Ve===t.id)He(null);else{let n=(t.tray.find(e=>e.tray_type)?.tray_type||`PLA`).split(` `)[0].toUpperCase(),r=x[n]||x.PLA,i=t.module_type;Ke(n),Je(r[i]||r.n3f),Xe(i===`n3s`?r.n3s_hours:r.n3f_hours),Qe(!1),We(t.module_type),He(t.id),tt(Uf({triggerRect:e.currentTarget.getBoundingClientRect(),popoverWidth:Dq,estimatedHeight:Oq,horizontalAlign:`center`}))}},className:`ml-1 flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] transition-colors ${t.dry_time>0?`bg-amber-500/20 text-amber-400`:t.dry_sf_reason?.length?`bg-bambu-dark text-bambu-gray/50 cursor-not-allowed`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:t.dry_time>0?j(`printers.drying.stop`):t.dry_sf_reason?.length?j(`printers.drying.powerRequired`):j(`printers.drying.start`),children:(0,G.jsx)(ec,{className:`w-3 h-3`})})]})]}),t.dry_time>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-amber-500/10 px-2 py-1 text-[9px]`,children:[(0,G.jsx)(ec,{className:`w-3 h-3 text-amber-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-amber-400 font-medium`,children:j(`printers.drying.active`)}),(0,G.jsx)(`span`,{className:`text-amber-300/70`,children:j(`printers.drying.timeRemaining`,{time:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`})}),(0,G.jsx)(`button`,{onClick:()=>wn.mutate(t.id),disabled:wn.isPending,className:`ml-auto text-amber-400 hover:text-amber-300 transition-colors disabled:opacity-50`,title:j(`printers.drying.stop`),children:(0,G.jsx)(Nu,{className:`w-3 h-3`})})]}),(0,G.jsx)(`div`,{className:`grid w-full grid-cols-[repeat(4,minmax(3.5rem,1fr))] gap-1`,children:[0,1,2,3].map(r=>{let a=t.tray[r]||t.tray.find(e=>e.id===r),g=a?.tray_type&&a.remain>=0,_=!a?.tray_type,v=Rq(a),y=t.id*4+r,b=Qt===y,x=a?.tray_info_idx?Pt?.[a.tray_info_idx]:null,S=Ft?.[y],C=(a?.tray_uuid||a?.tag_uid||lq(e.serial_number,t.id,r))?.toUpperCase(),w=C?s?.[C]:void 0,T=sq(w),E=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===r):void 0,D=E?f?.find(e=>e.id===E.spoolman_spool_id):void 0,O=D&&(D.label_weight??0)>0?Math.round(Math.max(0,(D.label_weight??0)-D.weight_used)/(D.label_weight??1)*100):null,k=u?.(e.id,t.id,r),A=(()=>{let e=k?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),M=A===0&&g&&a.remain>0?null:A,N=T??O??M??(g?a.remain:null),P=T!==null||O!==null?`spoolman`:M===null?g?`ams`:void 0:`inventory`,I=a?.tray_type?{vendor:fq(a)?`Bambu Lab`:`Generic`,profile:S?.preset_name||(D?[D.brand,D.slicer_filament_name?.split(`@`)[0].trim()||D.material].filter(Boolean).join(` `).trim():null)||k?.spool?.slicer_filament_name||x?.name||a.tray_sub_brands||a.tray_type,colorName:zd(a.tray_color||``),colorHex:a.tray_color||null,kFactor:kq(a.k),fillLevel:N,trayUuid:a.tray_uuid||null,tagUid:a.tag_uid||null,fillSource:P}:null,L=qn?.amsId===t.id&&qn?.slotId===r,R=(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${_?`opacity-50`:``} ${b?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,G.jsx)(Eq,{trayColor:a?.tray_color,trayType:a?.tray_type,isEmpty:_,emptyKind:v,slotNumber:r+1}),(0,G.jsx)(`div`,{className:`text-[9px] text-white font-bold truncate`,children:a?.tray_type||j(v===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:N!==null&&N>=0&&!_&&a&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${N}%`,backgroundColor:oq(N)}})})]});return(0,G.jsxs)(`div`,{className:`relative group w-full ${i}`,children:[L&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,G.jsx)(Cl,{className:`w-4 h-4 text-bambu-green animate-spin`})}),I?(0,G.jsx)(gK,{data:I,actions:Tr({amsId:t.id,slotId:r,loadTrayId:t.id*4+r,isRefreshing:L}),spoolman:{enabled:o,linkedSpoolId:E?.spoolman_spool_id??(C?s?.[C]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!E&&!k?()=>{let n=(I.trayUuid||I.tagUid||lq(e.serial_number,t.id,r)).toUpperCase();dt({tagUid:I.tagUid||n,trayUuid:I.trayUuid||``,printerId:e.id,amsId:t.id,trayId:r})}:void 0,onUnlinkSpool:w?.id?()=>Sn.mutate(w.id):void 0},inventory:(()=>{if(o){if(m)return;let n=E,i=D;return{assignedSpool:i?{id:i.id,material:i.material,brand:i.brand??null,color_name:i.color_name??null,remainingWeightGrams:i.label_weight?Math.max(0,Math.round(i.label_weight-i.weight_used)):void 0}:null,onAssignSpool:()=>pt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:a?.tray_type||I.profile,material:a?.tray_type??void 0,profile:I.profile,color:I.colorHex||``,location:`${Lq(t.id,t.tray.length)} Slot ${r+1}`}}),onUnassignSpool:i&&!fq(a)?()=>h?.(i.id):void 0,isAssigned:!!n||fq(a)}}let n=u?.(e.id,t.id,r);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,brand:n.spool.brand,color_name:n.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>pt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:a?.tray_type||I.profile,material:a?.tray_type??void 0,profile:I.profile,color:I.colorHex||``,location:`${Lq(t.id,t.tray.length)} Slot ${r+1}`}}),onUnassignSpool:n&&!fq(a)?()=>d?.(e.id,t.id,r):void 0,isAssigned:!!n||fq(a)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:t.id,trayId:r,trayCount:t.tray.length,trayType:a?.tray_type||void 0,trayColor:a?.tray_color||void 0,traySubBrands:a?.tray_sub_brands||void 0,trayInfoIdx:a?.tray_info_idx||void 0,extruderId:n,caliIdx:a?.cali_idx,savedPresetId:S?.preset_id})},children:R}):(0,G.jsx)(_K,{kind:v??void 0,actions:Tr({amsId:t.id,slotId:r,loadTrayId:t.id*4+r,isRefreshing:L}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:t.id,trayId:r,trayCount:t.tray.length,extruderId:n})},onAssignSpool:()=>pt({printerId:e.id,amsId:t.id,trayId:r,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`${Lq(t.id,t.tray.length)} Slot ${r+1}`}}),children:R})]},r)})})]},t.id)}),n.map(t=>{let n=qt[String(t.id)],i=t.id>=128?t.id-128:t.id,g=n===void 0?i:n,_=g===1,v=g===0,y=t.tray[0],b=y?.tray_type&&y.remain>=0,S=!y?.tray_type,C=Rq(y),w=aq(t.id,y?.id??0,!1),T=Qt===w,E=y?.tray_info_idx?Pt?.[y.tray_info_idx]:null,D=Ft?.[w],O=y?.id??0,k=(y?.tray_uuid||y?.tag_uid||lq(e.serial_number,t.id,O))?.toUpperCase(),A=k?s?.[k]:void 0,M=sq(A),N=u?.(e.id,t.id,O),P=(()=>{let e=N?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),I=P===0&&b&&y.remain>0?null:P,L=o&&!m?p?.find(n=>n.printer_id===e.id&&n.ams_id===t.id&&n.tray_id===O):void 0,R=L?f?.find(e=>e.id===L.spoolman_spool_id):void 0,z=R&&(R.label_weight??0)>0?Math.round(Math.max(0,(R.label_weight??0)-R.weight_used)/(R.label_weight??1)*100):null,B=M??z??I??(b?y.remain:null),ee=M!==null||z!==null?`spoolman`:I===null?b?`ams`:void 0:`inventory`,te=y?.tray_type?{vendor:fq(y)?`Bambu Lab`:`Generic`,profile:D?.preset_name||(R?[R.brand,R.slicer_filament_name?.split(`@`)[0].trim()||R.material].filter(Boolean).join(` `).trim():null)||N?.spool?.slicer_filament_name||E?.name||y.tray_sub_brands||y.tray_type,colorName:zd(y.tray_color||``),colorHex:y.tray_color||null,kFactor:kq(y.k),fillLevel:B,trayUuid:y.tray_uuid||null,tagUid:y.tag_uid||null,fillSource:ee}:null,V=qn?.amsId===t.id&&qn?.slotId===O,ne=(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${S?`opacity-50`:``} ${T?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,G.jsx)(Eq,{trayColor:y?.tray_color,trayType:y?.tray_type,isEmpty:S,emptyKind:C,slotNumber:1}),(0,G.jsx)(`div`,{className:`text-[9px] text-white font-bold truncate`,children:y?.tray_type||j(C===`reset`?`ams.slotUnconfigured`:`ams.slotEmpty`)}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:B!==null&&B>=0&&!S&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${B}%`,backgroundColor:oq(B)}})})]});return(0,G.jsxs)(`div`,{style:{flex:`1 1 11rem`,minWidth:`11rem`},className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsxs)(`div`,{className:`flex w-full min-h-7 items-center gap-1.5 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[(0,G.jsx)(Kq,{ams:t,printerId:e.id,label:Lq(t.id,t.tray.length),amsLabels:zt,canEdit:F(`printers:update`),onSaved:Bt,children:(0,G.jsx)(`span`,{className:`block truncate text-[10px] text-white font-medium cursor-default select-none`,children:zt?.[t.id]||Lq(t.id,t.tray.length)})}),r&&(_||v)&&(0,G.jsx)(Aq,{side:_?`L`:`R`})]}),W.supports_drying&&(t.module_type===`n3f`||t.module_type===`n3s`)&&F(`printers:control`)&&(0,G.jsx)(`div`,{className:`relative ml-auto`,children:(0,G.jsx)(`button`,{onClick:e=>{if(t.dry_time>0)wn.mutate(t.id);else if(Ve===t.id)He(null);else{let n=(t.tray.find(e=>e.tray_type)?.tray_type||`PLA`).split(` `)[0].toUpperCase(),r=x[n]||x.PLA,i=t.module_type;Ke(n),Je(r[i]||r.n3f),Xe(i===`n3s`?r.n3s_hours:r.n3f_hours),Qe(!1),We(t.module_type),He(t.id),tt(Uf({triggerRect:e.currentTarget.getBoundingClientRect(),popoverWidth:Dq,estimatedHeight:Oq,horizontalAlign:`center`}))}},className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] transition-colors ${t.dry_time>0?`bg-amber-500/20 text-amber-400`:`bg-bambu-dark text-bambu-gray hover:text-white hover:bg-bambu-dark/80`}`,title:t.dry_time>0?j(`printers.drying.stop`):j(`printers.drying.start`),children:(0,G.jsx)(ec,{className:`w-3 h-3`})})})]}),t.dry_time>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5 overflow-hidden whitespace-nowrap rounded-lg bg-amber-500/10 px-2 py-1 text-[9px]`,children:[(0,G.jsx)(ec,{className:`w-3 h-3 text-amber-400 shrink-0`}),(0,G.jsx)(`span`,{className:`text-amber-300/70 text-[8px] truncate`,children:t.dry_time>=60?`${Math.floor(t.dry_time/60)}h ${t.dry_time%60}m`:`${t.dry_time}m`}),(0,G.jsx)(`button`,{onClick:()=>wn.mutate(t.id),disabled:wn.isPending,className:`ml-auto text-amber-400 hover:text-amber-300 transition-colors disabled:opacity-50 shrink-0`,title:j(`printers.drying.stop`),children:(0,G.jsx)(Nu,{className:`w-3 h-3`})})]}),(0,G.jsxs)(`div`,{className:`flex gap-1.5 max-[550px]:flex-col max-[550px]:items-start`,children:[(0,G.jsxs)(`div`,{className:`relative group min-w-14 flex-1`,children:[V&&(0,G.jsx)(`div`,{className:`absolute inset-0 bg-bambu-dark-tertiary/80 rounded flex items-center justify-center z-20`,children:(0,G.jsx)(Cl,{className:`w-4 h-4 text-bambu-green animate-spin`})}),te?(0,G.jsx)(gK,{data:te,actions:Tr({amsId:t.id,slotId:O,loadTrayId:t.id*4+O,isRefreshing:V}),spoolman:{enabled:o,linkedSpoolId:L?.spoolman_spool_id??(k?s?.[k]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!L&&!N?()=>{let n=(te.trayUuid||te.tagUid||lq(e.serial_number,t.id,O)).toUpperCase();dt({tagUid:te.tagUid||n,trayUuid:te.trayUuid||``,printerId:e.id,amsId:t.id,trayId:O})}:void 0,onUnlinkSpool:A?.id?()=>Sn.mutate(A.id):void 0},inventory:(()=>{if(o){if(m)return;let n=L,r=R;return{assignedSpool:r?{id:r.id,material:r.material,brand:r.brand??null,color_name:r.color_name??null,remainingWeightGrams:r.label_weight?Math.max(0,Math.round(r.label_weight-r.weight_used)):void 0}:null,onAssignSpool:()=>pt({printerId:e.id,amsId:t.id,trayId:O,trayInfo:{type:y?.tray_type||te.profile,material:y?.tray_type??void 0,profile:te.profile,color:te.colorHex||``,location:Lq(t.id,t.tray.length)}}),onUnassignSpool:r&&!fq(y)?()=>h?.(r.id):void 0,isAssigned:!!n||fq(y)}}let n=u?.(e.id,t.id,O);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,brand:n.spool.brand,color_name:n.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>pt({printerId:e.id,amsId:t.id,trayId:O,trayInfo:{type:y?.tray_type||te.profile,material:y?.tray_type??void 0,profile:te.profile,color:te.colorHex||``,location:Lq(t.id,t.tray.length)}}),onUnassignSpool:n&&!fq(y)?()=>d?.(e.id,t.id,O):void 0,isAssigned:!!n||fq(y)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:t.id,trayId:O,trayCount:t.tray.length,trayType:y?.tray_type||void 0,trayColor:y?.tray_color||void 0,traySubBrands:y?.tray_sub_brands||void 0,trayInfoIdx:y?.tray_info_idx||void 0,extruderId:n,caliIdx:y?.cali_idx,savedPresetId:D?.preset_id})},children:ne}):(0,G.jsx)(_K,{kind:C??void 0,actions:Tr({amsId:t.id,slotId:O,loadTrayId:t.id*4+O,isRefreshing:V}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:t.id,trayId:O,trayCount:t.tray.length,extruderId:n})},onAssignSpool:()=>pt({printerId:e.id,amsId:t.id,trayId:O,trayInfo:{type:``,material:void 0,profile:``,color:``,location:Lq(t.id,t.tray.length)}}),children:ne})]}),(t.humidity!=null||t.temp!=null)&&(0,G.jsxs)(`div`,{className:`flex flex-col justify-center gap-1 shrink-0 max-[550px]:w-full`,children:[t.temp!=null&&(0,G.jsx)(Iq,{temp:t.temp,goodThreshold:a?.tempGood,fairThreshold:a?.tempFair,onClick:()=>lt({amsId:t.id,amsLabel:Lq(t.id,t.tray.length),mode:`temperature`}),compact:!0}),t.humidity!=null&&(0,G.jsx)(Fq,{humidity:t.humidity,goodThreshold:a?.humidityGood,fairThreshold:a?.humidityFair,onClick:()=>lt({amsId:t.id,amsLabel:Lq(t.id,t.tray.length),mode:`humidity`}),compact:!0})]})]})]},t.id)}),W.vt_tray.length>0&&(0,G.jsxs)(`div`,{style:g(W.vt_tray.length),className:`min-w-0 p-2 bg-bambu-dark rounded-[10px] space-y-1`,children:[(0,G.jsx)(`div`,{className:`flex w-full min-h-7 items-center gap-1.5 rounded-lg bg-bambu-dark-secondary px-2 py-1`,children:(0,G.jsx)(`span`,{className:`block min-w-0 flex-1 truncate text-[10px] text-white font-medium`,children:j(`printers.external`)})}),(0,G.jsx)(`div`,{className:`grid w-full ${W.vt_tray.length>1?`grid-cols-[repeat(2,minmax(3.5rem,1fr))]`:`grid-cols-[minmax(3.5rem,1fr)]`} gap-1`,children:[...W.vt_tray].sort((e,t)=>(e.id??254)-(t.id??254)).map(t=>{let n=t.id??254,a=r&&Qt===254?n===254&&W.active_extruder===1||n===255&&W.active_extruder===0:Qt===n,g=n-254,_=r?j(n===254?`printers.extL`:`printers.extR`):``,v=t.tray_info_idx?Pt?.[t.tray_info_idx]:null,y=Ft?.[1020+g],b=(t.tray_uuid||t.tag_uid||lq(e.serial_number,255,g))?.toUpperCase(),x=b?s?.[b]:void 0,S=sq(x),C=u?.(e.id,255,g),w=(()=>{let e=C?.spool;return e&&e.label_weight>0&&e.weight_used!=null?Math.round(Math.max(0,e.label_weight-e.weight_used)/e.label_weight*100):null})(),T=t.tray_type&&t.remain>=0,E=w===0&&T&&t.remain>0?null:w,D=o&&!m?p?.find(t=>t.printer_id===e.id&&t.ams_id===255&&t.tray_id===g):void 0,O=D?f?.find(e=>e.id===D.spoolman_spool_id):void 0,k=O&&(O.label_weight??0)>0?Math.round(Math.max(0,(O.label_weight??0)-O.weight_used)/(O.label_weight??1)*100):null,A=S??k??E??(T?t.remain:null),M=S!==null||k!==null?`spoolman`:E===null?T?`ams`:void 0:`inventory`,N={vendor:fq(t)?`Bambu Lab`:`Generic`,profile:y?.preset_name||(O?[O.brand,O.slicer_filament_name?.split(`@`)[0].trim()||O.material].filter(Boolean).join(` `).trim():null)||C?.spool?.slicer_filament_name||v?.name||t.tray_sub_brands||t.tray_type||`Unknown`,colorName:zd(t.tray_color||``),colorHex:t.tray_color||null,kFactor:kq(t.k),fillLevel:A,trayUuid:t.tray_uuid||null,tagUid:t.tag_uid||null,fillSource:M},P=!t.tray_type,I=Rq(t),L=(0,G.jsxs)(`div`,{className:`w-full bg-bambu-dark-secondary rounded-lg p-1 text-center ${P?`opacity-50`:``} ${a?`ring-2 ring-bambu-green ring-offset-1 ring-offset-bambu-dark`:``}`,children:[(0,G.jsx)(Eq,{trayColor:t.tray_color,trayType:t.tray_type,isEmpty:P,emptyKind:I,slotNumber:g+1}),(0,G.jsx)(`div`,{className:`text-[9px] font-bold truncate ${P?`text-white/40`:`text-white`}`,children:t.tray_type||j(`ams.slotEmpty`)}),(0,G.jsx)(`div`,{className:`mt-1 h-1.5 bg-black/30 rounded-full overflow-hidden`,children:A!==null&&A>=0&&!P&&(0,G.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${A}%`,backgroundColor:oq(A)}})}),_&&(0,G.jsx)(`div`,{className:`text-[7px] text-white/40 mt-0.5 truncate`,children:_})]});return(0,G.jsx)(`div`,{className:`relative group w-full ${i}`,children:P?(0,G.jsx)(_K,{kind:I??void 0,actions:Tr({amsId:255,slotId:g,loadTrayId:n,includeRfid:!1}),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:255,trayId:g,trayCount:1,extruderId:r?+(n===254):void 0})},onAssignSpool:()=>pt({printerId:e.id,amsId:255,trayId:g,trayInfo:{type:``,material:void 0,profile:``,color:``,location:`External Slot ${g+1}`}}),children:L}):(0,G.jsx)(gK,{data:N,actions:Tr({amsId:255,slotId:g,loadTrayId:n,includeRfid:!1}),spoolman:{enabled:o,linkedSpoolId:D?.spoolman_spool_id??(b?s?.[b]?.id:void 0),spoolmanUrl:c,syncMode:l,onLinkSpool:o&&!D&&!C?()=>{let t=(N.trayUuid||N.tagUid||lq(e.serial_number,255,g)).toUpperCase();dt({tagUid:N.tagUid||t,trayUuid:N.trayUuid||``,printerId:e.id,amsId:255,trayId:g})}:void 0,onUnlinkSpool:x?.id?()=>Sn.mutate(x.id):void 0},inventory:(()=>{if(o){if(m)return;let n=D,r=O;return{assignedSpool:r?{id:r.id,material:r.material,brand:r.brand??null,color_name:r.color_name??null,remainingWeightGrams:r.label_weight?Math.max(0,Math.round(r.label_weight-r.weight_used)):void 0}:null,onAssignSpool:()=>pt({printerId:e.id,amsId:255,trayId:g,trayInfo:{type:t.tray_type||N.profile,material:t.tray_type??void 0,profile:N.profile,color:N.colorHex||``,location:_||j(`printers.external`)}}),onUnassignSpool:r&&!fq(t)?()=>h?.(r.id):void 0,isAssigned:!!n||fq(t)}}let n=u?.(e.id,255,g);return{assignedSpool:n?.spool?{id:n.spool.id,material:n.spool.material,brand:n.spool.brand,color_name:n.spool.color_name,remainingWeightGrams:Math.max(0,Math.round(n.spool.label_weight-n.spool.weight_used))}:null,onAssignSpool:()=>pt({printerId:e.id,amsId:255,trayId:g,trayInfo:{type:t.tray_type||N.profile,material:t.tray_type??void 0,profile:N.profile,color:N.colorHex||``,location:_||j(`printers.external`)}}),onUnassignSpool:n&&!fq(t)?()=>d?.(e.id,255,g):void 0,isAssigned:!!n||fq(t)}})(),configureSlot:{enabled:F(`printers:control`),onConfigure:()=>ht({amsId:255,trayId:g,trayCount:1,trayType:t.tray_type||void 0,trayColor:t.tray_color||void 0,traySubBrands:t.tray_sub_brands||void 0,trayInfoIdx:t.tray_info_idx||void 0,extruderId:r?+(n===254):void 0,caliIdx:t.cali_idx,savedPresetId:y?.preset_id})},children:L})},n)})})]})]})]})})()]}),r===`expanded`&&(0,G.jsxs)(`div`,{className:`mt-auto`,children:[$t&&(0,G.jsxs)(`div`,{className:`pt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-bambu-gray font-medium`,children:j(`printers.power`,`Power`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-[10px] bg-bambu-dark p-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 pl-1`,children:[(0,G.jsx)(Fu,{className:`w-4 h-4 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-sm text-white truncate`,children:$t.name}),(0,G.jsx)(`span`,{className:`px-1.5 py-0.5 rounded-full bg-bambu-dark-tertiary text-bambu-gray text-[10px] font-medium flex-shrink-0`,title:j(`smartPlugs.power`),children:tn?.energy?.power!==null&&tn?.energy?.power!==void 0?`${Math.round(tn.energy.power)}W`:`--`})]}),(0,G.jsx)(`div`,{className:`flex-1`}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>En.mutate(!$t.auto_off),disabled:En.isPending||$t.auto_off_executed||!F(`smart_plugs:control`),title:F(`smart_plugs:control`)?$t.auto_off_executed?j(`printers.autoOffExecuted`):j(`printers.autoOffAfterPrint`):j(`printers.permission.noSmartPlugControl`),className:`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-xs font-bold transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${F(`smart_plugs:control`)?$t.auto_off||$t.auto_off_executed?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/80`:`bg-bambu-dark-tertiary/50 text-bambu-gray/50`}`,children:(0,G.jsx)(_s,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:()=>{tn?.state===`ON`?se(!0):oe(!0)},disabled:Tn.isPending||!F(`smart_plugs:control`),className:`flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-lg text-xs transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${F(`smart_plugs:control`)?tn?.state===`ON`?`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30`:`bg-bambu-dark-tertiary text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/80`:`bg-bambu-dark-tertiary/50 text-bambu-gray/50`}`,title:F(`smart_plugs:control`)?tn?.state===`ON`?`Turn off`:`Turn on`:j(`printers.permission.noSmartPlugControl`),children:(0,G.jsx)(Fu,{className:`w-4 h-4`})})]})]}),en&&en.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mt-2`,children:[(0,G.jsx)(Tc,{className:`w-3.5 h-3.5 text-blue-400 flex-shrink-0`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`HA:`}),(0,G.jsx)(`div`,{className:`h-[2px] w-5 bg-bambu-dark-tertiary/50`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:en.map(e=>{let t=e.ha_entity_id?.startsWith(`script.`);return(0,G.jsxs)(`button`,{onClick:()=>{t?Dn.mutate({id:e.id,action:`on`}):le(e)},disabled:Dn.isPending,title:`${t?`Run`:`Toggle`} ${e.ha_entity_id}`,className:`px-2 py-0.5 text-xs bg-blue-500/20 text-blue-400 hover:bg-blue-500/30 rounded transition-colors flex items-center gap-1`,children:[(0,G.jsx)(hl,{className:`w-2.5 h-2.5`}),e.name]},e.id)})})]})]}),(0,G.jsxs)(`div`,{className:`pt-4`,children:[(0,G.jsx)(`div`,{className:`mb-3 h-[2px] bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[Er,(0,G.jsxs)(`div`,{className:`flex items-center justify-end gap-2 flex-wrap`,children:[(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{if(_===`embedded`&&v)v(e.id,e.name);else{let t=localStorage.getItem(`cameraWindowState`),n=t?JSON.parse(t):{width:640,height:400},r=[`width=${n.width}`,`height=${n.height}`,n.left===void 0?``:`left=${n.left}`,n.top===void 0?``:`top=${n.top}`,`menubar=no,toolbar=no,location=no,status=no`].filter(Boolean).join(`,`);window.open(`/camera/${e.id}`,`camera-${e.id}`,r)}},disabled:!W?.connected||!F(`camera:view`),title:F(`camera:view`)?j(_===`embedded`?`printers.openCameraOverlay`:`printers.openCameraWindow`):j(`printers.permission.noCamera`),className:wr,children:(0,G.jsx)(wu,{className:`w-4 h-4`})}),(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>re(!0),disabled:!Gt||!F(`printers:files`),title:F(`printers:files`)?j(`printers.browseFiles`):j(`printers.permission.noFiles`),className:wr,children:(0,G.jsx)(yc,{className:`w-4 h-4`})}),Gt&&W?.state!==`RUNNING`&&W?.state!==`PAUSE`&&(0,G.jsxs)(Q,{size:`sm`,onClick:()=>Ne(!0),disabled:!F(`printers:control`),title:F(`printers:control`)?j(`common.print`):j(`printers.permission.noControl`),className:`!h-8 !min-h-8 !px-2 !py-0 !bg-bambu-green hover:!bg-bambu-green/80 !text-white`,children:[(0,G.jsx)(bl,{className:`w-4 h-4`}),j(`common.print`)]})]})]})]})]})]}),ne&&(0,G.jsx)(nce,{printerId:e.id,printerName:e.name,onClose:()=>re(!1)}),Me&&(0,G.jsx)(ZK,{folderId:null,onClose:()=>Ne(!1),onUploadComplete:()=>{},autoUpload:!0,accept:`.gcode,.3mf`,validateFile:e=>{let t=e.name.toLowerCase();if(!t.endsWith(`.gcode`)&&!t.includes(`.gcode.`))return j(`printers.dropNotPrintable`,`Only .gcode and .gcode.3mf files can be printed`)},onFileUploaded:t=>{let n=t.metadata?.sliced_for_model,r=Gq(e.model);if(n&&r&&n.toLowerCase()!==r.toLowerCase())return Z.deleteLibraryFile(t.id).catch(()=>{}),j(`printers.incompatibleFile`,`This file was sliced for {{slicedFor}}, but this printer is a {{printerModel}}`,{slicedFor:n,printerModel:r});Be({id:t.id,filename:t.filename})}}),ze&&(0,G.jsx)(wq,{mode:`reprint`,libraryFileId:ze.id,archiveName:ze.filename,initialSelectedPrinterIds:[e.id],onClose:()=>Be(null),onSuccess:()=>Be(null),cleanupLibraryAfterDispatch:!0}),ie&&(0,G.jsx)(lce,{printerId:e.id,printerName:e.name,onClose:()=>H(!1)}),Ie&&(0,G.jsx)(gf,{printerId:e.id,printerName:e.name,onClose:()=>Le(!1)}),Pe&&(0,G.jsx)(_Te,{printer:e,status:W,totalPrintHours:n?.total_print_hours,onClose:Re}),vt&&(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,onClick:()=>lr(),children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl max-w-lg w-full`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[vt.needs_calibration?(0,G.jsx)(Al,{className:`w-5 h-5 text-blue-500`}):vt.is_empty?(0,G.jsx)(ls,{className:`w-5 h-5 text-green-500`}):(0,G.jsx)(ms,{className:`w-5 h-5 text-yellow-500`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`Build Plate Check`}),vt.reference_count!==void 0&&vt.max_references&&(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray bg-bambu-dark-tertiary px-2 py-1 rounded`,children:[vt.reference_count,`/`,vt.max_references,` refs`]})]}),(0,G.jsx)(`button`,{onClick:()=>lr(),className:`p-1 text-bambu-gray hover:text-white rounded transition-colors`,children:(0,G.jsx)(Nu,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[vt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 rounded-lg bg-blue-500/20 border border-blue-500/50`,children:[(0,G.jsx)(`p`,{className:`font-medium text-blue-400`,children:j(`printers.plateDetection.calibrationRequired`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,dangerouslySetInnerHTML:{__html:j(`printers.plateDetection.calibrationInstructions`)}})]}),(0,G.jsxs)(`div`,{className:`text-sm text-bambu-gray space-y-2`,children:[(0,G.jsx)(`p`,{children:j(`printers.plateDetection.calibrationDescription`)}),(0,G.jsx)(`p`,{dangerouslySetInnerHTML:{__html:j(`printers.plateDetection.calibrationTip`)}})]})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`p-3 rounded-lg ${vt.is_empty?`bg-green-500/20 border border-green-500/50`:`bg-yellow-500/20 border border-yellow-500/50`}`,children:[(0,G.jsx)(`p`,{className:`font-medium ${vt.is_empty?`text-green-400`:`text-yellow-400`}`,children:vt.is_empty?j(`printers.plateDetection.plateEmpty`):j(`printers.plateDetection.objectsDetected`)}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:[j(`printers.plateDetection.confidence`),`: `,Math.round(vt.confidence*100),`% | `,j(`printers.plateDetection.difference`),`: `,vt.difference_percent.toFixed(1),`%`]})]}),vt.debug_image_url&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-2`,children:j(`printers.plateDetection.analysisPreview`)}),(0,G.jsx)(`img`,{src:vt.debug_image_url,alt:j(`printers.plateDetection.analysisPreview`),className:`w-full rounded-lg border border-bambu-dark-tertiary`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-2`,children:j(`printers.plateDetection.analysisLegend`)})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:vt.message})]}),nr&&nr.references.length>0&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:j(`printers.plateDetection.savedReferences`,{count:nr.references.length,max:nr.max_references})}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-5 gap-2`,children:nr.references.map(t=>(0,G.jsxs)(`div`,{className:`relative group`,children:[(0,G.jsx)(`img`,{src:Z.getPlateReferenceThumbnailUrl(e.id,t.index),alt:t.label||`Reference ${t.index+1}`,className:`w-full aspect-video object-cover rounded border border-bambu-dark-tertiary`}),(0,G.jsx)(`button`,{onClick:()=>fr(t.index),className:`absolute top-1 right-1 p-0.5 bg-red-500/80 rounded opacity-0 group-hover:opacity-100 transition-opacity`,title:j(`printers.plateDetection.deleteReference`),children:(0,G.jsx)(Nu,{className:`w-3 h-3 text-white`})}),ir?.index===t.index?(0,G.jsx)(`input`,{type:`text`,value:ir.label,onChange:e=>ar({...ir,label:e.target.value}),onBlur:()=>dr(t.index,ir.label),onKeyDown:e=>{e.key===`Enter`&&dr(t.index,ir.label),e.key===`Escape`&&ar(null)},className:`w-full mt-1 px-1 py-0.5 text-xs bg-bambu-dark-tertiary border border-bambu-green rounded text-white`,autoFocus:!0,placeholder:j(`printers.plateDetection.labelPlaceholder`)}):(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate cursor-pointer hover:text-white`,onClick:()=>ar({index:t.index,label:t.label}),title:t.label?j(`printers.plateDetection.clickToEdit`,{label:t.label}):j(`printers.plateDetection.clickToAddLabel`),children:t.label||(0,G.jsx)(`span`,{className:`italic opacity-50`,children:j(`printers.noLabel`)})}),(0,G.jsx)(`p`,{className:`text-[10px] text-bambu-gray/60`,children:t.timestamp?nf(t.timestamp)?.toLocaleDateString()??``:``})]},t.index))})]}),!vt.needs_calibration&&(0,G.jsxs)(`div`,{className:`mt-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,G.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[(0,G.jsx)(`p`,{className:`text-sm font-medium text-white shrink-0`,children:j(`printers.roi.title`)}),(0,G.jsx)(`div`,{className:`flex-1 h-[2px] bg-bambu-dark-tertiary`})]}),wt?(0,G.jsxs)(`div`,{className:`flex gap-1`,children:[(0,G.jsx)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Tt(null),disabled:Et,children:j(`common.cancel`)}),(0,G.jsx)(Q,{size:`sm`,onClick:pr,disabled:Et,children:Et?(0,G.jsx)(Y,{className:`w-3 h-3 animate-spin`}):j(`common.save`)})]}):(0,G.jsxs)(Q,{variant:`ghost`,size:`sm`,onClick:()=>Tt(vt.roi||{x:.15,y:.35,w:.7,h:.55}),children:[(0,G.jsx)(pl,{className:`w-3 h-3 mr-1`}),j(`common.edit`)]})]}),wt?(0,G.jsxs)(`div`,{className:`space-y-3 bg-bambu-dark-tertiary/50 p-3 rounded-lg`,children:[(0,G.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.roi.xStart`)}),(0,G.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:wt.x,onChange:e=>Tt({...wt,x:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(wt.x*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.roi.yStart`)}),(0,G.jsx)(`input`,{type:`range`,min:`0`,max:`0.9`,step:`0.01`,value:wt.y,onChange:e=>Tt({...wt,y:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(wt.y*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.width`)}),(0,G.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:wt.w,onChange:e=>Tt({...wt,w:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(wt.w*100),`%`]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-xs text-bambu-gray`,children:j(`printers.height`)}),(0,G.jsx)(`input`,{type:`range`,min:`0.1`,max:`1`,step:`0.01`,value:wt.h,onChange:e=>Tt({...wt,h:parseFloat(e.target.value)}),className:`w-full h-1.5 bg-bambu-dark-tertiary rounded-lg cursor-pointer accent-green-500`}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[Math.round(wt.h*100),`%`]})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:j(`printers.roi.instruction`)})]}):(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray`,children:[`Current: X=`,Math.round((vt.roi?.x||.15)*100),`%, Y=`,Math.round((vt.roi?.y||.35)*100),`%, W=`,Math.round((vt.roi?.w||.7)*100),`%, H=`,Math.round((vt.roi?.h||.55)*100),`%`]})]})]}),(0,G.jsx)(`div`,{className:`flex justify-end gap-2 p-4`,children:vt.needs_calibration?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>lr(),children:j(`common.cancel`)}),(0,G.jsx)(Q,{onClick:()=>ur(),disabled:St,children:St?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 mr-2 animate-spin`}),`Calibrating...`]}):`Calibrate Empty Plate`})]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Q,{variant:`ghost`,onClick:()=>ur(),disabled:St,children:St?`Adding...`:`Add Reference (${nr?.references.length||0}/${nr?.max_references||5})`}),(0,G.jsx)(Q,{onClick:()=>lr(),children:`Close`})]})})]})}),ae&&$t&&(0,G.jsx)(wd,{title:j(`printers.confirm.powerOnTitle`),message:j(`printers.confirm.powerOnMessage`,{name:e.name}),confirmText:j(`printers.confirm.powerOnButton`),variant:`default`,onConfirm:()=>{Tn.mutate(`on`),oe(!1)},onCancel:()=>oe(!1)}),U&&$t&&(0,G.jsx)(wd,{title:j(`printers.confirm.powerOffTitle`),message:W?.state===`RUNNING`?j(`printers.confirm.powerOffWarning`,{name:e.name}):j(`printers.confirm.powerOffMessage`,{name:e.name}),confirmText:j(`printers.confirm.powerOffButton`),variant:`danger`,onConfirm:()=>{Tn.mutate(`off`),se(!1)},onCancel:()=>se(!1)}),ce&&(0,G.jsx)(wd,{title:j(`printers.confirm.haToggleTitle`,{name:ce.name}),message:W?.state===`RUNNING`?j(`printers.confirm.haToggleWarning`,{name:e.name,entity:ce.ha_entity_id||ce.name}):j(`printers.confirm.haToggleMessage`,{entity:ce.ha_entity_id||ce.name}),confirmText:j(`printers.confirm.haToggleButton`),variant:W?.state===`RUNNING`?`danger`:`default`,onConfirm:()=>{Dn.mutate({id:ce.id,action:`toggle`}),le(null)},onCancel:()=>le(null)}),fe&&(0,G.jsx)(wd,{title:j(`printers.confirm.stopTitle`),message:j(`printers.confirm.stopMessage`,{name:e.name}),confirmText:j(`printers.confirm.stopButton`),variant:`danger`,onConfirm:()=>{On.mutate(),pe(!1)},onCancel:()=>pe(!1)}),me&&(0,G.jsx)(wd,{title:j(`printers.confirm.pauseTitle`),message:j(`printers.confirm.pauseMessage`,{name:e.name}),confirmText:j(`printers.confirm.pauseButton`),variant:`default`,onConfirm:()=>{kn.mutate(),he(!1)},onCancel:()=>he(!1)}),Oe&&(0,G.jsx)(wd,{title:j(`printers.confirm.resumeTitle`),message:j(`printers.confirm.resumeMessage`,{name:e.name}),confirmText:j(`printers.confirm.resumeButton`),variant:`default`,onConfirm:()=>{An.mutate(),ke(!1)},onCancel:()=>ke(!1)}),Ee&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl w-full max-w-sm p-5`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(_u,{className:`w-5 h-5 text-yellow-400 flex-shrink-0 mt-0.5`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-semibold text-white mb-1`,children:j(`printers.bedJog.notHomedTitle`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray leading-relaxed`,children:j(`printers.bedJog.notHomedMessage`)})]})]}),(0,G.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,G.jsx)(`button`,{onClick:()=>{Un.mutate(`all`),De(null)},className:`w-full px-3 py-2 rounded-lg text-xs font-medium bg-bambu-green/20 text-bambu-green hover:bg-bambu-green/30 transition-colors`,children:j(`printers.bedJog.homeZ`)}),(0,G.jsx)(`button`,{onClick:()=>{let t=Ee.distance;try{sessionStorage.setItem(`bambuddy.bedJog.warned.${e.id}`,`1`)}catch{}Bn.mutate({distance:t,force:!0}),De(null)},className:`w-full px-3 py-2 rounded-lg text-xs font-medium bg-yellow-500/20 text-yellow-400 hover:bg-yellow-500/30 transition-colors`,children:j(`printers.bedJog.moveAnyway`)}),(0,G.jsx)(`button`,{onClick:()=>De(null),className:`w-full px-3 py-2 rounded-lg text-xs font-medium bg-bambu-dark text-bambu-gray hover:bg-bambu-dark-tertiary transition-colors`,children:j(`common.cancel`)})]})]})}),(0,G.jsx)(wT,{printerId:e.id,isOpen:Ae,onClose:()=>je(!1)}),ue&&(0,G.jsx)(np,{printerName:e.name,errors:W?.hms_errors||[],onClose:()=>de(!1),printerId:e.id,hasPermission:F}),ct&&(0,G.jsx)(Rwe,{isOpen:!!ct,onClose:()=>lt(null),printerId:e.id,printerName:e.name,amsId:ct.amsId,amsLabel:ct.amsLabel,initialMode:ct.mode,thresholds:a}),ut&&(0,G.jsx)(vK,{isOpen:!!ut,onClose:()=>dt(null),tagUid:ut.tagUid,trayUuid:ut.trayUuid,printerId:ut.printerId,amsId:ut.amsId,trayId:ut.trayId}),ft&&(0,G.jsx)(bK,{isOpen:!!ft,onClose:()=>pt(null),printerId:ft.printerId,amsId:ft.amsId,trayId:ft.trayId,trayInfo:ft.trayInfo,spoolmanEnabled:!!o}),mt&&(0,G.jsx)(YK,{isOpen:!!mt,onClose:()=>ht(null),printerId:e.id,slotInfo:mt,printerModel:Gq(e.model)||void 0,onSuccess:()=>{M.invalidateQueries({queryKey:[`slotPresets`,e.id]}),M.invalidateQueries({queryKey:[`printerStatus`,e.id]})}}),te&&(0,G.jsx)(FTe,{printer:e,onClose:()=>V(!1)}),gt&&At&&(0,G.jsx)(PTe,{printer:e,firmwareInfo:At,onClose:()=>_t(!1)}),Ve!==null&&$e&&(()=>{let e=Ue===`n3s`?85:65,t=e+10;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-[100]`,onClick:()=>He(null)}),(0,G.jsxs)(`div`,{className:`fixed z-[101] flex flex-col w-[240px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-xl shadow-2xl overflow-hidden`,style:{top:$e.top,left:$e.left,maxHeight:`calc(100dvh - ${$e.top}px - 8px)`},onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`shrink-0 flex items-center justify-center gap-2 px-3 py-2.5`,children:[(0,G.jsx)(ec,{className:`w-3.5 h-3.5 text-bambu-green`}),(0,G.jsx)(`span`,{className:`text-sm text-white font-medium text-center`,children:j(`printers.drying.start`)})]}),(0,G.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,G.jsxs)(`div`,{className:`px-3 py-2.5 space-y-2.5 overflow-y-auto min-h-0`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium mb-1 block`,children:j(`printers.filaments`)}),(0,G.jsx)(zq,{value:Ge,options:Object.keys(x).map(e=>({value:e,label:e})),onChange:e=>{Ke(e);let t=x[e];t&&(Je(t[Ue===`n3s`?`n3s`:`n3f`]),Xe(Ue===`n3s`?t.n3s_hours:t.n3f_hours))},fullWidth:!0})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium`,children:j(`printers.drying.temperature`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:45,max:e,value:qe,onChange:t=>Je(Math.min(e,Math.max(45,Number(t.target.value)||45))),className:`w-12 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[11px] text-center focus:outline-none focus:border-bambu-green [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:`°C`})]})]}),(0,G.jsx)(`input`,{type:`range`,min:35,max:t,value:qe,onChange:t=>Je(Math.min(e,Math.max(45,Number(t.target.value)))),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[9px] text-bambu-gray/50 mt-0.5`,children:[(0,G.jsx)(`span`,{children:`45°C`}),(0,G.jsxs)(`span`,{children:[e,`°C`]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-1`,children:[(0,G.jsx)(`label`,{className:`text-[10px] text-white/70 font-medium`,children:j(`printers.drying.duration`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,G.jsx)(`input`,{type:`number`,min:1,max:24,value:Ye,onChange:e=>Xe(Math.min(24,Math.max(1,Number(e.target.value)||1))),className:`w-10 px-1 py-0.5 bg-bambu-dark border border-bambu-dark-tertiary rounded text-white text-[11px] text-center focus:outline-none focus:border-bambu-green [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}),(0,G.jsx)(`span`,{className:`text-[10px] text-bambu-gray`,children:j(`printers.drying.hours`)})]})]}),(0,G.jsx)(`input`,{type:`range`,min:1,max:24,value:Ye,onChange:e=>Xe(Number(e.target.value)),className:`w-full h-1 accent-bambu-green cursor-pointer`}),(0,G.jsxs)(`div`,{className:`flex justify-between text-[9px] text-bambu-gray/50 mt-0.5`,children:[(0,G.jsx)(`span`,{children:`1h`}),(0,G.jsx)(`span`,{children:`24h`})]})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>Qe(e=>!e),"aria-pressed":Ze,className:`h-8 w-full rounded-lg border px-2 text-sm font-medium transition-colors ${Ze?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:j(`printers.drying.rotateTray`)})]}),(0,G.jsx)(`div`,{className:`shrink-0 h-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`shrink-0 px-3 pt-2.5 pb-3`,children:(0,G.jsx)(`button`,{onClick:()=>{Ve!==null&&Cn.mutate({amsId:Ve,temp:qe,duration:Ye,filament:Ge,rotateTray:Ze})},disabled:Cn.isPending,className:`w-full py-1.5 bg-bambu-green hover:bg-bambu-green/80 text-white text-xs font-medium rounded-lg transition-colors disabled:opacity-50`,children:Cn.isPending?j(`printers.drying.startingDrying`):j(`printers.drying.start`)})})]})]})})()]})}function NTe({onClose:e,onAdd:t,existingSerials:n}){let{t:r}=et(),[i,a]=(0,y.useState)({name:``,serial_number:``,ip_address:``,access_code:``,model:``,location:``,auto_archive:!0}),[o,s]=(0,y.useState)(!1),[c,l]=(0,y.useState)([]),[u,d]=(0,y.useState)(``),[f,p]=(0,y.useState)(!1),[m,h]=(0,y.useState)(!1),[g,_]=(0,y.useState)([]),[v,b]=(0,y.useState)(``),[x,S]=(0,y.useState)(``),[C,w]=(0,y.useState)(!1),[T,E]=(0,y.useState)({scanned:0,total:0}),[D,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(!1),[j,M]=(0,y.useState)(null);(0,y.useEffect)(()=>{Yu.getInfo().then(e=>{h(e.is_docker),e.subnets.length>0&&(_(e.subnets),b(e.subnets[0]))}).catch(()=>{});try{let e=localStorage.getItem(`bambuddy.discovery.customSubnet`);e&&S(e)}catch{}},[]);let N=c.filter(e=>!n.includes(e.serial)),P=async e=>{e.preventDefault(),A(!0);try{let e=await Z.diagnoseConnection({ip_address:i.ip_address.trim(),serial_number:i.serial_number.trim()||void 0,access_code:i.access_code||void 0});if(e.checks.some(e=>e.status===`fail`)){M(e);return}}catch{}finally{A(!1)}t(i)},F=async()=>{d(``),l([]),s(!0),p(!1),E({scanned:0,total:0});let e=C?x.trim():v,t=m||C;if(t&&C)try{localStorage.setItem(`bambuddy.discovery.customSubnet`,e)}catch{}try{if(t){await Yu.startSubnetScan(e);let t=setInterval(async()=>{try{let e=await Yu.getScanStatus();E({scanned:e.scanned,total:e.total}),l(await Yu.getDiscoveredPrinters()),e.running||(clearInterval(t),s(!1),p(!0))}catch(e){console.error(`Failed to get scan status:`,e)}},500)}else{await Yu.startDiscovery(10);let e=setInterval(async()=>{try{l(await Yu.getDiscoveredPrinters())}catch(e){console.error(`Failed to get discovered printers:`,e)}},1e3);setTimeout(async()=>{clearInterval(e);try{await Yu.stopDiscovery()}catch{}s(!1),p(!0);try{l(await Yu.getDiscoveredPrinters())}catch(e){console.error(`Failed to get final discovered printers:`,e)}},1e4)}}catch(e){console.error(`Failed to start discovery:`,e),d(e instanceof Error?e.message:r(`printers.discovery.failedToStart`)),s(!1),p(!0)}},I=e=>{let t=e.serial.startsWith(`unknown-`)?``:e.serial;a({...i,name:e.name||``,serial_number:t,ip_address:e.ip_address,model:Gq(e.model)}),l([])};return(0,y.useEffect)(()=>()=>{Yu.stopDiscovery().catch(()=>{}),Yu.stopSubnetScan().catch(()=>{})},[]),(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-start sm:items-center justify-center z-50 p-4 overflow-y-auto`,onClick:e,children:(0,G.jsx)(dd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(pd,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:r(`printers.addPrinter`)}),(0,G.jsxs)(`div`,{className:`mb-4 pb-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`mb-3`,children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.discovery.subnetToScan`)}),g.length>0?(0,G.jsxs)(`select`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:C?`__custom__`:v,onChange:e=>{e.target.value===`__custom__`?w(!0):(w(!1),b(e.target.value))},disabled:o,children:[g.map(e=>(0,G.jsx)(`option`,{value:e,children:e},e)),(0,G.jsx)(`option`,{value:`__custom__`,children:r(`printers.discovery.customSubnetOption`)})]}):(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:v,onChange:e=>b(e.target.value),placeholder:`192.168.1.0/24`,disabled:o}),C&&(0,G.jsx)(`input`,{type:`text`,"aria-label":r(`printers.discovery.customSubnetLabel`),className:`mt-2 w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none text-sm`,value:x,onChange:e=>S(e.target.value),placeholder:`10.1.1.0/24`,disabled:o}),(0,G.jsx)(`p`,{className:`mt-1 text-xs text-bambu-gray`,children:r(m?`printers.discovery.dockerNote`:`printers.discovery.customSubnetNote`)})]}),(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:F,disabled:o,className:`w-full`,children:o?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),(m||C)&&T.total>0?r(`printers.discovery.scanProgress`,{scanned:T.scanned,total:T.total}):r(`printers.discovery.scanning`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Ml,{className:`w-4 h-4`}),r(m||C?`printers.discovery.scanSubnet`:`printers.discovery.discoverNetwork`)]})}),u&&(0,G.jsx)(`div`,{className:`mt-2 text-sm text-red-400`,children:u}),N.length>0&&(0,G.jsx)(`div`,{className:`mt-3 space-y-2 max-h-40 overflow-y-auto`,children:N.map(e=>(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-2 bg-bambu-dark rounded-lg hover:bg-bambu-dark-secondary cursor-pointer transition-colors`,onClick:()=>I(e),children:[(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`font-medium text-white text-sm truncate`,children:e.name||e.serial}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[Gq(e.model)||r(`printers.discovery.unknown`),` • `,e.ip_address,e.serial.startsWith(`unknown-`)&&(0,G.jsxs)(`span`,{className:`text-yellow-500`,children:[` • `,r(`printers.discovery.serialRequired`)]})]})]}),(0,G.jsx)(es,{className:`w-4 h-4 text-bambu-gray -rotate-90 flex-shrink-0 ml-2`})]},e.serial))}),o&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(m||C?`printers.discovery.scanningSubnet`:`printers.discovery.scanningNetwork`)}),f&&!o&&c.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(m||C?`printers.discovery.noPrintersFoundSubnet`:`printers.discovery.noPrintersFoundNetwork`)}),f&&!o&&c.length>0&&N.length===0&&(0,G.jsx)(`p`,{className:`mt-2 text-sm text-bambu-gray text-center`,children:r(`printers.discovery.allConfigured`)})]}),(0,G.jsxs)(`form`,{onSubmit:P,className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.name`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.name,onChange:e=>a({...i,name:e.target.value}),placeholder:r(`printers.modal.myPrinter`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.ipAddress`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,pattern:`(\\d{1,3}(\\.\\d{1,3}){3}|[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?)*)`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.ip_address,onChange:e=>a({...i,ip_address:e.target.value}),placeholder:`192.168.1.100 or printer.local`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.serialNumber`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.serial_number,onChange:e=>a({...i,serial_number:e.target.value}),placeholder:`01P00A000000000`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.accessCode`)}),(0,G.jsx)(`input`,{type:`password`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.access_code,onChange:e=>a({...i,access_code:e.target.value}),placeholder:r(`printers.modal.fromPrinterSettings`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.modelOptional`)}),(0,G.jsxs)(`select`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.model||``,onChange:e=>a({...i,model:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:r(`printers.modal.selectModel`)}),(0,G.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,G.jsx)(`option`,{value:`A1`,children:`A1`}),(0,G.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,G.jsx)(`optgroup`,{label:`A2 Series`,children:(0,G.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,G.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,G.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,G.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,G.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,G.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,G.jsxs)(`optgroup`,{label:`P Series`,children:[(0,G.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,G.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,G.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,G.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,G.jsx)(`option`,{value:`X1`,children:`X1`}),(0,G.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,G.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,G.jsx)(`optgroup`,{label:`X2 Series`,children:(0,G.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`printers.modal.locationGroup`)}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:i.location||``,onChange:e=>a({...i,location:e.target.value}),placeholder:r(`printers.modal.locationPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`printers.locationHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`auto_archive`,checked:i.auto_archive,onChange:e=>a({...i,auto_archive:e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`auto_archive`,className:`text-sm text-bambu-gray`,children:r(`printers.modal.autoArchiveLabel`)})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:()=>O(!0),disabled:!i.ip_address.trim(),className:`w-full flex items-center justify-center gap-2 px-3 py-2 text-sm text-bambu-gray hover:text-white disabled:opacity-40 disabled:cursor-not-allowed border border-bambu-dark-tertiary rounded-lg transition-colors`,children:[(0,G.jsx)(nu,{className:`w-4 h-4`}),r(`diagnostic.runButton`)]}),j?(0,G.jsxs)(`div`,{className:`rounded-lg bg-amber-500/10 border border-amber-500/30 p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(_u,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-400`}),(0,G.jsx)(`p`,{className:`text-sm text-amber-300`,children:r(`printers.addPreflight.warning`)})]}),(0,G.jsx)(mf,{result:j}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>M(null),className:`flex-1`,children:r(`printers.addPreflight.back`)}),(0,G.jsx)(Q,{type:`button`,onClick:()=>t(i),className:`flex-1`,children:r(`printers.addPreflight.saveAnyway`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:e,className:`flex-1`,children:r(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,disabled:k,className:`flex-1`,children:r(k?`printers.addPreflight.checking`:`printers.addPrinter`)})]})]})]})})}),D&&(0,G.jsx)(gf,{connection:{ip_address:i.ip_address.trim(),serial_number:i.serial_number.trim()||void 0,access_code:i.access_code||void 0},printerName:i.name||null,onClose:()=>O(!1)})]})}function PTe({printer:e,firmwareInfo:t,onClose:n}){let{t:r}=et(),i=$a(),{showToast:a}=yd(),{hasPermission:o}=ad(),s=o(`firmware:update`),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(t.update_available?t.latest_version:null),{data:g,isLoading:_}=K({queryKey:[`firmwarePrepare`,e.id,m],queryFn:()=>$u.prepareUpload(e.id,m??void 0),staleTime:3e4,enabled:!!m&&s&&!u}),v=q({mutationFn:()=>$u.startUpload(e.id,m??void 0),onSuccess:()=>{d(!0);let t=setInterval(async()=>{try{let n=await $u.getUploadStatus(e.id);l(n),(n.status===`complete`||n.status===`error`)&&(clearInterval(t),p(null),d(!1),n.status===`complete`&&(a(r(`printers.firmwareModal.uploadedToast`),`success`),i.invalidateQueries({queryKey:[`firmwareUpdate`,e.id]})))}catch{}},2e3);p(t)},onError:e=>{a(r(`printers.firmwareModal.uploadFailed`,{error:e.message}),`error`),d(!1)}});return(0,y.useEffect)(()=>()=>{f&&clearInterval(f)},[f]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50`,children:(0,G.jsx)(dd,{className:`w-full max-w-md mx-4`,children:(0,G.jsxs)(pd,{children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-3 mb-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full ${t.update_available?`bg-orange-500/20`:`bg-status-ok/20`}`,children:t.update_available?(0,G.jsx)(Is,{className:`w-5 h-5 text-orange-400`}):(0,G.jsx)(ls,{className:`w-5 h-5 text-status-ok`})}),(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white`,children:t.update_available?r(`printers.firmwareModal.title`):r(`printers.firmwareModal.titleUpToDate`)}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mt-1`,children:e.name})]})]}),(()=>{let e=m?t.available_versions?.find(e=>e.version===m):null,n=m??t.latest_version,i=e?.release_notes??t.release_notes,a=!!n&&n!==t.current_version;return(0,G.jsxs)(`div`,{className:`bg-bambu-dark rounded-lg p-3 mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.currentVersion`)}),(0,G.jsx)(`span`,{className:`font-mono ${a?`text-white`:`text-status-ok`}`,children:t.current_version||r(`common.unknown`)})]}),a&&(0,G.jsxs)(`div`,{className:`flex justify-between items-center text-sm mt-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray`,children:r(`printers.firmwareModal.latestVersion`)}),(0,G.jsx)(`span`,{className:`text-orange-400 font-mono`,children:n})]}),i&&(0,G.jsxs)(`details`,{className:`mt-3 text-sm`,open:!a,children:[(0,G.jsx)(`summary`,{className:`cursor-pointer hover:underline ${a?`text-orange-400`:`text-status-ok`}`,children:r(`printers.firmwareModal.releaseNotes`)}),(0,G.jsx)(`div`,{className:`mt-2 text-bambu-gray text-xs max-h-40 overflow-y-auto whitespace-pre-wrap`,children:i})]},n??`none`)]})})(),t.available_versions&&t.available_versions.length>0&&!u&&c?.status!==`complete`&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray mb-2`,children:r(`printers.firmwareModal.availableVersions`)}),(0,G.jsx)(`div`,{className:`max-h-56 overflow-y-auto border border-bambu-dark-tertiary rounded-lg divide-y divide-bambu-dark-tertiary`,children:t.available_versions.map(e=>{let n=t.current_version===e.version,i=m===e.version,a=t.current_version?Vf(e.version,t.current_version):0,o=r(n?`printers.firmwareModal.currentBadge`:a>0?`printers.firmwareModal.newerBadge`:`printers.firmwareModal.olderBadge`),c=n?`text-bambu-gray`:a>0?`text-orange-400`:`text-blue-400`;return(0,G.jsxs)(`button`,{type:`button`,disabled:!e.file_available||!s||n,onClick:()=>h(e.version),className:`w-full text-left px-3 py-2 text-sm flex items-center justify-between gap-2 transition-colors ${i?`bg-orange-500/10`:`hover:bg-bambu-dark`} ${!e.file_available||!s||n?`opacity-60 cursor-not-allowed`:`cursor-pointer`}`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`span`,{className:`font-mono text-white`,children:e.version}),(0,G.jsx)(`span`,{className:`text-xs ${c}`,children:o})]}),(0,G.jsx)(`span`,{className:`text-xs px-2 py-0.5 rounded-full ${n?`bg-blue-500/15 text-blue-400 border border-blue-500/30`:e.file_available?`bg-bambu-green/15 text-bambu-green border border-bambu-green/30`:`bg-bambu-gray/10 text-bambu-gray border border-bambu-gray/30`}`,children:n?r(`printers.firmwareModal.installed`):e.file_available?r(`printers.firmwareModal.usable`):r(`printers.firmwareModal.unavailable`)})]},e.version)})})]}),m?_?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm mb-4`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),r(`printers.firmwareModal.checkingPrereqs`)]}):g&&!u&&!c?(0,G.jsx)(`div`,{className:`mb-4`,children:g.can_proceed?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-green text-sm`,children:[(0,G.jsx)(Vo,{className:`w-4 h-4`}),r(`printers.firmwareModal.sdCardReady`)]}):(0,G.jsx)(`div`,{className:`space-y-1`,children:g.errors.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-red-400 text-sm`,children:[(0,G.jsx)(ss,{className:`w-4 h-4 flex-shrink-0`}),e]},t))})}):null:null,(u||c)&&c&&(0,G.jsxs)(`div`,{className:`mb-4`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between text-sm mb-1`,children:[(0,G.jsx)(`span`,{className:`text-bambu-gray capitalize`,children:c.status}),(0,G.jsxs)(`span`,{className:`text-white`,children:[c.progress,`%`]})]}),(0,G.jsx)(`div`,{className:`w-full bg-bambu-dark-tertiary rounded-full h-2`,children:(0,G.jsx)(`div`,{className:`h-2 rounded-full transition-all ${c.status===`error`?`bg-status-error`:c.status===`complete`?`bg-status-ok`:`bg-orange-500`} ${c.status===`uploading`?`animate-pulse`:``}`,style:{width:`${c.progress}%`}})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:c.message}),c.error&&(0,G.jsx)(`p`,{className:`text-xs text-red-400 mt-1`,children:c.error})]}),c?.status===`complete`&&(0,G.jsxs)(`div`,{className:`bg-bambu-green/10 border border-bambu-green/30 rounded-lg p-3 mb-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-green font-medium mb-2`,children:r(`printers.firmwareModal.uploadedSuccess`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`printers.firmwareModal.applyInstructions`)}),(0,G.jsxs)(`ol`,{className:`text-xs text-bambu-gray mt-1 list-decimal list-inside space-y-1`,children:[(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step1`)}}),(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step2`)}}),(0,G.jsx)(`li`,{dangerouslySetInnerHTML:{__html:r(`printers.firmwareModal.step3`)}}),(0,G.jsx)(`li`,{children:r(`printers.firmwareModal.step4`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:n,children:c?.status===`complete`?r(`printers.firmwareModal.done`):r(`common.cancel`)}),g?.can_proceed&&!u&&c?.status!==`complete`&&s&&(0,G.jsx)(Q,{onClick:()=>{l(null),v.mutate()},disabled:v.isPending,children:v.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-2`}),r(`printers.firmwareModal.starting`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Is,{className:`w-4 h-4 mr-2`}),r(`printers.firmwareModal.uploadFirmware`)]})})]})]})})})}function FTe({printer:e,onClose:t}){let{t:n}=et(),r=$a(),{showToast:i}=yd(),[a,o]=(0,y.useState)({name:e.name,ip_address:e.ip_address,access_code:``,model:e.model||``,location:e.location||``,auto_archive:e.auto_archive}),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(null),d=q({mutationFn:t=>Z.updatePrinter(e.id,t),onSuccess:()=>{r.invalidateQueries({queryKey:[`printers`]}),r.invalidateQueries({queryKey:[`printerStatus`,e.id]}),t()},onError:e=>i(e.message||n(`printers.toast.failedToUpdate`),`error`)});(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let f=()=>{let e={name:a.name,ip_address:a.ip_address,model:a.model||void 0,location:a.location||void 0,auto_archive:a.auto_archive};a.access_code&&(e.access_code=a.access_code),d.mutate(e)};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-start sm:items-center justify-center z-50 p-4 overflow-y-auto`,onClick:t,children:(0,G.jsx)(dd,{className:`w-full max-w-md my-auto max-h-[calc(100vh-2rem)] overflow-y-auto`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(pd,{children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold mb-4`,children:n(`printers.editPrinter`)}),(0,G.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),c(!0);try{let t=await Z.diagnoseConnection({ip_address:a.ip_address.trim(),serial_number:e.serial_number,access_code:a.access_code||void 0});if(t.checks.some(e=>e.status===`fail`)){u(t);return}}catch{}finally{c(!1)}f()},className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.name`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.name,onChange:e=>o({...a,name:e.target.value}),placeholder:n(`printers.modal.myPrinter`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.ipAddress`)}),(0,G.jsx)(`input`,{type:`text`,required:!0,pattern:`(\\d{1,3}(\\.\\d{1,3}){3}|[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?)*)`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.ip_address,onChange:e=>o({...a,ip_address:e.target.value}),placeholder:`192.168.1.100 or printer.local`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.serialNumber`)}),(0,G.jsx)(`input`,{type:`text`,disabled:!0,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-bambu-gray cursor-not-allowed`,value:e.serial_number}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.serialCannotBeChanged`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.accessCode`)}),(0,G.jsx)(`input`,{type:`password`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.access_code,onChange:e=>o({...a,access_code:e.target.value}),placeholder:n(`printers.accessCodePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:n(`printers.model`)}),(0,G.jsxs)(`select`,{className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.model,onChange:e=>o({...a,model:e.target.value}),children:[(0,G.jsx)(`option`,{value:``,children:n(`printers.modal.selectModel`)}),(0,G.jsxs)(`optgroup`,{label:`A1 Series`,children:[(0,G.jsx)(`option`,{value:`A1`,children:`A1`}),(0,G.jsx)(`option`,{value:`A1 Mini`,children:`A1 Mini`})]}),(0,G.jsx)(`optgroup`,{label:`A2 Series`,children:(0,G.jsx)(`option`,{value:`A2L`,children:`A2L`})}),(0,G.jsxs)(`optgroup`,{label:`H2 Series`,children:[(0,G.jsx)(`option`,{value:`H2C`,children:`H2C`}),(0,G.jsx)(`option`,{value:`H2D`,children:`H2D`}),(0,G.jsx)(`option`,{value:`H2D Pro`,children:`H2D Pro`}),(0,G.jsx)(`option`,{value:`H2S`,children:`H2S`})]}),(0,G.jsxs)(`optgroup`,{label:`P Series`,children:[(0,G.jsx)(`option`,{value:`P1P`,children:`P1P`}),(0,G.jsx)(`option`,{value:`P1S`,children:`P1S`}),(0,G.jsx)(`option`,{value:`P2S`,children:`P2S`})]}),(0,G.jsxs)(`optgroup`,{label:`X1 Series`,children:[(0,G.jsx)(`option`,{value:`X1`,children:`X1`}),(0,G.jsx)(`option`,{value:`X1C`,children:`X1 Carbon`}),(0,G.jsx)(`option`,{value:`X1E`,children:`X1E`})]}),(0,G.jsx)(`optgroup`,{label:`X2 Series`,children:(0,G.jsx)(`option`,{value:`X2D`,children:`X2D`})})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:`Location / Group`}),(0,G.jsx)(`input`,{type:`text`,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,value:a.location,onChange:e=>o({...a,location:e.target.value}),placeholder:n(`printers.modal.locationPlaceholder`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:n(`printers.locationHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`input`,{type:`checkbox`,id:`edit_auto_archive`,checked:a.auto_archive,onChange:e=>o({...a,auto_archive:e.target.checked}),className:`rounded border-bambu-dark-tertiary bg-bambu-dark text-bambu-green focus:ring-bambu-green`}),(0,G.jsx)(`label`,{htmlFor:`edit_auto_archive`,className:`text-sm text-bambu-gray`,children:n(`printers.modal.autoArchiveLabel`)})]}),l?(0,G.jsxs)(`div`,{className:`rounded-lg bg-amber-500/10 border border-amber-500/30 p-3 space-y-3`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,G.jsx)(_u,{className:`w-4 h-4 mt-0.5 flex-shrink-0 text-amber-400`}),(0,G.jsx)(`p`,{className:`text-sm text-amber-300`,children:n(`printers.addPreflight.warning`)})]}),(0,G.jsx)(mf,{result:l}),(0,G.jsxs)(`div`,{className:`flex gap-3`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:()=>u(null),className:`flex-1`,children:n(`printers.addPreflight.back`)}),(0,G.jsx)(Q,{type:`button`,onClick:f,className:`flex-1`,disabled:d.isPending,children:n(`printers.addPreflight.saveAnyway`)})]})]}):(0,G.jsxs)(`div`,{className:`flex gap-3 pt-4`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:n(`common.cancel`)}),(0,G.jsx)(Q,{type:`submit`,className:`flex-1`,disabled:d.isPending||s,children:s?n(`printers.addPreflight.checking`):d.isPending?n(`common.saving`):n(`printers.modal.saveChanges`)})]})]})]})})})}function ITe(e){let{data:t}=K({queryKey:[`printerStatus`,e],queryFn:()=>Z.getPrinterStatus(e),refetchInterval:3e4});return!t?.connected}function LTe({printer:e,plug:t,onPowerOn:n,isPowering:r}){let i=ITe(e.id),{data:a}=K({queryKey:[`smartPlugStatus`,t.id],queryFn:()=>Z.getSmartPlugStatus(t.id),refetchInterval:1e4});return i?(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 hover:bg-gray-100 dark:hover:bg-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(`span`,{className:`text-sm text-gray-900 dark:text-white truncate`,children:e.name}),a&&(0,G.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 rounded ${a.state===`ON`?`bg-bambu-green/20 text-bambu-green`:`bg-red-500/20 text-red-400`}`,children:a.state||`?`})]}),(0,G.jsxs)(`button`,{onClick:()=>n(t.id),disabled:r||a?.state===`ON`,className:`px-2 py-1 text-xs rounded transition-colors flex items-center gap-1 ${a?.state===`ON`?`bg-bambu-green/20 text-bambu-green cursor-default`:`bg-bambu-green/20 text-bambu-green hover:bg-bambu-green hover:text-white`}`,children:[(0,G.jsx)(yl,{className:`w-3 h-3`}),r?`...`:`On`]})]}):null}function RTe(){let{t:e}=et(),{resolvedMode:t,darkAccent:n,lightAccent:r}=cd(),i={green:`bg-green-500 text-white hover:bg-green-400 border-green-400/60`,teal:`bg-teal-500 text-white hover:bg-teal-400 border-teal-400/60`,blue:`bg-blue-500 text-white hover:bg-blue-400 border-blue-400/60`,orange:`bg-orange-500 text-white hover:bg-orange-400 border-orange-400/60`,purple:`bg-purple-500 text-white hover:bg-purple-400 border-purple-400/60`,red:`bg-red-500 text-white hover:bg-red-400 border-red-400/60`}[t===`dark`?n:r],[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(()=>localStorage.getItem(`hideDisconnectedPrinters`)===`true`),[l,u]=(0,y.useState)(!1),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(()=>localStorage.getItem(`printerSortBy`)||`name`),[h,g]=(0,y.useState)(()=>localStorage.getItem(`printerSortAsc`)!==`false`),[_,v]=(0,y.useState)(()=>{let e=localStorage.getItem(`printerCardSize`);return e?parseInt(e,10):2}),b=_===1?`compact`:`expanded`,[x,S]=(0,y.useState)(null),C=(0,y.useCallback)(e=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{let t=document.getElementById(`printer-card-${e}`);if(!t)return;let n=document.querySelector(`header`)?.getBoundingClientRect().height??56,r=t.getBoundingClientRect().top+window.scrollY-n-16;window.scrollTo({top:Math.max(0,r),behavior:`smooth`})})})},[]),w=(0,y.useCallback)(e=>{S(e),v(2),localStorage.setItem(`printerCardSize`,`2`),C(e)},[C]),T=(0,y.useCallback)(()=>{let e=x;S(null),v(1),localStorage.setItem(`printerCardSize`,`1`),e!=null&&C(e)},[x,C]),[E,D]=(0,y.useState)(``),[O,k]=(0,y.useState)(`all`),[A,j]=(0,y.useState)(`all`),[M,N]=(0,y.useState)(0),[P,F]=(0,y.useState)(()=>{try{let e=localStorage.getItem(`printerCollapsedSections`);return e?JSON.parse(e):{}}catch{return{}}}),I=$a(),{showToast:L}=yd(),{hasPermission:R}=ad(),[z,B]=(0,y.useState)(()=>{let e=localStorage.getItem(`openEmbeddedCameras`);if(e)try{let t=JSON.parse(e);return new Map(t.map(e=>[e.id,e]))}catch{return new Map}return new Map});(0,y.useEffect)(()=>{let e=Array.from(z.values());e.length>0?localStorage.setItem(`openEmbeddedCameras`,JSON.stringify(e)):localStorage.removeItem(`openEmbeddedCameras`)},[z]);let{data:ee,isLoading:te}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:V}=K({queryKey:[`ui-preferences`],queryFn:Z.getUiPreferences}),ne=(0,y.useMemo)(()=>Yf(V?.nozzle_temp_presets,Wf,0,320),[V?.nozzle_temp_presets]),re=(0,y.useMemo)(()=>Yf(V?.bed_temp_presets,Gf,0,140),[V?.bed_temp_presets]),ie=(0,y.useMemo)(()=>Yf(V?.chamber_temp_presets,Kf,0,60),[V?.chamber_temp_presets]),H=(0,y.useMemo)(()=>Yf(V?.fan_speed_presets,qf,0,100),[V?.fan_speed_presets]),ae=(0,y.useMemo)(()=>{if(V?.drying_presets)try{let e=JSON.parse(V.drying_presets);if(typeof e==`object`&&e&&Object.keys(e).length>0)return{...qq,...e}}catch{}return qq},[V?.drying_presets]);(0,y.useEffect)(()=>{V?.camera_view_mode===`window`&&z.size>0&&B(new Map)},[V?.camera_view_mode,z.size]);let{data:oe}=K({queryKey:[`smart-plugs`],queryFn:Z.getSmartPlugs}),{data:U}=K({queryKey:[`maintenanceOverview`],queryFn:Z.getMaintenanceOverview,staleTime:60*1e3}),{data:se}=K({queryKey:[`spoolman-status`],queryFn:Z.getSpoolmanStatus,staleTime:60*1e3}),ce=se?.enabled&&se?.connected,{data:le}=K({queryKey:[`spoolman-settings`],queryFn:Z.getSpoolmanSettings,enabled:!!ce,staleTime:60*1e3}),ue=le?.spoolman_sync_mode,{data:de}=K({queryKey:[`unlinked-spools`],queryFn:Z.getUnlinkedSpools,enabled:!!ce,staleTime:30*1e3}),fe=de&&de.length>0,{data:pe}=K({queryKey:[`linked-spools`],queryFn:Z.getLinkedSpools,enabled:!!ce,staleTime:30*1e3}),me=pe?.linked,{data:he}=K({queryKey:[`spool-assignments`],queryFn:()=>Z.getAssignments(),enabled:R(`inventory:view_assignments`),staleTime:30*1e3}),ge=q({mutationFn:({printerId:e,amsId:t,trayId:n})=>Z.unassignSpool(e,t,n),onSuccess:()=>{I.invalidateQueries({queryKey:[`spool-assignments`]})}}),{data:_e,isLoading:ve}=K({queryKey:[`spoolman-inventory-spools`],queryFn:()=>Z.getSpoolmanInventorySpools(!1),enabled:!!ce,staleTime:30*1e3}),{data:ye,isLoading:be}=K({queryKey:[`spoolman-slot-assignments`],queryFn:()=>Z.getSpoolmanSlotAssignments(),enabled:!!ce,staleTime:30*1e3}),xe=q({mutationFn:e=>Z.unassignSpoolmanSlot(e),onSuccess:()=>{I.invalidateQueries({queryKey:[`spoolman-inventory-spools`]}),I.invalidateQueries({queryKey:[`spoolman-slot-assignments`]})}}),Se=(e,t,n)=>he?.find(r=>r.printer_id===e&&r.ams_id===Number(t)&&r.tray_id===Number(n)),Ce=U?.reduce((e,t)=>(e[t.printer_id]={due_count:t.due_count,warning_count:t.warning_count,total_print_hours:t.total_print_hours},e),{})||{},we=oe?.reduce((e,t)=>(t.printer_id&&(e[t.printer_id]=t),e),{})||{},Te=q({mutationFn:Z.createPrinter,onSuccess:()=>{I.invalidateQueries({queryKey:[`printers`]}),I.invalidateQueries({queryKey:[`maintenanceOverview`]}),o(!1)},onError:t=>{if(t instanceof Ru&&t.code===`printer_connection_failed`){L(e(`printers.toast.connectionFailedNotAdded`),`error`);return}L(t.message||e(`printers.toast.failedToAdd`),`error`)}}),Ee=q({mutationFn:e=>Z.controlSmartPlug(e,`on`),onSuccess:()=>{I.invalidateQueries({queryKey:[`smart-plugs`]}),f(null)},onError:()=>{f(null)}}),[De,Oe]=(0,y.useState)(new Set),[ke,Ae]=(0,y.useState)(!1),[je,Me]=(0,y.useState)(null),[Ne,Pe]=(0,y.useState)(!1),Fe=ke||De.size>0,Ie=(0,y.useCallback)(e=>{Oe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Le=(0,y.useCallback)(()=>{Oe(new Set),Ae(!1)},[]);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&Fe&&Le()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Fe,Le]);let Re=(0,y.useCallback)(async t=>{Pe(!0);let n=Array.from(De).filter(e=>{let n=I.getQueryData([`printerStatus`,e]);if(!n?.connected)return!1;switch(t){case`stop`:return n.state===`RUNNING`||n.state===`PAUSE`;case`pause`:return n.state===`RUNNING`;case`resume`:return n.state===`PAUSE`;case`clearPlate`:return!!n.awaiting_plate_clear;case`clearHMS`:return n.hms_errors&&ep(n.hms_errors).length>0;default:return!1}});if(n.length===0){L(e(`printers.bulk.noneApplicable`),`error`),Pe(!1),Me(null);return}let r={stop:Z.stopPrint,pause:Z.pausePrint,resume:Z.resumePrint,clearPlate:Z.clearPlate,clearHMS:Z.clearHMSErrors}[t],i=await Promise.allSettled(n.map(e=>r(e))),a=i.filter(e=>e.status===`fulfilled`).length,o=i.filter(e=>e.status===`rejected`).length;o===0?L(e(`printers.bulk.success`,{action:e(`printers.bulk.actions.${t}`),count:a})):L(e(`printers.bulk.partial`,{succeeded:a,failed:o}),`error`),n.forEach(e=>{I.invalidateQueries({queryKey:[`printerStatus`,e]})}),Pe(!1),Me(null)},[De,I,L,e]),ze=(0,y.useCallback)(e=>{e===`stop`||e===`pause`||e===`clearPlate`?Me(e):Re(e)},[Re]),Be=()=>{let e=!s;c(e),localStorage.setItem(`hideDisconnectedPrinters`,String(e))},Ve=e=>{m(e),localStorage.setItem(`printerSortBy`,e)},He=()=>{let e=!h;g(e),localStorage.setItem(`printerSortAsc`,String(e))},Ue=()=>{switch(_){case 1:return`grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5`;case 2:return`grid-cols-1 md:grid-cols-2 xl:grid-cols-3`;case 3:return`grid-cols-1 lg:grid-cols-2`;case 4:return`grid-cols-1`;default:return`grid-cols-1 md:grid-cols-2 xl:grid-cols-3`}},We=[`S`,`M`,`L`,`XL`];(0,y.useEffect)(()=>I.getQueryCache().subscribe(e=>{e.type===`updated`&&Array.isArray(e.query.queryKey)&&e.query.queryKey[0]===`printerStatus`&&N(e=>e+1)}),[I]);let Ge=(0,y.useMemo)(()=>{if(!ee)return[];let e=ee;if(E.trim()){let t=E.trim().toLowerCase();e=e.filter(e=>e.name.toLowerCase().includes(t)||(e.model||``).toLowerCase().includes(t)||(e.location||``).toLowerCase().includes(t)||(e.serial_number||``).toLowerCase().includes(t))}return A!==`all`&&(e=e.filter(e=>(e.location||``)===A)),O!==`all`&&(e=e.filter(e=>{let t=I.getQueryData([`printerStatus`,e.id]);if(!t?.connected)return O===`offline`;let n=t.hms_errors?ep(t.hms_errors):[];switch(O){case`printing`:return t.state===`RUNNING`;case`paused`:return t.state===`PAUSE`;case`finished`:return t.state===`FINISH`;case`error`:return t.state===`FAILED`||n.length>0;case`idle`:return t.state!==`RUNNING`&&t.state!==`PAUSE`&&t.state!==`FINISH`&&t.state!==`FAILED`&&n.length===0;case`offline`:return!1;default:return!0}})),e},[ee,E,O,A,I,M]),Ke=(0,y.useMemo)(()=>ee?[...new Set(ee.map(e=>e.location||``).filter(Boolean))].sort():[],[ee]),qe=(0,y.useMemo)(()=>{let e=[...Ge];switch(p){case`name`:e.sort((e,t)=>e.name.localeCompare(t.name));break;case`model`:e.sort((e,t)=>(e.model||``).localeCompare(t.model||``));break;case`location`:e.sort((e,t)=>{let n=e.location||``,r=t.location||``;return!n&&r?1:n&&!r?-1:n.localeCompare(r)||e.name.localeCompare(t.name)});break;case`status`:e.sort((e,t)=>{let n=I.getQueryData([`printerStatus`,e.id]),r=I.getQueryData([`printerStatus`,t.id]),i=e=>e?.connected?(e.hms_errors?ep(e.hms_errors):[]).length>0?0:e.state===`RUNNING`?1:2:3;return i(n)-i(r)});break}return h||e.reverse(),e},[Ge,p,h,I]),Je=(0,y.useCallback)(()=>{Oe(new Set(qe.map(e=>e.id))),Ae(!0)},[qe]),Ye=(0,y.useCallback)(e=>{Oe(t=>{let n=new Set(t);return qe.forEach(t=>{Wq(I.getQueryData([`printerStatus`,t.id]))===e&&n.add(t.id)}),n}),Ae(!0)},[qe,I]),Xe=(0,y.useCallback)(e=>{Oe(t=>{let n=new Set(t);return qe.filter(t=>(t.location||``)===e).forEach(e=>n.add(e.id)),n}),Ae(!0)},[qe]),Ze=(0,y.useCallback)(e=>{Oe(t=>{let n=new Set(t);return qe.filter(t=>(t.model||`Unknown`)===e).forEach(e=>n.add(e.id)),n}),Ae(!0)},[qe]),Qe=(0,y.useCallback)(e=>{F(t=>{let n={...t,[e]:!t[e]};try{localStorage.setItem(`printerCollapsedSections`,JSON.stringify(n))}catch{}return n})},[]),$e=(0,y.useMemo)(()=>{if(p===`name`)return null;let e={};return p===`location`?qe.forEach(t=>{let n=t.location||`Ungrouped`;e[n]||(e[n]=[]),e[n].push(t)}):p===`model`?qe.forEach(t=>{let n=t.model||`Unknown`;e[n]||(e[n]=[]),e[n].push(t)}):p===`status`&&qe.forEach(t=>{let n=Wq(I.getQueryData([`printerStatus`,t.id]));e[n]||(e[n]=[]),e[n].push(t)}),e},[p,qe,I,M]),tt=(0,y.useRef)(null),nt=(0,y.useRef)(null),rt=(0,y.useRef)(0),[it,at]=(0,y.useState)(!1),ot=(0,y.useCallback)(()=>{let e=tt.current;if(!e)return;let t=nt.current?.offsetWidth;t&&(rt.current=t);let n=rt.current>0&&e.clientWidthe===n?e:n)},[]),st=Object.keys(we).length;(0,y.useLayoutEffect)(()=>{ot();let e=tt.current;if(!e)return;if(typeof ResizeObserver>`u`)return window.addEventListener(`resize`,ot),()=>window.removeEventListener(`resize`,ot);let t=new ResizeObserver(()=>ot());return t.observe(e),window.addEventListener(`resize`,ot),()=>{t.disconnect(),window.removeEventListener(`resize`,ot)}},[ot,ee?.length,Ke.length,s,st]);let ct=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[ee&&ee.length>0&&(0,G.jsx)(zq,{value:O,onChange:k,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allStatuses`)},{value:`printing`,label:e(`printers.status.printing`)},{value:`paused`,label:e(`printers.status.paused`)},{value:`idle`,label:e(`printers.status.idle`)},{value:`finished`,label:e(`printers.status.finished`)},{value:`error`,label:e(`printers.status.error`)},{value:`offline`,label:e(`printers.status.offline`)}]}),ee&&ee.length>0&&Ke.length>0&&(0,G.jsx)(zq,{value:A,onChange:j,fullWidth:t,options:[{value:`all`,label:e(`printers.filter.allLocations`)},...Ke.map(e=>({value:e,label:e}))]}),(0,G.jsx)(`button`,{type:`button`,onClick:Be,"aria-pressed":s,className:`h-8 px-2 rounded-lg border text-sm font-medium transition-colors ${t?`w-full`:``} ${s?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:e(`printers.hideOffline`)})]}),lt=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-1 ${t?`w-full`:``}`,children:[(0,G.jsx)(zq,{value:p,onChange:Ve,fullWidth:t,options:[{value:`name`,label:e(`printers.sort.name`)},{value:`status`,label:e(`printers.sort.status`)},{value:`model`,label:e(`printers.sort.model`)},{value:`location`,label:e(`printers.sort.location`)}]}),(0,G.jsx)(`button`,{onClick:He,className:`h-8 shrink-0 px-2 rounded-lg border bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary transition-colors flex items-center justify-center`,title:e(h?`printers.sort.descending`:`printers.sort.ascending`),children:h?(0,G.jsx)(No,{className:`w-4 h-4 text-white`}):(0,G.jsx)(Do,{className:`w-4 h-4 text-white`})})]}),(0,G.jsx)(`div`,{className:`flex h-8 items-center bg-bambu-dark rounded-lg border border-bambu-dark-tertiary ${t?`w-full`:``}`,children:We.map((n,r)=>{let i=r+1,a=_===i;return(0,G.jsx)(`button`,{onClick:()=>{S(null),v(i),localStorage.setItem(`printerCardSize`,String(i))},className:`h-full px-2 text-xs font-medium transition-colors ${t?`flex-1`:``} ${r===0?`rounded-l-lg`:``} ${r===We.length-1?`rounded-r-lg`:``} ${a?`bg-bambu-green text-white`:`text-white hover:bg-bambu-dark-tertiary`}`,title:e(n===`S`?`printers.cardSize.small`:n===`M`?`printers.cardSize.medium`:n===`L`?`printers.cardSize.large`:`printers.cardSize.extraLarge`),children:n},n)})})]}),ut=(t=!1)=>(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{onClick:()=>{Fe?Le():Ae(!0)},className:`h-8 px-2 rounded-lg border transition-colors ${t?`w-full justify-center gap-1.5 text-sm font-medium flex items-center`:``} ${Fe?`bg-bambu-green border-bambu-green text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,title:e(`printers.bulk.select`),disabled:!R(`printers:control`),children:[(0,G.jsx)(Ql,{className:`w-4 h-4`}),t&&(0,G.jsx)(`span`,{children:e(`printers.bulk.select`)})]}),s&&Object.keys(we).length>0&&(0,G.jsxs)(`div`,{className:`relative ${t?`w-full`:``}`,children:[(0,G.jsxs)(`button`,{onClick:()=>u(!l),className:`h-8 flex items-center gap-1.5 px-2 text-sm rounded-lg border transition-colors ${t?`w-full justify-between bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary hover:text-white`:`bg-bambu-dark border-bambu-dark-tertiary text-white hover:bg-bambu-dark-tertiary`}`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(yl,{className:`w-4 h-4`}),e(`printers.powerOn`)]}),(0,G.jsx)(es,{className:`w-3 h-3 transition-transform ${l?`rotate-180`:``}`})]}),l&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`fixed inset-0 z-10`,onClick:()=>u(!1)}),(0,G.jsxs)(`div`,{className:`absolute right-0 mt-2 w-56 bg-white dark:bg-bambu-dark-secondary border border-gray-200 dark:border-bambu-dark-tertiary rounded-lg shadow-lg z-20 py-1`,children:[(0,G.jsx)(`div`,{className:`px-3 py-2 text-xs text-gray-500 dark:text-bambu-gray border-b border-gray-200 dark:border-bambu-dark-tertiary`,children:e(`printers.offlinePrintersWithPlugs`)}),ee?.filter(e=>we[e.id]).map(e=>(0,G.jsx)(LTe,{printer:e,plug:we[e.id],onPowerOn:e=>{f(e),Ee.mutate(e)},isPowering:d===we[e.id]?.id},e.id)),ee?.filter(e=>we[e.id]).length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray`,children:`No printers with smart plugs`})]})]})]}),(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!R(`printers:create`),title:R(`printers:create`)?void 0:e(`printers.permission.noAdd`),className:`!h-8 !min-h-8 px-2 py-0 ${t?`w-full`:``}`,children:[(0,G.jsx)(_l,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]});return(0,G.jsxs)(`div`,{className:`p-4 md:p-8`,children:[(0,G.jsxs)(`div`,{className:`space-y-3 mb-6`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`h1`,{className:`text-2xl font-bold text-white flex items-center gap-3`,children:[(0,G.jsx)(bl,{className:`w-7 h-7 text-bambu-green`}),e(`printers.title`)]}),(0,G.jsx)(kTe,{printers:ee})]}),(0,G.jsxs)(`div`,{ref:tt,className:`relative flex items-center gap-2`,children:[ee&&ee.length>0&&(0,G.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,G.jsx)(Ml,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray/50`}),(0,G.jsx)(`input`,{type:`search`,name:`printer-search`,autoComplete:`off`,"data-1p-ignore":!0,"data-lpignore":`true`,value:E,onChange:e=>D(e.target.value),placeholder:e(`printers.search`),"aria-label":e(`printers.search`),className:`w-full h-8 pl-9 pr-8 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm placeholder:text-bambu-gray/50 focus:outline-none focus:border-bambu-green`}),E&&(0,G.jsx)(`button`,{type:`button`,"aria-label":e(`common.clear`),onClick:()=>D(``),className:`absolute right-3 top-1/2 -translate-y-1/2 text-bambu-gray hover:text-white`,children:(0,G.jsx)(Nu,{className:`w-4 h-4`})})]}),(0,G.jsxs)(`div`,{ref:nt,"aria-hidden":it,inert:it,className:`${it?`absolute -left-[9999px] top-0 flex w-max pointer-events-none opacity-0`:`flex`} ml-auto items-center justify-end gap-2 flex-nowrap [&>*]:shrink-0`,children:[(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:ct()}),(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:lt()}),(0,G.jsx)(`div`,{className:`h-6 w-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`div`,{className:`flex items-center gap-2`,children:ut()})]}),it&&(0,G.jsxs)(`div`,{className:`ml-auto flex items-center justify-end gap-1`,children:[(0,G.jsx)(Bq,{label:e(`printers.toolbar.filters`,`Filters`),icon:(0,G.jsx)(lc,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:ct(!0)})}),(0,G.jsx)(Bq,{label:e(`printers.toolbar.view`,`View`),icon:(0,G.jsx)(Kl,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:lt(!0)})}),(0,G.jsx)(Bq,{label:e(`printers.toolbar.actions`,`Actions`),icon:(0,G.jsx)(Bs,{className:`w-4 h-4`}),children:(0,G.jsx)(`div`,{className:`flex w-48 flex-col gap-2`,children:ut(!0)})})]})]})]}),te?(0,G.jsx)(`div`,{className:`text-center py-12 text-bambu-gray`,children:e(`common.loading`)}):ee?.length===0?(0,G.jsx)(dd,{children:(0,G.jsxs)(pd,{className:`text-center py-12`,children:[(0,G.jsx)(`p`,{className:`text-bambu-gray mb-4`,children:e(`printers.noPrintersConfigured`)}),(0,G.jsxs)(Q,{onClick:()=>o(!0),disabled:!R(`printers:create`),title:R(`printers:create`)?void 0:e(`printers.permission.noAdd`),children:[(0,G.jsx)(_l,{className:`w-4 h-4`}),e(`printers.addPrinter`)]})]})}):qe.length===0&&(E.trim()||O!==`all`||A!==`all`)?(0,G.jsx)(dd,{children:(0,G.jsx)(pd,{className:`text-center py-12`,children:(0,G.jsx)(`p`,{className:`text-bambu-gray`,children:e(`printers.noSearchResults`)})})}):$e?(0,G.jsx)(`div`,{className:`space-y-6`,children:(()=>{let e=p===`status`?jTe.filter(e=>$e[e]?.length>0):Object.keys($e);return h?e:[...e].reverse()})().map(t=>{let n=$e[t],r=`${p}:${t}`,i=!P[r],a=p===`status`&&Uq[t]?.dot||`bg-bambu-green`,o=p===`status`?e(Uq[t]?.labelKey||t):t;return(0,G.jsx)(xf,{open:i,onToggle:()=>Qe(r),summaryClassName:`py-1`,summary:(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`w-2 h-2 rounded-full ${a}`}),o,(0,G.jsxs)(`span`,{className:`text-sm font-normal text-bambu-gray`,children:[`(`,n.length,`)`]}),Fe&&(0,G.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p===`location`?Xe(t===`Ungrouped`?``:t):p===`status`?Ye(t):p===`model`&&Ze(t)},className:`text-xs text-bambu-green hover:text-bambu-green-light transition-colors ml-1`,children:e(`printers.bulk.selectAll`)})]}),children:(0,G.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${Ue()}`,children:n.map(e=>(0,G.jsx)(Jq,{printer:e,hideIfDisconnected:s,maintenanceInfo:Ce[e.id],viewMode:b,cardSize:_,amsThresholds:V?{humidityGood:Number(V.ams_humidity_good)||40,humidityFair:Number(V.ams_humidity_fair)||60,tempGood:Number(V.ams_temp_good)||28,tempFair:Number(V.ams_temp_fair)||35}:void 0,spoolmanEnabled:ce,hasUnlinkedSpools:fe,linkedSpools:me,spoolmanUrl:se?.url,spoolmanSyncMode:ue,onGetAssignment:Se,onUnassignSpool:(e,t,n)=>ge.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:_e,spoolmanSlotAssignments:ye,spoolmanLoading:ve||be,onUnassignSpoolmanSpool:e=>xe.mutate(e),timeFormat:V?.time_format||`system`,cameraViewMode:V?.camera_view_mode||`window`,onOpenEmbeddedCamera:(e,t)=>B(n=>new Map(n).set(e,{id:e,name:t})),checkPrinterFirmware:V?.check_printer_firmware!==!1,dryingPresets:ae,nozzleTempPresets:ne,bedTempPresets:re,chamberTempPresets:ie,fanSpeedPresets:H,requirePlateClear:V?.require_plate_clear===!0,selectionMode:Fe,isSelected:De.has(e.id),onToggleSelect:Ie,onOpenCompactCard:w},e.id))})},t)})}):(0,G.jsx)(`div`,{className:`grid gap-4 ${_>=3?`gap-6`:``} ${Ue()}`,children:qe.map(e=>(0,G.jsx)(Jq,{printer:e,hideIfDisconnected:s,maintenanceInfo:Ce[e.id],viewMode:b,cardSize:_,spoolmanEnabled:ce,hasUnlinkedSpools:fe,linkedSpools:me,spoolmanUrl:se?.url,spoolmanSyncMode:ue,onGetAssignment:Se,onUnassignSpool:(e,t,n)=>ge.mutate({printerId:e,amsId:t,trayId:n}),spoolmanSpools:_e,spoolmanSlotAssignments:ye,spoolmanLoading:ve||be,onUnassignSpoolmanSpool:e=>xe.mutate(e),amsThresholds:V?{humidityGood:Number(V.ams_humidity_good)||40,humidityFair:Number(V.ams_humidity_fair)||60,tempGood:Number(V.ams_temp_good)||28,tempFair:Number(V.ams_temp_fair)||35}:void 0,timeFormat:V?.time_format||`system`,cameraViewMode:V?.camera_view_mode||`window`,onOpenEmbeddedCamera:(e,t)=>B(n=>new Map(n).set(e,{id:e,name:t})),checkPrinterFirmware:V?.check_printer_firmware!==!1,dryingPresets:ae,nozzleTempPresets:ne,bedTempPresets:re,chamberTempPresets:ie,fanSpeedPresets:H,requirePlateClear:V?.require_plate_clear===!0,selectionMode:Fe,isSelected:De.has(e.id),onToggleSelect:Ie,onOpenCompactCard:w},e.id))}),_===2&&x!=null&&(0,G.jsxs)(`button`,{type:`button`,onClick:T,className:`fixed bottom-5 left-1/2 z-40 inline-flex -translate-x-1/2 items-center gap-2 rounded-full border px-4 py-2 text-sm font-medium shadow-xl transition-colors ${i}`,title:e(`common.back`,`Back`),children:[(0,G.jsx)(Oo,{className:`w-4 h-4`}),e(`common.back`,`Back`)]}),a&&(0,G.jsx)(NTe,{onClose:()=>o(!1),onAdd:e=>Te.mutate(e),existingSerials:ee?.map(e=>e.serial_number)||[]}),Fe&&ee&&(0,G.jsx)(ip,{selectedIds:De,printers:ee,onClose:Le,onSelectAll:Je,onSelectByLocation:Xe,onSelectByState:Ye,onAction:ze,actionPending:Ne}),je===`stop`&&(0,G.jsx)(wd,{title:e(`printers.bulk.confirm.stopTitle`,{count:De.size}),message:e(`printers.bulk.confirm.stopMessage`,{count:De.size}),confirmText:e(`printers.bulk.confirm.stopButton`),variant:`danger`,isLoading:Ne,onConfirm:()=>Re(`stop`),onCancel:()=>Me(null)}),je===`pause`&&(0,G.jsx)(wd,{title:e(`printers.bulk.confirm.pauseTitle`,{count:De.size}),message:e(`printers.bulk.confirm.pauseMessage`,{count:De.size}),confirmText:e(`printers.bulk.confirm.pauseButton`),isLoading:Ne,onConfirm:()=>Re(`pause`),onCancel:()=>Me(null)}),je===`clearPlate`&&(0,G.jsx)(wd,{title:e(`printers.bulk.confirm.clearPlateTitle`,{count:De.size}),message:e(`printers.bulk.confirm.clearPlateMessage`,{count:De.size}),confirmText:e(`printers.bulk.confirm.clearPlateButton`),isLoading:Ne,onConfirm:()=>Re(`clearPlate`),onCancel:()=>Me(null)}),Array.from(z.values()).map((e,t)=>(0,G.jsx)(cce,{printerId:e.id,printerName:e.name,viewerIndex:t,onClose:()=>B(t=>{let n=new Map(t);return n.delete(e.id),n})},e.id))]})}function zTe({title:e,message:t,subtitle:n,closeText:r,variant:i=`error`,onClose:a}){let{t:o}=et(),s=r??o(`common.close`);return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&a()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[a]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-[120]`,onClick:a,children:(0,G.jsx)(dd,{className:`w-full max-w-md`,onClick:e=>e.stopPropagation(),children:(0,G.jsxs)(pd,{className:`p-6`,children:[(0,G.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,G.jsx)(`div`,{className:`p-2 rounded-full bg-bambu-dark ${i===`warning`?`text-yellow-400`:`text-red-400`}`,children:(0,G.jsx)(_u,{className:`w-6 h-6`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-lg font-semibold text-white mb-1`,children:e}),n&&(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2 truncate`,children:n}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm whitespace-pre-line break-words`,children:t})]})]}),(0,G.jsx)(`div`,{className:`flex mt-6`,children:(0,G.jsx)(Q,{onClick:a,className:`flex-1`,children:s})})]})})})}var Yq=(0,y.createContext)(null),BTe=1500,VTe=1e3,Xq=e=>`slice-job-${e}`;function Zq(e){try{return decodeURIComponent(e)}catch{return e}}function HTe(e){let t=Math.max(0,Math.floor(e));if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function UTe({children:e}){let{t}=et(),{showToast:n,showPersistentToast:r,dismissToast:i}=yd(),a=$a(),[o,s]=(0,y.useState)([]),[c,l]=(0,y.useState)(null),u=(0,y.useRef)([]);u.current=o;let d=(0,y.useRef)(new Map),f=(0,y.useRef)(new Map),p=(0,y.useRef)(new Map),m=(0,y.useCallback)(e=>{let n=d.current.get(e.id);if(n==null)return;let i=(Date.now()-n)/1e3,a=f.current.get(e.id)??`pending`,o=HTe(i),s=p.current.get(e.id)??null,c=s&&s.stage&&s.total_percent>0;if(a===`running`&&c){let n=Zq(e.sourceName),i=s.stage,a=Math.min(100,Math.max(0,Math.round(s.total_percent))),c=typeof s.multi_plate_index==`number`&&typeof s.multi_plate_count==`number`&&s.multi_plate_count>1?t(`slice.runningWithProgressMultiPlate`,`Plate {{plateIndex}} of {{plateCount}} • {{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{plateIndex:s.multi_plate_index,plateCount:s.multi_plate_count,name:n,stage:i,percent:a,elapsed:o}):t(`slice.runningWithProgress`,`{{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{name:n,stage:i,percent:a,elapsed:o});r(Xq(e.id),c,`loading`);return}let l=a===`pending`?`slice.queuedToast`:`slice.runningToast`,u=a===`pending`?`Queued: {{name}} — {{elapsed}}`:`Slicing {{name}} — {{elapsed}}`;r(Xq(e.id),t(l,u,{name:Zq(e.sourceName),elapsed:o}),`loading`)},[r,t]),h=(0,y.useCallback)((e,t,n)=>{s(r=>r.some(t=>t.id===e)?r:[...r,{id:e,kind:t,sourceName:n}]),d.current.set(e,Date.now()),f.current.set(e,`pending`),p.current.set(e,null),m({id:e,kind:t,sourceName:n})},[m]),g=(0,y.useCallback)((e,r)=>{s(t=>t.filter(t=>t.id!==e.id)),d.current.delete(e.id),f.current.delete(e.id),p.current.delete(e.id),i(Xq(e.id)),r.status===`completed`?n(t(`slice.completedToast`,`Sliced {{name}}`,{name:Zq(e.sourceName)}),`success`):r.status===`failed`&&l({name:Zq(e.sourceName),detail:r.error_detail||t(`slice.failed`)}),a.invalidateQueries({queryKey:[`library-files`]}),a.invalidateQueries({queryKey:[`archives`]})},[i,a,n,t]);return(0,y.useEffect)(()=>{if(o.length===0)return;let e=!1,t=setInterval(async()=>{if(e)return;let t=[...u.current];for(let e of t)try{let t=await Z.getSliceJob(e.id);f.current.set(e.id,t.status),t.progress&&p.current.set(e.id,t.progress),(t.status===`completed`||t.status===`failed`)&&g(e,t)}catch{}},BTe);return()=>{e=!0,clearInterval(t)}},[o.length,g]),(0,y.useEffect)(()=>{if(o.length===0)return;let e=setInterval(()=>{for(let e of u.current)m(e)},VTe);return()=>clearInterval(e)},[o.length,m]),(0,G.jsxs)(Yq.Provider,{value:{trackJob:h,activeJobs:o},children:[e,c&&(0,G.jsx)(zTe,{title:t(`slice.failedTitle`),subtitle:c.name,message:c.detail,onClose:()=>l(null)})]})}function WTe(){let e=(0,y.useContext)(Yq);if(!e)throw Error(`useSliceJobTracker must be used inside SliceJobTrackerProvider`);return e}function Qq({plates:e,onSelect:t,onClose:n}){let{t:r}=et();return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`w-full max-w-3xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`h3`,{className:`text-white font-medium`,children:r(`archives.platePicker.title`)}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`archives.platePicker.hint`)})]}),(0,G.jsx)(`button`,{onClick:n,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors`,"aria-label":r(`common.close`,`Close`),children:(0,G.jsx)(Nu,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:(0,G.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:e.map(e=>(0,G.jsxs)(`button`,{type:`button`,onClick:()=>t(e.index),className:`flex items-center gap-2 p-2 rounded-lg border border-bambu-dark-tertiary bg-bambu-dark hover:border-bambu-gray transition-colors text-left`,children:[e.has_thumbnail&&e.thumbnail_url!=null?(0,G.jsx)(`img`,{src:Gu(e.thumbnail_url),alt:`Plate ${e.index}`,className:`w-12 h-12 rounded object-cover bg-bambu-dark-tertiary flex-shrink-0`}):(0,G.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center flex-shrink-0`,children:(0,G.jsx)(Nc,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white font-medium truncate`,children:e.name?`${r(`archives.platePicker.plateLabel`,{index:e.index})} — ${e.name}`:r(`archives.platePicker.plateLabel`,{index:e.index})}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray truncate`,children:[e.objects.length>0?e.objects.slice(0,3).join(`, `)+(e.objects.length>3?`…`:``):e.object_count!=null&&e.object_count>0?r(`archives.platePicker.objectCount`,{count:e.object_count}):`${e.filaments.length} filament${e.filaments.length===1?``:`s`}`,e.print_time_seconds==null?``:` • ${cf(e.print_time_seconds)}`]})]})]},e.index))})})]})})}var $q=[`local`,`orca_cloud`,`cloud`,`standard`];function eJ(e,t){for(let n of $q){let r=e[n][t];if(r.length>0)return{source:r[0].source,id:r[0].id}}return null}function tJ(e,t,n){return t?e[t.source][n].find(e=>e.id===t.id)??null:null}function nJ(e,t,n){if(!n)return null;for(let r of $q){let i=e[r][t].find(e=>e.name===n);if(i)return{source:i.source,id:i.id}}return null}function GTe(e,t,n,r){let i=nJ(e,`process`,r);if(i){let r=tJ(e,i,`process`);if(r&&EK(r,`process`,t,n)!==`mismatch`)return i}for(let r of[`match`,`unknown`])for(let i of $q)for(let a of e[i].process)if(EK(a,`process`,t,n)===r)return{source:a.source,id:a.id};return eJ(e,`process`)}var KTe={local:1.75,orca_cloud:1.5,cloud:1,standard:.5};function qTe(e,t,n,r){let i=t.type.trim().toUpperCase(),a=$K(t.color),o=null;for(let s of $q)for(let c of e[s].filament){let e=0,l=(c.filament_type??``).trim().toUpperCase(),u=$K(c.filament_colour??``);i&&l&&i===l&&(e+=10),a&&u&&(u===a?e+=5:rq(c.filament_colour??``,t.color)&&(e+=2)),e+=KTe[s],EK(c,`filament`,n,r)===`mismatch`&&(e-=100),(o==null||e>o.score)&&(o={ref:{source:c.source,id:c.id},score:e})}return o==null?eJ(e,`filament`):o.ref}function JTe(e){return e?`${e.source}:${e.id}`:``}function YTe(e){if(!e)return null;let t=e.indexOf(`:`);if(t<0)return null;let n=e.slice(0,t),r=e.slice(t+1);return n!==`orca_cloud`&&n!==`cloud`&&n!==`local`&&n!==`standard`?null:{source:n,id:r}}function XTe({requestId:e,sourceName:t}){let{t:n}=et(),{showPersistentToast:r,dismissToast:i}=yd(),[a,o]=(0,y.useState)(0),[s,c]=(0,y.useState)(null),l=t;try{l=decodeURIComponent(t)}catch{}(0,y.useEffect)(()=>{let e=Date.now(),t=setInterval(()=>o(Math.floor((Date.now()-e)/1e3)),1e3);return()=>clearInterval(t)},[]),(0,y.useEffect)(()=>{let t=!1,n=setInterval(async()=>{if(t)return;let n=await Z.getPreviewSliceProgress(e);!t&&n&&c(n)},1e3);return()=>{t=!0,clearInterval(n)}},[e]);let u=`slice-preview-${e}`;(0,y.useEffect)(()=>{let e=s&&s.stage&&s.total_percent>0,t=ZTe(a);return e?r(u,n(`slice.previewWithProgress`,`Analyzing {{name}} — {{stage}} ({{percent}}%) — {{elapsed}}`,{name:l,stage:s.stage,percent:Math.min(100,Math.max(0,Math.round(s.total_percent))),elapsed:t}),`loading`):r(u,n(`slice.previewToast`,{name:l,elapsed:t}),`loading`),()=>{i(u)}},[a,s,l,r,i,n,u]);let d=s?.stage,f=s?.total_percent,p=d&&typeof f==`number`&&f>0?`${d} (${Math.min(100,Math.max(0,Math.round(f)))}%)`:n(`slice.analyzingPlateFilaments`);return(0,G.jsxs)(`div`,{className:`flex flex-col gap-1 text-bambu-gray text-sm py-2`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),p,(0,G.jsxs)(`span`,{className:`text-xs tabular-nums`,children:[a,`s`]})]}),a>=5&&(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray/70 pl-6`,children:n(`slice.analyzingPlateFilamentsHint`,`Running a preview slice to discover which AMS slots this plate uses. Cached after — re-opening is instant.`)})]})}function ZTe(e){let t=Math.max(0,Math.floor(e));if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return n<60?`${n}m ${r}s`:`${Math.floor(n/60)}h ${n%60}m`}function rJ({source:e,onClose:t}){let{t:n}=et(),{trackJob:r}=WTe(),i=$a(),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)([]),[d,f]=(0,y.useState)(null),[p,m]=(0,y.useState)(null),[h,g]=(0,y.useState)(!1),[_,v]=(0,y.useState)(null),b=K({queryKey:[`slicePlates`,e.kind,e.id],queryFn:async()=>e.kind===`libraryFile`?Z.getLibraryFilePlates(e.id):Z.getArchivePlates(e.id),staleTime:6e4}),x=!!b.data?.is_multi_plate&&(b.data?.plates?.length??0)>1,S=x&&p==null,C=p??1,w=(0,y.useMemo)(()=>{let t=typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`;return`${e.kind}-${e.id}-p${C}-${t}`},[e.kind,e.id,C]),T=K({queryKey:[`sliceFilamentReqs`,e.kind,e.id,C],queryFn:async()=>e.kind===`libraryFile`?Z.getLibraryFileFilamentRequirements(e.id,C,w):Z.getArchiveFilamentRequirements(e.id,C,w),enabled:!S,staleTime:6e4}),E=(0,y.useMemo)(()=>{let e=T.data?.filaments??[],t=e.length>0?e:[{slot_id:1,type:``,color:``,used_grams:0,used_meters:0}];return h?t.map(e=>({...e,used_in_plate:!0})):t},[h,T.data]),D=K({queryKey:[`slicerPresets`],queryFn:()=>Z.getSlicerPresets(),staleTime:6e4,enabled:!b.isLoading&&!S}),[O,k]=(0,y.useState)(!1),A=async()=>{if(!O){k(!0);try{let e=await Z.getSlicerPresets({refresh:!0});i.setQueryData([`slicerPresets`],e)}catch{i.invalidateQueries({queryKey:[`slicerPresets`]})}finally{k(!1)}}},j=K({queryKey:[`slicerPrinterModels`],queryFn:Z.getSlicerPrinterModels,staleTime:1/0}),M=(0,y.useMemo)(()=>!D.data||!a?null:tJ(D.data,a,`printer`)?.name??null,[D.data,a]),N=(0,y.useMemo)(()=>CK(j.data??{}),[j.data]),P=b.data?.embedded_printer??null,F=b.data?.embedded_process??null;(0,y.useEffect)(()=>{let e=D.data;e&&(a??o(nJ(e,`printer`,P)??eJ(e,`printer`)))},[D.data,P]),(0,y.useEffect)(()=>{let e=D.data;e&&c(t=>{if(t){let n=tJ(e,t,`process`);if(n&&EK(n,`process`,M,N)!==`mismatch`)return t}return GTe(e,M,N,F)})},[D.data,M,N,F]),(0,y.useEffect)(()=>{let e=D.data;e&&u(t=>E.map((n,r)=>{let i=t[r]??null;if(i){let t=tJ(e,i,`filament`);if(t&&EK(t,`filament`,M,N)!==`mismatch`)return i}return qTe(e,{type:n.type,color:n.color},M,N)}))},[D.data,E,M,N]);let I=q({mutationFn:async t=>{let n=L(t);return e.kind===`libraryFile`?Z.sliceLibraryFile(e.id,n):Z.sliceArchive(e.id,n)},onSuccess:n=>{r(n.job_id,e.kind,e.filename),t()},onError:e=>{f(e instanceof Error?e.message:String(e))}});function L(e){if(!a||!s||l.length===0||l.some(e=>e==null))throw Error(n(`slice.allPresetsRequired`));return{printer_preset:a,process_preset:s,filament_preset:l[0],filament_presets:l,...e==null?{}:{plate:e},..._==null?{}:{bed_type:_}}}let R=a!=null&&s!=null&&T.isSuccess&&l.length>0&&l.every(e=>e!=null),z=I.isPending,B=b.data?.plates?.length??0,ee=x&&B>1&&!S;return S&&b.data?(0,G.jsx)(Qq,{plates:b.data.plates,onSelect:e=>m(e),onClose:t}):(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:()=>{z||t()},children:(0,G.jsxs)(`div`,{className:`w-full max-w-xl max-h-[85vh] flex flex-col rounded-lg bg-bambu-dark-secondary border border-bambu-dark-tertiary/60`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex items-start justify-between gap-3 px-4 pt-4 pb-3 border-b border-bambu-dark-tertiary/40`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`h3`,{className:`text-white font-medium flex items-center gap-2`,children:[(0,G.jsx)(ws,{className:`w-4 h-4`}),n(`slice.title`)]}),(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mt-1 truncate`,title:e.filename,children:[e.filename,p==null?``:` • ${n(`archives.platePicker.plateLabel`,{index:p})}`]})]}),(0,G.jsx)(`button`,{onClick:t,disabled:z,className:`flex-shrink-0 text-bambu-gray hover:text-white transition-colors disabled:opacity-50`,"aria-label":n(`common.close`),children:(0,G.jsx)(Nu,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(b.isLoading||D.isLoading)&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-bambu-gray text-sm`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`slice.loadingPresets`)]}),D.isError&&(0,G.jsx)(`div`,{className:`text-sm text-red-400`,role:`alert`,children:n(`slice.presetsLoadFailed`,`Failed to load presets. Open Settings → Profiles to import them, or sign in to Bambu Cloud.`)}),D.data&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,G.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,G.jsx)(iJ,{status:D.data.cloud_status,cloudName:`bambu`}),(0,G.jsx)(iJ,{status:D.data.orca_cloud_status,cloudName:`orca`})]}),(0,G.jsxs)(`button`,{type:`button`,onClick:A,disabled:O||z,className:`flex-shrink-0 inline-flex items-center gap-1 px-2 py-1 rounded-md text-xs text-bambu-gray hover:text-white hover:bg-bambu-dark-tertiary/40 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,title:n(`slice.refreshPresetsTitle`),"aria-label":n(`slice.refreshPresets`),children:[(0,G.jsx)(Cl,{className:`w-3.5 h-3.5 ${O?`animate-spin`:``}`}),n(`slice.refreshPresets`)]})]}),(0,G.jsx)(aJ,{label:n(`slice.printer`),slot:`printer`,data:D.data,value:a,onChange:o,disabled:z}),(0,G.jsx)(aJ,{label:n(`slice.process`),slot:`process`,data:D.data,value:s,onChange:c,disabled:z,selectedPrinterName:M,compatIndex:N}),(0,G.jsx)($Te,{value:_,onChange:v,disabled:z}),T.isLoading?(0,G.jsx)(XTe,{requestId:w,sourceName:e.filename}):E.map((e,t)=>{let r=e.used_in_plate!==!1,i=E.length>1?n(`slice.filamentSlot`,{index:t+1,type:e.type}):n(`slice.filament`);return(0,G.jsx)(aJ,{label:r?i:`${i} ${n(`slice.notUsedByPlate`)}`,slot:`filament`,data:D.data,value:l[t]??null,onChange:e=>u(n=>{let r=n.length===E.length?[...n]:E.map((e,t)=>n[t]??null);return r[t]=e,r}),disabled:z||!r,swatchColor:E.length>1?e.color:void 0,selectedPrinterName:M,compatIndex:N},`filament-${t}`)})]}),d&&(0,G.jsx)(`div`,{className:`text-sm text-red-400 bg-red-900/20 border border-red-900/40 rounded p-2`,role:`alert`,children:d})]}),(0,G.jsxs)(`div`,{className:`flex-shrink-0 flex justify-end gap-2 px-4 py-3 border-t border-bambu-dark-tertiary/40`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:t,disabled:z,className:`px-3 py-1.5 text-sm rounded-md border border-bambu-dark-tertiary text-bambu-gray hover:text-white hover:border-bambu-gray transition-colors disabled:opacity-50`,children:n(`common.cancel`)}),ee&&(0,G.jsxs)(`label`,{className:`flex items-center gap-2 mr-auto text-sm text-bambu-gray cursor-pointer select-none`,title:n(`slice.actionAllTitle`,{count:B}),children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:h,onChange:e=>g(e.target.checked),disabled:z,className:`cursor-pointer`}),n(`slice.allPlatesToggle`,{count:B})]}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>{f(null);let e=h?0:p;I.mutate(e)},disabled:!R||z,className:`px-3 py-1.5 text-sm rounded-md bg-bambu-green hover:bg-bambu-green/90 text-bambu-dark font-medium transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2`,children:z?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`slice.enqueuing`)]}):h?n(`slice.actionAll`,{count:B}):n(`slice.action`)})]})]})})}function iJ({status:e,cloudName:t=`bambu`}){let{t:n}=et();if(e===`ok`||e===`not_authenticated`)return null;let r=t===`orca`?{expired:{key:`slice.orcaCloud.expired`,fallback:`Orca Cloud session expired — sign in again to refresh your Orca presets.`},unreachable:{key:`slice.orcaCloud.unreachable`,fallback:`Orca Cloud is unreachable right now. Other presets still work.`}}:{expired:{key:`slice.cloud.expired`,fallback:`Bambu Cloud session expired — sign in again to refresh your cloud presets.`},unreachable:{key:`slice.cloud.unreachable`,fallback:`Bambu Cloud is unreachable right now. Local and standard presets still work.`}},{tone:i,icon:a}={expired:{tone:`border-amber-700/40 bg-amber-900/20 text-amber-200`,icon:vs},unreachable:{tone:`border-bambu-dark-tertiary/40 bg-bambu-dark text-bambu-gray`,icon:vs}}[e],{key:o,fallback:s}=r[e];return(0,G.jsxs)(`div`,{className:`flex items-start gap-2 text-xs rounded-md border p-2 ${i}`,role:`status`,children:[(0,G.jsx)(a,{className:`w-4 h-4 flex-shrink-0 mt-0.5`}),(0,G.jsx)(`span`,{children:n(o,s)})]})}var QTe=[{value:`Cool Plate`,labelKey:`slice.bedType.coolPlate`,fallback:`Cool Plate`},{value:`Cool Plate (SuperTack)`,labelKey:`slice.bedType.coolPlateSuperTack`,fallback:`Cool Plate SuperTack`},{value:`Engineering Plate`,labelKey:`slice.bedType.engineering`,fallback:`Engineering Plate`},{value:`High Temp Plate`,labelKey:`slice.bedType.highTemp`,fallback:`High Temp Plate`},{value:`Textured PEI Plate`,labelKey:`slice.bedType.texturedPEI`,fallback:`Textured PEI Plate`},{value:`Smooth PEI Plate`,labelKey:`slice.bedType.smoothPEI`,fallback:`Smooth PEI Plate`}];function $Te({value:e,onChange:t,disabled:n}){let{t:r}=et();return(0,G.jsxs)(`label`,{className:`block`,children:[(0,G.jsx)(`span`,{className:`block text-xs text-bambu-gray mb-1`,children:r(`slice.bedType.label`)}),(0,G.jsxs)(`select`,{value:e??``,onChange:e=>t(e.target.value===``?null:e.target.value),disabled:n,className:`w-full px-3 py-2 rounded-md bg-bambu-dark border border-bambu-dark-tertiary text-white text-sm focus:outline-none focus:border-bambu-gray disabled:opacity-50`,children:[(0,G.jsx)(`option`,{value:``,children:r(`slice.bedType.auto`)}),QTe.map(e=>(0,G.jsx)(`option`,{value:e.value,children:r(e.labelKey,e.fallback)},e.value))]})]})}function aJ({label:e,slot:t,data:n,value:r,onChange:i,disabled:a,swatchColor:o,selectedPrinterName:s,compatIndex:c}){let{t:l}=et(),{sections:u,otherEntries:d}=(0,y.useMemo)(()=>{let e=[{key:`local`,label:`slice.tier.local`,fallback:`Imported`},{key:`orca_cloud`,label:`slice.tier.orcaCloud`,fallback:`Orca Cloud`},{key:`cloud`,label:`slice.tier.cloud`,fallback:`Bambu Cloud`},{key:`standard`,label:`slice.tier.standard`,fallback:`Standard`}],r=t!==`printer`,i=[],a=[];for(let{key:o,label:u,fallback:d}of e){let e=n[o][t];if(!r){e.length>0&&i.push({tierLabel:l(u,d),entries:e});continue}let f=[];for(let n of e)EK(n,t,s??null,c??Bwe)===`mismatch`?a.push(n):f.push(n);f.length>0&&i.push({tierLabel:l(u,d),entries:f})}return{sections:i,otherEntries:a}},[n,t,l,s,c]),f=u.reduce((e,t)=>e+t.entries.length,0)+d.length;return(0,G.jsxs)(`label`,{className:`block`,children:[(0,G.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-bambu-gray mb-1`,children:[o&&(0,G.jsx)(`span`,{className:`inline-block w-3 h-3 rounded-full border border-bambu-dark-tertiary`,style:{backgroundColor:o||`transparent`},"aria-hidden":!0}),(0,G.jsx)(`span`,{children:e})]}),(0,G.jsxs)(`select`,{value:JTe(r),onChange:e=>i(YTe(e.target.value)),disabled:a||f===0,className:`w-full px-3 py-2 rounded-md bg-bambu-dark border border-bambu-dark-tertiary text-white text-sm focus:outline-none focus:border-bambu-gray disabled:opacity-50`,children:[(0,G.jsx)(`option`,{value:``,children:l(f===0?`slice.noPresetsForSlot`:`slice.selectPreset`)}),u.map(e=>(0,G.jsx)(`optgroup`,{label:e.tierLabel,children:e.entries.map(e=>(0,G.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))},e.tierLabel)),d.length>0&&(0,G.jsx)(`optgroup`,{label:l(`slice.otherPrinters`),children:d.map(e=>(0,G.jsx)(`option`,{value:`${e.source}:${e.id}`,children:e.name},`${e.source}:${e.id}`))})]})]})}function eEe(){let e=navigator.userAgent.toLowerCase(),t=navigator.platform?.toLowerCase()||``;return e.includes(`win`)||t.includes(`win`)?`windows`:e.includes(`mac`)||t.includes(`mac`)?`macos`:e.includes(`linux`)||t.includes(`linux`)?`linux`:`unknown`}function oJ(e,t=`bambu_studio`){let n,r=encodeURIComponent(e);n=t===`orcaslicer`?`orcaslicer://open?file=${r}`:eEe()===`macos`?`bambustudioopen://${r}`:`bambustudio://open?file=${r}`;let i=document.createElement(`a`);i.href=n,i.style.display=`none`,document.body.appendChild(i),i.click(),document.body.removeChild(i)}var sJ=768;function cJ(){let[e,t]=(0,y.useState)(()=>typeof window<`u`?window.innerWidth{let e=window.matchMedia(`(max-width: ${sJ-1}px)`),n=e=>{t(e.matches)};return t(e.matches),e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}function tEe({onClose:e,initialFiles:t}){let{t:n}=et(),r=$a(),{showToast:i}=yd(),a=(0,y.useRef)(null),[o,s]=(0,y.useState)(()=>t?.filter(e=>e.name.endsWith(`.3mf`)).map(e=>({file:e,status:`pending`}))||[]),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(null);(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let f=q({mutationFn:e=>Z.uploadArchivesBulk(e),onSuccess:e=>{d(e),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`archiveStats`]}),s(t=>t.map(t=>{let n=e.results.find(e=>e.filename===t.file.name),r=e.errors.find(e=>e.filename===t.file.name);return n?{...t,status:`success`,archiveId:n.id}:r?{...t,status:`error`,error:r.error}:t})),e.failed===0?i(`${e.uploaded} file${e.uploaded===1?``:`s`} uploaded`):e.uploaded===0?i(`Failed to upload ${e.failed} file${e.failed===1?``:`s`}`,`error`):i(`${e.uploaded} uploaded, ${e.failed} failed`,`warning`)},onError:()=>{s(e=>e.map(e=>({...e,status:`error`,error:`Upload failed`}))),i(`Upload failed`,`error`)}}),p=(0,y.useCallback)(e=>{e.preventDefault(),l(!0)},[]),m=(0,y.useCallback)(e=>{e.preventDefault(),l(!1)},[]),h=(0,y.useCallback)(e=>{e.preventDefault(),l(!1);let t=Array.from(e.dataTransfer.files).filter(e=>e.name.endsWith(`.3mf`));t.length>0&&s(e=>[...e,...t.map(e=>({file:e,status:`pending`}))])},[]),g=(0,y.useCallback)(e=>{let t=Array.from(e.target.files||[]).filter(e=>e.name.endsWith(`.3mf`));t.length>0&&s(e=>[...e,...t.map(e=>({file:e,status:`pending`}))]),a.current&&(a.current.value=``)},[]),_=(0,y.useCallback)(e=>{s(t=>t.filter((t,n)=>n!==e))},[]),v=()=>{if(o.length===0)return;let e=o.filter(e=>e.status===`pending`);e.length!==0&&(s(e=>e.map(e=>e.status===`pending`?{...e,status:`uploading`}:e)),f.mutate(e.map(e=>e.file)))},b=o.filter(e=>e.status===`pending`).length,x=f.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(dd,{className:`w-full max-w-2xl max-h-[90vh] flex flex-col`,children:(0,G.jsxs)(pd,{className:`p-0 flex flex-col h-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:n(`uploadModal.title`)}),(0,G.jsx)(`button`,{onClick:e,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(Nu,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`p-4`,children:(0,G.jsxs)(`div`,{className:`border-2 border-dashed rounded-lg p-8 text-center transition-colors ${c?`border-bambu-green bg-bambu-green/10`:`border-bambu-dark-tertiary hover:border-bambu-gray`}`,onDragOver:p,onDragLeave:m,onDrop:h,children:[(0,G.jsx)(xu,{className:`w-12 h-12 mx-auto mb-4 text-bambu-gray`}),(0,G.jsx)(`p`,{className:`text-white mb-2`,children:n(`uploadModal.dragDrop`)}),(0,G.jsx)(`p`,{className:`text-bambu-gray text-sm mb-4`,children:n(`uploadModal.or`)}),(0,G.jsx)(Q,{variant:`secondary`,onClick:()=>a.current?.click(),disabled:x,children:n(`uploadModal.browseFiles`)}),(0,G.jsx)(`input`,{ref:a,type:`file`,accept:`.3mf`,multiple:!0,className:`hidden`,onChange:g})]})}),(0,G.jsx)(`div`,{className:`px-4 pb-4`,children:(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:n(`uploadModal.extractionInfo`)})}),o.length>0&&(0,G.jsx)(`div`,{className:`px-4 pb-4 max-h-60 overflow-y-auto`,children:(0,G.jsx)(`div`,{className:`space-y-2`,children:o.map((e,t)=>(0,G.jsxs)(`div`,{className:`flex items-center gap-3 p-3 bg-bambu-dark rounded-lg`,children:[(0,G.jsx)(Qs,{className:`w-5 h-5 text-bambu-gray flex-shrink-0`}),(0,G.jsx)(`span`,{className:`flex-1 text-white text-sm truncate`,children:e.file.name}),(0,G.jsxs)(`span`,{className:`text-xs text-bambu-gray`,children:[(e.file.size/(1024*1024)).toFixed(1),` MB`]}),e.status===`pending`&&(0,G.jsx)(`button`,{onClick:()=>_(t),className:`text-bambu-gray hover:text-red-400 transition-colors`,disabled:x,children:(0,G.jsx)(Nu,{className:`w-4 h-4`})}),e.status===`uploading`&&(0,G.jsx)(Y,{className:`w-4 h-4 text-bambu-green animate-spin`}),e.status===`success`&&(0,G.jsx)(ls,{className:`w-4 h-4 text-bambu-green`}),e.status===`error`&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(`span`,{className:`text-xs text-red-400`,children:e.error}),(0,G.jsx)(ss,{className:`w-4 h-4 text-red-400`})]})]},`${e.file.name}-${t}`))})}),u&&(0,G.jsx)(`div`,{className:`px-4 pb-4`,children:(0,G.jsx)(`div`,{className:`p-3 bg-bambu-dark rounded-lg`,children:(0,G.jsxs)(`p`,{className:`text-sm text-white`,children:[(0,G.jsx)(`span`,{className:`text-bambu-green`,children:u.uploaded}),` `,n(`uploadModal.uploaded`),u.failed>0&&(0,G.jsxs)(G.Fragment,{children:[`, `,(0,G.jsx)(`span`,{className:`text-red-400`,children:u.failed}),` `,n(`uploadModal.failed`)]})]})})}),(0,G.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,className:`flex-1`,children:n(u?`common.close`:`common.cancel`)}),!u&&(0,G.jsx)(Q,{onClick:v,disabled:b===0||x,className:`flex-1`,children:x?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),n(`uploadModal.uploading`)]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(xu,{className:`w-4 h-4`}),n(`uploadModal.upload`),` `,b>0&&`(${b})`]})})]})]})})})}var nEe=365;function rEe({onClose:e,initialDays:t}){let{t:n}=et(),r=$a(),{showToast:i}=yd(),[a,o]=(0,y.useState)(t??nEe),[s,c]=(0,y.useState)(!1),[l,u]=(0,y.useState)(a);(0,y.useEffect)(()=>{let e=window.setTimeout(()=>u(a),300);return()=>window.clearTimeout(e)},[a]);let d=K({queryKey:[`archive-purge-preview`,l,s],queryFn:()=>Z.previewArchivePurge(l,s),enabled:l>=1}),f=q({mutationFn:()=>Z.executeArchivePurge(a,s),onSuccess:t=>{i(n(`archivePurge.toast.success`,{count:t.deleted}),`success`),r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`archive-stats`]}),e()},onError:e=>i(e.message||n(`archivePurge.toast.failed`),`error`)});(0,y.useEffect)(()=>{let t=t=>{t.key===`Escape`&&!f.isPending&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,f.isPending]);let p=d.data,m=p?.count??0,h=p?.total_bytes??0,g=m>0&&!f.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4`,children:(0,G.jsxs)(`div`,{className:`bg-white dark:bg-gray-900 rounded-lg shadow-xl max-w-lg w-full`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-center gap-2`,children:[(0,G.jsx)(mu,{className:`w-5 h-5`}),n(`archivePurge.title`)]}),(0,G.jsx)(`button`,{onClick:e,className:`text-gray-400 hover:text-gray-600 dark:hover:text-gray-200`,"aria-label":n(`common.close`),disabled:f.isPending,children:(0,G.jsx)(Nu,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.description`)}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`archive-purge-days`,className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:n(`archivePurge.ageLabel`)}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(`input`,{id:`archive-purge-days`,type:`number`,min:1,max:3650,value:a,onChange:e=>o(Math.max(1,Math.min(3650,parseInt(e.target.value||`0`,10)||0))),className:`w-24 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 text-sm px-2 py-1 text-gray-900 dark:text-gray-100`}),(0,G.jsx)(`span`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:n(`archivePurge.days`)})]})]}),(0,G.jsxs)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/30 p-3`,children:[(0,G.jsx)(`div`,{className:`text-xs font-semibold uppercase tracking-wide text-gray-600 dark:text-gray-300 mb-2`,children:n(`archivePurge.effectsTitle`)}),(0,G.jsxs)(`ul`,{className:`text-xs text-gray-700 dark:text-gray-300 space-y-1 list-disc pl-4`,children:[(0,G.jsx)(`li`,{children:n(`archivePurge.effect1`)}),(0,G.jsx)(`li`,{children:n(`archivePurge.effect2`)}),(0,G.jsx)(`li`,{children:n(`archivePurge.effect3`)}),(0,G.jsx)(`li`,{children:n(`archivePurge.effect4`)})]})]}),(0,G.jsx)(`div`,{className:`rounded border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-800/50 p-3`,children:d.isLoading||d.isFetching?(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-500 dark:text-gray-400`,children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),` `,n(`archivePurge.previewLoading`)]}):d.isError?(0,G.jsx)(`div`,{className:`text-sm text-red-600 dark:text-red-400`,children:d.error?.message??n(`archivePurge.previewFailed`)}):(0,G.jsxs)(`div`,{className:`text-sm text-gray-900 dark:text-gray-100`,children:[(0,G.jsx)(`div`,{className:`font-medium`,children:n(`archivePurge.previewSummary`,{count:m,size:_d(h)})}),p?.sample_filenames&&p.sample_filenames.length>0&&(0,G.jsxs)(`ul`,{className:`mt-2 text-xs text-gray-600 dark:text-gray-400 space-y-0.5 list-disc pl-4`,children:[p.sample_filenames.map(e=>(0,G.jsx)(`li`,{className:`truncate`,children:e},e)),m>p.sample_filenames.length&&(0,G.jsx)(`li`,{className:`list-none italic text-gray-500`,children:n(`archivePurge.andMore`,{count:m-p.sample_filenames.length})})]})]})}),(0,G.jsxs)(`label`,{className:`flex gap-2 items-start rounded border border-gray-200 dark:border-gray-700 px-3 py-2 cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:s,onChange:e=>c(e.target.checked),disabled:f.isPending,className:`mt-0.5 shrink-0`}),(0,G.jsxs)(`span`,{className:`text-xs text-gray-700 dark:text-gray-300`,children:[(0,G.jsx)(`span`,{className:`font-medium block mb-0.5`,children:n(`archivePurge.purgeStatsLabel`)}),(0,G.jsx)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:n(`archivePurge.purgeStatsHint`)})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-2 items-start text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 rounded px-3 py-2`,children:[(0,G.jsx)(_u,{className:`w-4 h-4 mt-0.5 shrink-0`}),(0,G.jsx)(`span`,{children:n(`archivePurge.warning`)})]})]}),(0,G.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t border-gray-200 dark:border-gray-700`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:e,disabled:f.isPending,children:n(`common.cancel`)}),(0,G.jsx)(Q,{variant:`danger`,disabled:!g,onClick:()=>f.mutate(),children:f.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin mr-1`}),n(`archivePurge.purging`)]}):n(`archivePurge.confirmCta`,{count:m})})]})]})})}function iEe(e){if(!e||e<=0)return`—`;let t=Math.floor(e/3600),n=Math.floor(e%3600/60);return t>0?`${t}h ${n}m`:`${n}m`}function aEe(e){if(!e)return`—`;let t=nf(e);return t?t.toLocaleString():`—`}function lJ({archiveId:e}){let{t}=et(),{data:n,isLoading:r}=K({queryKey:[`archive-runs`,e],queryFn:()=>Z.getArchiveRuns(e)});if(r)return(0,G.jsx)(`div`,{className:`flex justify-center py-4`,children:(0,G.jsx)(Y,{className:`w-5 h-5 text-bambu-gray animate-spin`})});let i=n?.items||[];return i.length===0?(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray italic py-2`,children:t(`archives.runLog.empty`)}):(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,G.jsx)(`thead`,{children:(0,G.jsxs)(`tr`,{className:`text-bambu-gray border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.date`)}),(0,G.jsx)(`th`,{className:`text-left py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.status`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.duration`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 pr-2 font-medium`,children:t(`archives.runLog.col.filament`)}),(0,G.jsx)(`th`,{className:`text-right py-1.5 font-medium`,children:t(`archives.runLog.col.cost`)})]})}),(0,G.jsx)(`tbody`,{children:i.map(e=>{let n=e.status===`completed`?`text-bambu-green`:e.status===`failed`?`text-red-400`:`text-bambu-gray`;return(0,G.jsxs)(`tr`,{className:`border-b border-bambu-dark-tertiary/40 last:border-0`,children:[(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-bambu-gray-light`,children:aEe(e.started_at||e.created_at)}),(0,G.jsxs)(`td`,{className:`py-1.5 pr-2 font-medium ${n}`,children:[t(`archives.runLog.status.${e.status}`,{defaultValue:e.status}),e.failure_reason&&(0,G.jsx)(`span`,{className:`block text-[10px] text-bambu-gray font-normal`,children:t(`editArchive.failureReasons.${e.failure_reason}`,{defaultValue:e.failure_reason})})]}),(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-right text-bambu-gray-light`,children:iEe(e.duration_seconds)}),(0,G.jsx)(`td`,{className:`py-1.5 pr-2 text-right text-bambu-gray-light`,children:e.filament_used_grams==null?`—`:`${e.filament_used_grams.toFixed(1)} g`}),(0,G.jsx)(`td`,{className:`py-1.5 text-right text-bambu-gray-light`,children:e.cost==null?`—`:e.cost.toFixed(2)})]},e.id)})})]})})}var uJ=[`adhesionFailure`,`spaghettiDetached`,`layerShift`,`cloggedNozzle`,`filamentRunout`,`warping`,`stringing`,`underExtrusion`,`powerFailure`,`userCancelled`,`other`],oEe=[`completed`,`failed`,`aborted`,`printing`];function dJ({archive:e,onClose:t,existingTags:n=[]}){let{t:r}=et();(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let i=$a(),[a,o]=(0,y.useState)(e.print_name||``),[s,c]=(0,y.useState)(e.printer_id),[l,u]=(0,y.useState)(e.project_id??null),[d,f]=(0,y.useState)(e.notes||``),[p,m]=(0,y.useState)(e.tags||``),[h,g]=(0,y.useState)(()=>{let t=e.failure_reason||``;return t?uJ.includes(t)?t:uJ.find(e=>r(`editArchive.failureReasons.${e}`)===t)||``:``}),[_,v]=(0,y.useState)(e.status),[b,x]=(0,y.useState)(e.quantity??1),[S,C]=(0,y.useState)(e.photos||[]),[w,T]=(0,y.useState)(e.external_url||``),[E,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(!1),A=(0,y.useRef)(null),j=(0,y.useRef)(null),M=(0,y.useRef)(null),{data:N}=K({queryKey:[`printers`],queryFn:Z.getPrinters}),{data:P}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects(),select:e=>[...e].sort((e,t)=>e.name.localeCompare(t.name))}),{data:F}=K({queryKey:[`tags`],queryFn:Z.getTags,enabled:n.length===0}),I=n.length>0?n:F?.map(e=>e.name)||[],L=p.split(`,`).map(e=>e.trim()).filter(Boolean),R=p.includes(`,`)?p.substring(p.lastIndexOf(`,`)+1).trim().toLowerCase():p.trim().toLowerCase(),z=I.filter(e=>!L.includes(e)&&(R===``||e.toLowerCase().includes(R))),B=e=>{let t;t=R&&!I.includes(R)?p.includes(`,`)?p.substring(0,p.lastIndexOf(`,`)).split(`,`).map(e=>e.trim()).filter(Boolean):[]:L,t.includes(e)||m([...t,e].join(`, `)),M.current!==null&&clearTimeout(M.current),A.current?.focus()},ee=e=>{m(L.filter(t=>t!==e).join(`, `))},te=q({mutationFn:t=>Z.updateArchive(e.id,t),onSuccess:()=>{i.invalidateQueries({queryKey:[`archives`]}),i.invalidateQueries({queryKey:[`projects`]}),t()}}),V=async t=>{let n=t.target.files?.[0];if(n){D(!0);try{C((await Z.uploadArchivePhoto(e.id,n)).photos),i.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to upload photo:`,e)}finally{D(!1),j.current&&(j.current.value=``)}}},ne=async t=>{try{C((await Z.deleteArchivePhoto(e.id,t)).photos||[]),i.invalidateQueries({queryKey:[`archives`]})}catch(e){console.error(`Failed to delete photo:`,e)}};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:t,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-md max-h-[90vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:r(`editArchive.title`)}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(Nu,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`form`,{onSubmit:t=>{t.preventDefault();let n={print_name:a||void 0,printer_id:s,project_id:l,notes:d||void 0,tags:p||void 0,quantity:b,external_url:w||null};_!==e.status&&(n.status=_),_===`failed`||_===`aborted`?n.failure_reason=h||void 0:(e.status===`failed`||e.status===`aborted`)&&(n.failure_reason=null),te.mutate(n)},className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`archives.runLog.title`)}),(0,G.jsx)(lJ,{archiveId:e.id})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.name`)}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:r(`editArchive.namePlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.printer`)}),(0,G.jsxs)(`select`,{value:s??``,onChange:e=>c(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:r(`editArchive.noPrinter`)}),N?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(nc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.project`)]}),(0,G.jsxs)(`select`,{value:l??``,onChange:e=>u(e.target.value?Number(e.target.value):null),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:r(`editArchive.noProject`)}),P?.map(e=>(0,G.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(bc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.itemsPrinted`)]}),(0,G.jsx)(`input`,{type:`number`,min:1,value:b,onChange:e=>x(Math.max(1,parseInt(e.target.value)||1)),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:`1`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`editArchive.itemsPrintedHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.notes`)}),(0,G.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),rows:3,className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none resize-none`,placeholder:r(`editArchive.notesPlaceholder`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(Lc,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.externalLink`)]}),(0,G.jsx)(`input`,{type:`url`,value:w,onChange:e=>T(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:`https://printables.com/model/...`}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mt-1`,children:r(`editArchive.externalLinkHelp`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.tags`)}),L.length>0&&(0,G.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mb-2`,children:L.map(e=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2 py-0.5 bg-bambu-dark-tertiary rounded text-sm text-white`,children:[(0,G.jsx)(ou,{className:`w-3 h-3`}),e,(0,G.jsx)(`button`,{type:`button`,onClick:()=>ee(e),className:`ml-0.5 text-bambu-gray hover:text-white`,children:(0,G.jsx)(Nu,{className:`w-3 h-3`})})]},e))}),(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(`input`,{ref:A,type:`text`,value:p,onChange:e=>m(e.target.value),onFocus:()=>{M.current!==null&&clearTimeout(M.current),k(!0)},onBlur:()=>{M.current=window.setTimeout(()=>k(!1),200)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,placeholder:L.length>0?r(`editArchive.addMoreTags`):r(`editArchive.tagsPlaceholder`)}),O&&z.length>0&&(0,G.jsxs)(`div`,{className:`absolute top-full left-0 right-0 mt-1 bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-lg z-10 max-h-40 overflow-y-auto`,children:[(0,G.jsxs)(`div`,{className:`p-2 text-xs text-bambu-gray border-b border-bambu-dark-tertiary`,children:[R?r(`editArchive.matchingTags`,{query:R}):r(`editArchive.existingTags`),` `,r(`editArchive.clickToAdd`)]}),(0,G.jsx)(`div`,{className:`p-2 flex flex-wrap gap-1.5`,children:z.map(e=>(0,G.jsx)(`button`,{type:`button`,onClick:()=>B(e),className:`px-2 py-0.5 bg-bambu-dark-tertiary hover:bg-bambu-green/20 rounded text-sm text-bambu-gray hover:text-white transition-colors`,children:e},e))})]})]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.status`)}),(0,G.jsx)(`select`,{value:_,onChange:e=>{v(e.target.value),e.target.value===`completed`&&g(``)},className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:oEe.map(e=>(0,G.jsx)(`option`,{value:e,children:r(`editArchive.statuses.${e}`)},e))})]}),(_===`failed`||_===`aborted`)&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`label`,{htmlFor:`failure-reason-select`,className:`block text-sm text-bambu-gray mb-1`,children:r(`editArchive.failureReason`)}),(0,G.jsxs)(`select`,{id:`failure-reason-select`,value:h,onChange:e=>g(e.target.value),className:`w-full px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white focus:border-bambu-green focus:outline-none`,children:[(0,G.jsx)(`option`,{value:``,children:r(`editArchive.selectReason`)}),uJ.map(e=>(0,G.jsx)(`option`,{value:e,children:r(`editArchive.failureReasons.${e}`)},e))]})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`label`,{className:`block text-sm text-bambu-gray mb-1`,children:[(0,G.jsx)(Yo,{className:`w-4 h-4 inline mr-1`}),r(`editArchive.photos`)]}),(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-2`,children:[S.map(t=>(0,G.jsxs)(`div`,{className:`relative group`,children:[(0,G.jsx)(`img`,{src:Z.getArchivePhotoUrl(e.id,t),alt:r(`editArchive.printResult`),className:`w-20 h-20 object-cover rounded-lg border border-bambu-dark-tertiary`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>ne(t),className:`absolute -top-1 -right-1 p-1 bg-red-500 rounded-full opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,G.jsx)(mu,{className:`w-3 h-3 text-white`})})]},t)),(0,G.jsxs)(`label`,{className:`w-20 h-20 flex items-center justify-center border-2 border-dashed border-bambu-dark-tertiary rounded-lg cursor-pointer hover:border-bambu-green transition-colors`,children:[(0,G.jsx)(`input`,{ref:j,type:`file`,accept:`image/jpeg,image/png,image/webp`,onChange:V,className:`hidden`,disabled:E}),E?(0,G.jsx)(Y,{className:`w-6 h-6 text-bambu-gray animate-spin`}):(0,G.jsx)(_l,{className:`w-6 h-6 text-bambu-gray`})]})]}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray`,children:r(`editArchive.photosHelp`)})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 pt-2`,children:[(0,G.jsx)(Q,{type:`button`,variant:`secondary`,onClick:t,className:`flex-1`,children:r(`common.cancel`)}),(0,G.jsxs)(Q,{type:`submit`,disabled:te.isPending,className:`flex-1`,children:[(0,G.jsx)(Dl,{className:`w-4 h-4`}),te.isPending?r(`common.saving`):r(`common.save`)]})]})]})]})})}function fJ({archiveId:e,archiveName:t,onClose:n}){let{t:r}=et();return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-2xl max-h-[85vh] flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,G.jsx)(wc,{className:`w-5 h-5 text-bambu-green flex-shrink-0`}),(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white truncate`,title:t||``,children:r(`archives.runLog.modalTitle`,{name:t||r(`archives.runLog.modalTitleFallback`)})})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,title:r(`common.close`),children:(0,G.jsx)(Nu,{className:`w-5 h-5`})})]}),(0,G.jsx)(`div`,{className:`p-6 overflow-y-auto flex-1`,children:(0,G.jsx)(lJ,{archiveId:e})})]})})}function sEe({items:e,searchPlaceholder:t,onClose:n,className:r,onMouseEnter:i,onMouseLeave:a}){let[o,s]=(0,y.useState)(``),c=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(t){let e=window.setTimeout(()=>c.current?.focus(),0);return()=>window.clearTimeout(e)}},[t]);let l=o.trim().toLowerCase(),u=t&&l?e.filter(e=>e.label.toLowerCase().includes(l)):e;return(0,G.jsxs)(`div`,{className:r,onMouseEnter:i,onMouseLeave:a,children:[t&&(0,G.jsx)(`div`,{className:`sticky top-0 z-[1] px-2 py-1.5 bg-bambu-dark-secondary border-b border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ml,{className:`absolute left-2 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{ref:c,type:`text`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{if(e.key===`Enter`){let e=u.find(e=>!e.disabled);e&&(e.onClick(),n())}},placeholder:t,className:`w-full pl-7 pr-2 py-1 text-sm bg-bambu-dark border border-bambu-dark-tertiary rounded text-white placeholder-bambu-gray focus:border-bambu-green focus:outline-none`})]})}),u.map((e,t)=>(0,G.jsxs)(`button`,{onClick:()=>{e.disabled||(e.onClick(),n())},disabled:e.disabled,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${e.disabled?`text-bambu-gray cursor-not-allowed`:e.danger?`text-red-400 hover:bg-red-400/10`:`text-white hover:bg-bambu-dark-tertiary`}`,children:[e.icon&&(0,G.jsx)(`span`,{className:`w-4 h-4 flex-shrink-0 flex items-center justify-center`,children:e.icon}),(0,G.jsx)(`span`,{className:`flex-1 truncate`,children:e.label})]},t)),t&&u.length===0&&(0,G.jsx)(`div`,{className:`px-3 py-2 text-sm text-bambu-gray text-center italic`,children:`—`})]})}function pJ({x:e,y:t,items:n,onClose:r}){let i=(0,y.useRef)(null),[a,o]=(0,y.useState)(null),s=(0,y.useRef)(null),[c,l]=(0,y.useState)({x:e,y:t,visible:!1}),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)({});(0,y.useEffect)(()=>{let e=e=>{i.current&&!i.current.contains(e.target)&&r()},t=e=>{e.key===`Escape`&&r()},n=e=>{i.current&&i.current.contains(e.target)||r()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),document.addEventListener(`scroll`,n,!0),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t),document.removeEventListener(`scroll`,n,!0),s.current&&clearTimeout(s.current)}},[r]),(0,y.useLayoutEffect)(()=>{if(i.current){i.current.style.visibility=`hidden`,i.current.style.display=`block`;let n=i.current.getBoundingClientRect(),r=window.innerWidth,a=window.innerHeight,o=e,s=t;e+n.width>r-8&&(o=Math.max(8,r-n.width-8)),o<8&&(o=8),t+n.height>a-8&&(s=Math.max(8,a-n.height-8)),s<8&&(s=8),d(r-o-n.width<180&&o>180),l({x:o,y:s,visible:!0})}},[e,t]);let m=(e,t)=>{s.current&&=(clearTimeout(s.current),null);let n=t.getBoundingClientRect(),r=window.innerHeight-n.top-8<300&&n.top>300;p(t=>({...t,[e]:r?`bottom`:`top`})),o(e)},h=()=>{s.current=window.setTimeout(()=>{o(null)},150)};return(0,G.jsx)(`div`,{ref:i,className:`fixed z-50 min-w-[180px] max-w-[280px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1`,style:{left:c.x,top:c.y,visibility:c.visible?`visible`:`hidden`},children:n.map((e,t)=>{if(e.divider)return(0,G.jsx)(`div`,{className:`my-1 border-t border-bambu-dark-tertiary`},t);let n=e.submenu&&e.submenu.length>0;return(0,G.jsxs)(`div`,{className:`relative`,onMouseEnter:e=>n&&m(t,e.currentTarget),onMouseLeave:()=>n&&h(),children:[(0,G.jsxs)(`button`,{onMouseEnter:e=>n&&m(t,e.currentTarget.parentElement),onClick:()=>{n?o(a===t?null:t):e.disabled||(e.onClick(),r())},disabled:e.disabled,title:e.title,className:`w-full flex items-center gap-2 px-3 py-2 text-sm text-left transition-colors ${e.disabled?`text-bambu-gray cursor-not-allowed`:e.danger?`text-red-400 hover:bg-red-400/10`:`text-white hover:bg-bambu-dark-tertiary`} ${n&&a===t?`bg-bambu-dark-tertiary`:``}`,children:[e.icon&&(0,G.jsx)(`span`,{className:`w-4 h-4 flex-shrink-0 flex items-center justify-center`,children:e.icon}),(0,G.jsx)(`span`,{className:`flex-1`,children:e.label}),n&&(0,G.jsx)(ts,{className:`w-4 h-4 text-bambu-gray`})]}),n&&a===t&&(0,G.jsx)(sEe,{items:e.submenu,searchPlaceholder:e.submenuSearchPlaceholder,onClose:r,className:`absolute min-w-[200px] bg-bambu-dark-secondary border border-bambu-dark-tertiary rounded-lg shadow-xl py-1 overflow-hidden max-h-[300px] overflow-y-auto z-[60] ${u?`right-full mr-1`:`left-full ml-1`} ${f[t]===`bottom`?`bottom-0`:`top-0`}`,onMouseEnter:()=>{s.current&&=(clearTimeout(s.current),null)},onMouseLeave:()=>h()})]},t)})})}function cEe({selectedIds:e,existingTags:t,onClose:n}){let r=$a(),{showToast:i}=yd(),[a,o]=(0,y.useState)(``),[s,c]=(0,y.useState)(new Set),[l,u]=(0,y.useState)(`add`);(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]);let d=q({mutationFn:async()=>{let t=Array.from(s),n=0;for(let r of e)try{let e=await Z.getArchive(r),i=e.tags?e.tags.split(`,`).map(e=>e.trim()).filter(Boolean):[],a;a=l===`add`?[...new Set([...i,...t])]:i.filter(e=>!s.has(e)),await Z.updateArchive(r,{tags:a.join(`, `)}),n++}catch(e){throw console.error(`Failed to update archive ${r}:`,e),Error(`Failed on archive ${r}: ${e instanceof Error?e.message:`Unknown error`}`)}return{count:n,mode:l,tags:t}},onSuccess:({count:e,mode:t,tags:a})=>{r.invalidateQueries({queryKey:[`archives`]}),i(`${t===`add`?`Added`:`Removed`} ${a.length} tag${a.length===1?``:`s`} ${t===`add`?`to`:`from`} ${e} archive${e===1?``:`s`}`),n()},onError:e=>{i(e.message||`Failed to update tags`,`error`)}}),f=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},p=()=>{a.trim()&&!s.has(a.trim())&&(c(e=>new Set([...e,a.trim()])),o(``))};return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(dd,{className:`w-full max-w-md`,children:(0,G.jsxs)(pd,{className:`p-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(ou,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:l===`add`?`Add Tags`:`Remove Tags`})]}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(Nu,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[l===`add`?`Add`:`Remove`,` tags for `,e.length,` selected archive`,e.length===1?``:`s`]}),(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(Q,{size:`sm`,variant:l===`add`?`primary`:`secondary`,onClick:()=>u(`add`),children:`Add Tags`}),(0,G.jsx)(Q,{size:`sm`,variant:l===`remove`?`primary`:`secondary`,onClick:()=>u(`remove`),children:`Remove Tags`})]}),l===`add`&&(0,G.jsxs)(`div`,{className:`flex gap-2`,children:[(0,G.jsx)(`input`,{type:`text`,placeholder:`Enter new tag...`,className:`flex-1 px-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white text-sm focus:border-bambu-green focus:outline-none`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),p())}}),(0,G.jsx)(Q,{size:`sm`,variant:`secondary`,onClick:p,disabled:!a.trim(),children:(0,G.jsx)(_l,{className:`w-4 h-4`})})]}),t.length>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:`Existing tags:`}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t.map(e=>(0,G.jsx)(`button`,{onClick:()=>f(e),className:`px-2 py-1 rounded text-sm transition-colors ${s.has(e)?`bg-bambu-green text-white`:`bg-bambu-dark-tertiary text-bambu-gray-light hover:bg-bambu-dark`}`,children:e},e))})]}),s.size>0&&(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`p`,{className:`text-xs text-bambu-gray mb-2`,children:[`Tags to `,l===`add`?`add`:`remove`,`:`]}),(0,G.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Array.from(s).map(e=>(0,G.jsxs)(`span`,{className:`px-2 py-1 rounded text-sm flex items-center gap-1 ${l===`add`?`bg-green-500/20 text-green-400`:`bg-red-500/20 text-red-400`}`,children:[e,(0,G.jsx)(`button`,{onClick:()=>f(e),className:`hover:opacity-70`,children:(0,G.jsx)(Nu,{className:`w-3 h-3`})})]},e))})]})]}),(0,G.jsxs)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary`,children:[(0,G.jsx)(Q,{variant:`secondary`,onClick:n,className:`flex-1`,children:`Cancel`}),(0,G.jsx)(Q,{onClick:()=>d.mutate(),disabled:s.size===0||d.isPending,className:`flex-1`,children:d.isPending?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin`}),`Processing...`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(ou,{className:`w-4 h-4`}),l===`add`?`Add Tags`:`Remove Tags`]})})]})]})})})}function lEe({selectedIds:e,onClose:t}){let{t:n}=et(),r=$a(),{showToast:i}=yd(),[a,o]=(0,y.useState)(``),{data:s,isLoading:c}=K({queryKey:[`projects`],queryFn:()=>Z.getProjects()}),l=(0,y.useMemo)(()=>s?[...s].sort((e,t)=>e.name.localeCompare(t.name)):void 0,[s]),u=a.trim().toLowerCase(),d=u?l?.filter(e=>e.name.toLowerCase().includes(u)):l,f=(l?.length??0)>5;(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let p=()=>{r.invalidateQueries({queryKey:[`archives`]}),r.invalidateQueries({queryKey:[`projects`]}),r.invalidateQueries({queryKey:[`project`]}),r.invalidateQueries({queryKey:[`project-archives`]})},m=q({mutationFn:async t=>(await Z.addArchivesToProject(t,e),t),onSuccess:n=>{let r=s?.find(e=>e.id===n);p(),i(`Added ${e.length} archive${e.length===1?``:`s`} to "${r?.name}"`),t()},onError:()=>{i(`Failed to assign project`,`error`)}}),h=q({mutationFn:async()=>{for(let t of e)await Z.updateArchive(t,{project_id:null});return e.length},onSuccess:e=>{p(),i(`Removed ${e} archive${e===1?``:`s`} from project`),t()},onError:()=>{i(`Failed to remove from project`,`error`)}}),g=m.isPending||h.isPending;return(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4`,children:(0,G.jsx)(dd,{className:`w-full max-w-md max-h-[80vh] flex flex-col`,children:(0,G.jsxs)(pd,{className:`p-0 flex flex-col min-h-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-bambu-dark-tertiary shrink-0`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(nc,{className:`w-5 h-5 text-bambu-green`}),(0,G.jsx)(`h2`,{className:`text-xl font-semibold text-white`,children:`Assign to Project`})]}),(0,G.jsx)(`button`,{onClick:t,className:`text-bambu-gray hover:text-white transition-colors`,disabled:g,children:(0,G.jsx)(Nu,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-4 space-y-3 overflow-y-auto min-h-0`,children:[(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Assign `,e.length,` selected archive`,e.length===1?``:`s`,` to a project`]}),c?(0,G.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,G.jsx)(Y,{className:`w-6 h-6 animate-spin text-bambu-gray`})}):(0,G.jsxs)(`div`,{className:`space-y-2`,children:[(0,G.jsxs)(`button`,{onClick:()=>h.mutate(),disabled:g,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full bg-red-500/20 flex items-center justify-center shrink-0`,children:(0,G.jsx)(ms,{className:`w-4 h-4 text-red-400`})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium`,children:`Remove from project`}),(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray truncate`,children:`Clear project assignment`})]}),h.isPending&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]}),l&&l.length>0&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2 py-2`,children:[(0,G.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`}),(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`or assign to`}),(0,G.jsx)(`div`,{className:`flex-1 h-px bg-bambu-dark-tertiary`})]}),f&&(0,G.jsxs)(`div`,{className:`relative`,children:[(0,G.jsx)(Ml,{className:`absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-bambu-gray pointer-events-none`}),(0,G.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),placeholder:n(`archives.menu.searchProjects`),className:`w-full pl-9 pr-3 py-2 bg-bambu-dark border border-bambu-dark-tertiary rounded-lg text-white placeholder-bambu-gray text-sm focus:border-bambu-green focus:outline-none`})]}),d?.map(e=>(0,G.jsxs)(`button`,{onClick:()=>m.mutate(e.id),disabled:g,className:`w-full flex items-center gap-3 p-3 rounded-lg bg-bambu-dark hover:bg-bambu-dark-tertiary border border-bambu-dark-tertiary transition-colors text-left disabled:opacity-50`,children:[(0,G.jsx)(`div`,{className:`w-8 h-8 rounded-full flex items-center justify-center shrink-0`,style:{backgroundColor:e.color?`${e.color}20`:`rgb(var(--bambu-green) / 0.2)`},children:(0,G.jsx)(nc,{className:`w-4 h-4`,style:{color:e.color||`rgb(var(--bambu-green))`}})}),(0,G.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,G.jsx)(`p`,{className:`text-white font-medium truncate`,children:e.name}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray truncate`,children:[e.archive_count,` archive`,e.archive_count===1?``:`s`,e.status&&` • ${e.status}`]})]}),m.isPending&&m.variables===e.id&&(0,G.jsx)(Y,{className:`w-4 h-4 animate-spin text-bambu-gray shrink-0`})]},e.id)),(!l||l.length===0)&&(0,G.jsx)(`p`,{className:`text-center text-bambu-gray py-4`,children:`No projects yet. Create one from the Projects page.`}),l&&l.length>0&&d?.length===0&&(0,G.jsx)(`p`,{className:`text-center text-bambu-gray text-sm py-4`,children:`—`})]})]}),(0,G.jsx)(`div`,{className:`flex gap-3 p-4 border-t border-bambu-dark-tertiary shrink-0`,children:(0,G.jsx)(Q,{variant:`secondary`,onClick:t,className:`flex-1`,disabled:g,children:`Cancel`})})]})})})}function uEe(e,t){return new Date(e,t+1,0).getDate()}function dEe(e,t){return new Date(e,t,1).getDay()}var fEe=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],pEe=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];function mEe({archives:e,onArchiveClick:t,highlightedArchiveId:n}){let r=new Date,[i,a]=(0,y.useState)(r.getMonth()),[o,s]=(0,y.useState)(r.getFullYear()),[c,l]=(0,y.useState)(null),[u,d]=(0,y.useState)(null),f=(0,y.useMemo)(()=>{let t=new Map;return e.forEach(e=>{let n=nf(e.completed_at||e.created_at)||new Date,r=`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,`0`)}-${String(n.getDate()).padStart(2,`0`)}`,i=t.get(r)||[];i.push(e),t.set(r,i)}),t},[e]),p=uEe(o,i),m=dEe(o,i),h=()=>{i===0?(a(11),s(o-1)):a(i-1)},g=()=>{i===11?(a(0),s(o+1)):a(i+1)},_=()=>{a(r.getMonth()),s(r.getFullYear())},v=[];for(let e=0;e{e!==c&&d(null),l(e)};return(0,G.jsxs)(`div`,{className:`flex flex-col lg:flex-row gap-6`,children:[(0,G.jsxs)(`div`,{className:`flex-1`,children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between mb-4`,children:[(0,G.jsx)(`button`,{onClick:h,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(ns,{className:`w-5 h-5 text-bambu-gray`})}),(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsxs)(`h2`,{className:`text-lg font-semibold text-white`,children:[fEe[i],` `,o]}),(0,G.jsx)(`button`,{onClick:_,className:`px-2 py-1 text-xs bg-bambu-dark-tertiary hover:bg-bambu-green/20 text-bambu-gray hover:text-white rounded transition-colors`,children:`Today`})]}),(0,G.jsx)(`button`,{onClick:g,className:`p-2 hover:bg-bambu-dark-tertiary rounded-lg transition-colors`,children:(0,G.jsx)(ts,{className:`w-5 h-5 text-bambu-gray`})})]}),(0,G.jsx)(`div`,{className:`grid grid-cols-7 gap-1 mb-1`,children:pEe.map(e=>(0,G.jsx)(`div`,{className:`text-center text-xs text-bambu-gray py-2`,children:e},e))}),(0,G.jsx)(`div`,{className:`grid grid-cols-7 gap-1`,children:v.map((e,t)=>{if(e===null)return(0,G.jsx)(`div`,{className:`aspect-square`},`empty-${t}`);let n=`${o}-${String(i+1).padStart(2,`0`)}-${String(e).padStart(2,`0`)}`,a=f.get(n)||[],s=a.length>0,l=e===r.getDate()&&i===r.getMonth()&&o===r.getFullYear(),u=n===c,d=a.filter(e=>e.status===`completed`).length,p=a.filter(e=>e.status===`failed`).length;return(0,G.jsxs)(`button`,{onClick:()=>x(u?null:n),className:`aspect-square rounded-lg p-1 flex flex-col items-center justify-center transition-colors relative ${u?`bg-bambu-green text-white`:l?`bg-bambu-green/20 text-white ring-2 ring-bambu-green`:s?`bg-bambu-dark-tertiary hover:bg-bambu-dark-tertiary/70 text-white`:`hover:bg-bambu-dark-tertiary/50 text-bambu-gray`}`,children:[(0,G.jsx)(`span`,{className:`text-sm font-medium ${l&&!u?`text-bambu-green`:``}`,children:e}),s&&(0,G.jsxs)(`div`,{className:`absolute bottom-1 left-1/2 -translate-x-1/2 flex items-center gap-1`,children:[(0,G.jsx)(`div`,{className:`w-2 h-2 rounded-full ${p>0&&d===0?`bg-red-400`:p>0?`bg-yellow-400`:`bg-green-400`}`}),(0,G.jsx)(`span`,{className:`text-xs font-medium`,children:a.length})]})]},e)})}),(0,G.jsx)(`div`,{className:`mt-4 pt-4 border-t border-bambu-dark-tertiary`,children:(0,G.jsxs)(`div`,{className:`grid grid-cols-3 gap-4 text-center`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-2xl font-bold text-white`,children:e.filter(e=>{let t=nf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o}).length}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Prints this month`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-2xl font-bold text-green-400`,children:e.filter(e=>{let t=nf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o&&e.status===`completed`}).length}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Successful`})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-2xl font-bold text-red-400`,children:e.filter(e=>{let t=nf(e.completed_at||e.created_at)||new Date;return t.getMonth()===i&&t.getFullYear()===o&&e.status===`failed`}).length}),(0,G.jsx)(`div`,{className:`text-xs text-bambu-gray`,children:`Failed`})]})]})})]}),(0,G.jsx)(`div`,{className:`lg:w-80 bg-bambu-dark rounded-xl p-4`,children:c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`h3`,{className:`text-sm font-medium text-bambu-gray mb-3`,children:new Date(c+`T12:00:00`).toLocaleDateString(`en-US`,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`})}),b.length>0?(0,G.jsx)(`div`,{className:`calendar-scroll space-y-2 max-h-96 overflow-y-auto`,children:b.map(e=>{let r=e.id===u||e.id===n;return(0,G.jsxs)(`button`,{onClick:()=>{d(e.id),t?.(e)},className:`w-full flex items-center gap-3 p-2 rounded-lg transition-colors text-left ${r?``:`hover:bg-bambu-dark-tertiary`}`,style:r?{outline:`4px solid #facc15`,outlineOffset:`2px`}:void 0,children:[e.thumbnail_path?(0,G.jsx)(`img`,{src:Z.getArchiveThumbnail(e.id),alt:``,className:`w-12 h-12 rounded object-cover`}):(0,G.jsx)(`div`,{className:`w-12 h-12 rounded bg-bambu-dark-tertiary flex items-center justify-center`,children:(0,G.jsx)(`span`,{className:`text-xs text-bambu-gray`,children:`3MF`})}),(0,G.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,G.jsx)(`p`,{className:`text-sm text-white truncate`,children:e.print_name||e.filename}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,G.jsx)(`span`,{className:e.status===`failed`?`text-red-400`:`text-green-400`,children:e.status===`failed`?`Failed`:`Completed`}),e.filament_color&&(0,G.jsx)(`div`,{className:`flex gap-0.5`,children:e.filament_color.split(`,`).map((e,t)=>(0,G.jsx)(`div`,{className:`w-3 h-3 rounded-full border border-black/20`,style:{backgroundColor:e}},t))})]})]})]},e.id)})}):(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`No prints on this day`})]}):(0,G.jsx)(`div`,{className:`text-center py-8`,children:(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray`,children:`Select a day to see prints`})})})]})}function mJ({archiveId:e,archiveName:t,onClose:n}){let r=Z.getArchiveQRCodeUrl(e,300);return(0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,G.jsx)(`div`,{className:`fixed inset-0 bg-black/70 flex items-center justify-center z-50 p-4`,onClick:n,children:(0,G.jsxs)(`div`,{className:`bg-bambu-dark-secondary rounded-xl border border-bambu-dark-tertiary w-full max-w-sm`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-bambu-dark-tertiary`,children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:`QR Code`}),(0,G.jsx)(`button`,{onClick:n,className:`text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(Nu,{className:`w-5 h-5`})})]}),(0,G.jsxs)(`div`,{className:`p-6 flex flex-col items-center`,children:[(0,G.jsx)(`p`,{className:`text-sm text-bambu-gray mb-4 text-center truncate max-w-full`,children:t}),(0,G.jsx)(`div`,{className:`bg-white p-4 rounded-lg mb-4`,children:(0,G.jsx)(`img`,{src:r,alt:`QR Code`,className:`w-64 h-64`})}),(0,G.jsx)(`p`,{className:`text-xs text-bambu-gray mb-4 text-center`,children:`Scan to open this archive`}),(0,G.jsxs)(Q,{onClick:()=>{let e=document.createElement(`a`);e.href=r,e.download=`${t}_qrcode.png`,e.click()},className:`w-full`,children:[(0,G.jsx)(Is,{className:`w-4 h-4`}),`Download QR Code`]})]})]})})}function hJ({archiveId:e,archiveName:t,photos:n,onClose:r,onDelete:i}){let[a,o]=(0,y.useState)(0),[s,c]=(0,y.useState)(!1);if((0,y.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r(),e.key===`ArrowLeft`&&o(e=>Math.max(0,e-1)),e.key===`ArrowRight`&&o(e=>Math.min(n.length-1,e+1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,n.length]),(0,y.useEffect)(()=>{a>=n.length&&o(Math.max(0,n.length-1))},[n.length,a]),n.length===0)return r(),null;let l=n[a],u=Z.getArchivePhotoUrl(e,l);return(0,G.jsxs)(`div`,{className:`fixed inset-0 bg-black/90 flex items-center justify-center z-50`,onClick:r,children:[(0,G.jsxs)(`div`,{className:`relative w-full h-full flex flex-col`,onClick:e=>e.stopPropagation(),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 bg-black/50`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`text-lg font-semibold text-white`,children:t}),(0,G.jsxs)(`p`,{className:`text-sm text-bambu-gray`,children:[`Photo `,a+1,` of `,n.length]})]}),(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsxs)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{let e=document.createElement(`a`);e.href=u,e.download=`${t}_photo_${a+1}.jpg`,e.click()},children:[(0,G.jsx)(Is,{className:`w-4 h-4`}),`Download`]}),i&&(0,G.jsx)(Q,{variant:`secondary`,size:`sm`,onClick:()=>{i&&c(!0)},className:`text-red-400 hover:text-red-300`,children:(0,G.jsx)(mu,{className:`w-4 h-4`})}),(0,G.jsx)(`button`,{onClick:r,className:`p-2 text-bambu-gray hover:text-white transition-colors`,children:(0,G.jsx)(Nu,{className:`w-6 h-6`})})]})]}),(0,G.jsxs)(`div`,{className:`flex-1 min-h-0 flex items-center justify-center p-4 relative overflow-hidden`,children:[a>0&&(0,G.jsx)(`button`,{onClick:()=>o(e=>e-1),className:`absolute left-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,G.jsx)(ns,{className:`w-8 h-8 text-white`})}),(0,G.jsx)(`img`,{src:u,alt:`Photo ${a+1}`,className:`max-w-full max-h-full object-contain rounded-lg`,style:{maxHeight:`calc(100vh - 200px)`}}),ao(e=>e+1),className:`absolute right-4 z-10 p-3 bg-black/50 hover:bg-black/70 rounded-full transition-colors`,children:(0,G.jsx)(ts,{className:`w-8 h-8 text-white`})})]}),n.length>1&&(0,G.jsx)(`div`,{className:`flex justify-center gap-2 p-4 bg-black/50`,children:n.map((t,n)=>(0,G.jsx)(`button`,{onClick:()=>o(n),className:`w-16 h-16 rounded-lg overflow-hidden border-2 transition-colors ${n===a?`border-bambu-green`:`border-transparent hover:border-bambu-gray`}`,children:(0,G.jsx)(`img`,{src:Z.getArchivePhotoUrl(e,t),alt:`Thumbnail ${n+1}`,className:`w-full h-full object-cover`})},t))})]}),s&&(0,G.jsx)(wd,{title:`Delete Photo`,message:`Delete this photo? This cannot be undone.`,confirmText:`Delete`,variant:`danger`,onConfirm:()=>{i?.(l),c(!1)},onCancel:()=>c(!1)})]})}function gJ(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n`u`?null:BJ(BigInt.prototype.toString),FJ=typeof Symbol>`u`?null:BJ(Symbol.prototype.toString),IJ=BJ(Object.prototype.hasOwnProperty),LJ=BJ(Object.prototype.toString),RJ=BJ(RegExp.prototype.test),zJ=OEe(TypeError);function BJ(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return CJ(e,t,n)}}function OEe(e){return function(){return wJ(e,[...arguments])}}function VJ(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:kJ;if(vJ&&vJ(e,null),!OJ(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(bEe(t)||(t[r]=e),i=e)}e[i]=!0}return e}function kEe(e){for(let t=0;t/g),IEe=bJ(/\${[\w\W]*/g),LEe=bJ(/^data-[\-\w.\u00B7-\uFFFF]+$/),REe=bJ(/^aria-[\-\w]+$/),$J=bJ(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),zEe=bJ(/^(?:\w+script|data):/i),BEe=bJ(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),VEe=bJ(/^html$/i),HEe=bJ(/^[a-z][.\w]*(-[.\w]+)+$/i),eY=bJ(/<[/\w!]/g),UEe=bJ(/<[/\w]/g),WEe=bJ(/<\/no(script|embed|frames)/i),GEe=bJ(/\/>/i),tY={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},KEe=function(){return typeof window>`u`?null:window},qEe=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},nY=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},rY=function(e,t,n,r){return IJ(e,t)&&OJ(e[t])?VJ(r.base?HJ(r.base):{},e[t],r.transform):n};function iY(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:KEe(),t=e=>iY(e);if(t.version=`3.4.10`,t.removed=[],!e||!e.document||e.document.nodeType!==tY.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=UJ(d,`cloneNode`),p=UJ(d,`remove`),m=UJ(d,`nextSibling`),h=UJ(d,`childNodes`),g=UJ(d,`parentNode`),_=UJ(d,`shadowRoot`),v=UJ(d,`attributes`),y=o&&o.prototype?UJ(o.prototype,`nodeType`):null,b=o&&o.prototype?UJ(o.prototype,`nodeName`):null;if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let x,S=``,C,w=!1,T=0,E=function(){if(T>0)throw zJ(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},D=function(e){E(),T++;try{return x.createHTML(e)}finally{T--}},O=function(e){E(),T++;try{return x.createScriptURL(e)}finally{T--}},k=function(){return w||=(C=qEe(u,i),!0),C},A=n,j=A.implementation,M=A.createNodeIterator,N=A.createDocumentFragment,P=A.getElementsByTagName,F=r.importNode,I=nY();t.isSupported=typeof _J==`function`&&typeof g==`function`&&j&&j.createHTMLDocument!==void 0;let L=PEe,R=FEe,z=IEe,B=LEe,ee=REe,te=zEe,V=BEe,ne=HEe,re=$J,ie=null,H=VJ({},[...WJ,...GJ,...KJ,...qJ,...JJ]),ae=null,oe=VJ({},[...YJ,...XJ,...ZJ,...QJ]),U=Object.seal(xJ(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),se=null,ce=null,le=Object.seal(xJ(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),ue=!0,de=!0,fe=!1,pe=!0,me=!1,he=!0,ge=!1,_e=!1,ve=!1,ye=!1,be=!1,xe=!1,Se=!0,Ce=!1,we=`user-content-`,Te=!0,Ee=!1,De={},Oe=null,ke=VJ({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),Ae=null,je=VJ({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Me=null,Ne=VJ({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Pe=`http://www.w3.org/1998/Math/MathML`,Fe=`http://www.w3.org/2000/svg`,Ie=`http://www.w3.org/1999/xhtml`,Le=Ie,Re=!1,ze=null,Be=VJ({},[Pe,Fe,Ie],AJ),Ve=yJ([`mi`,`mo`,`mn`,`ms`,`mtext`]),He=VJ({},Ve),Ue=yJ([`annotation-xml`]),We=VJ({},Ue),Ge=VJ({},[`title`,`style`,`font`,`a`,`script`]),Ke=null,qe=[`application/xhtml+xml`,`text/html`],Je=null,Ye=null,Xe=n.createElement(`form`),Ze=function(e){return e instanceof RegExp||e instanceof Function},Qe=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Ye&&Ye===e)return;(!e||typeof e!=`object`)&&(e={}),e=HJ(e),Ke=qe.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,Je=Ke===`application/xhtml+xml`?AJ:kJ,ie=rY(e,`ALLOWED_TAGS`,H,{transform:Je}),ae=rY(e,`ALLOWED_ATTR`,oe,{transform:Je}),ze=rY(e,`ALLOWED_NAMESPACES`,Be,{transform:AJ}),Me=rY(e,`ADD_URI_SAFE_ATTR`,Ne,{transform:Je,base:Ne}),Ae=rY(e,`ADD_DATA_URI_TAGS`,je,{transform:Je,base:je}),Oe=rY(e,`FORBID_CONTENTS`,ke,{transform:Je}),se=rY(e,`FORBID_TAGS`,HJ({}),{transform:Je}),ce=rY(e,`FORBID_ATTR`,HJ({}),{transform:Je}),De=IJ(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?HJ(e.USE_PROFILES):e.USE_PROFILES:!1,ue=e.ALLOW_ARIA_ATTR!==!1,de=e.ALLOW_DATA_ATTR!==!1,fe=e.ALLOW_UNKNOWN_PROTOCOLS||!1,pe=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,me=e.SAFE_FOR_TEMPLATES||!1,he=e.SAFE_FOR_XML!==!1,ge=e.WHOLE_DOCUMENT||!1,ye=e.RETURN_DOM||!1,be=e.RETURN_DOM_FRAGMENT||!1,xe=e.RETURN_TRUSTED_TYPE||!1,ve=e.FORCE_BODY||!1,Se=e.SANITIZE_DOM!==!1,Ce=e.SANITIZE_NAMED_PROPS||!1,Te=e.KEEP_CONTENT!==!1,Ee=e.IN_PLACE||!1,re=jEe(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:$J,Le=typeof e.NAMESPACE==`string`?e.NAMESPACE:Ie,He=IJ(e,`MATHML_TEXT_INTEGRATION_POINTS`)&&e.MATHML_TEXT_INTEGRATION_POINTS&&typeof e.MATHML_TEXT_INTEGRATION_POINTS==`object`?HJ(e.MATHML_TEXT_INTEGRATION_POINTS):VJ({},Ve),We=IJ(e,`HTML_INTEGRATION_POINTS`)&&e.HTML_INTEGRATION_POINTS&&typeof e.HTML_INTEGRATION_POINTS==`object`?HJ(e.HTML_INTEGRATION_POINTS):VJ({},Ue);let t=IJ(e,`CUSTOM_ELEMENT_HANDLING`)&&e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING==`object`?HJ(e.CUSTOM_ELEMENT_HANDLING):xJ(null);if(U=xJ(null),IJ(t,`tagNameCheck`)&&Ze(t.tagNameCheck)&&(U.tagNameCheck=t.tagNameCheck),IJ(t,`attributeNameCheck`)&&Ze(t.attributeNameCheck)&&(U.attributeNameCheck=t.attributeNameCheck),IJ(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(U.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),bJ(U),me&&(de=!1),be&&(ye=!0),De&&(ie=VJ({},JJ),ae=xJ(null),De.html===!0&&(VJ(ie,WJ),VJ(ae,YJ)),De.svg===!0&&(VJ(ie,GJ),VJ(ae,XJ),VJ(ae,QJ)),De.svgFilters===!0&&(VJ(ie,KJ),VJ(ae,XJ),VJ(ae,QJ)),De.mathMl===!0&&(VJ(ie,qJ),VJ(ae,ZJ),VJ(ae,QJ))),le.tagCheck=null,le.attributeCheck=null,IJ(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?le.tagCheck=e.ADD_TAGS:OJ(e.ADD_TAGS)&&(ie===H&&(ie=HJ(ie)),VJ(ie,e.ADD_TAGS,Je))),IJ(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?le.attributeCheck=e.ADD_ATTR:OJ(e.ADD_ATTR)&&(ae===oe&&(ae=HJ(ae)),VJ(ae,e.ADD_ATTR,Je))),IJ(e,`ADD_URI_SAFE_ATTR`)&&OJ(e.ADD_URI_SAFE_ATTR)&&VJ(Me,e.ADD_URI_SAFE_ATTR,Je),IJ(e,`FORBID_CONTENTS`)&&OJ(e.FORBID_CONTENTS)&&(Oe===ke&&(Oe=HJ(Oe)),VJ(Oe,e.FORBID_CONTENTS,Je)),IJ(e,`ADD_FORBID_CONTENTS`)&&OJ(e.ADD_FORBID_CONTENTS)&&(Oe===ke&&(Oe=HJ(Oe)),VJ(Oe,e.ADD_FORBID_CONTENTS,Je)),Te&&(ie[`#text`]=!0),ge&&VJ(ie,[`html`,`head`,`body`]),ie.table&&(VJ(ie,[`tbody`]),delete se.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw zJ(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw zJ(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=x;x=e.TRUSTED_TYPES_POLICY;try{S=D(``)}catch(e){throw x=t,e}}else e.TRUSTED_TYPES_POLICY===null?(x=void 0,S=``):(x===void 0&&(x=k()),x&&typeof S==`string`&&(S=D(``)));(I.uponSanitizeElement.length>0||I.uponSanitizeAttribute.length>0)&&ie===H&&(ie=HJ(ie)),I.uponSanitizeAttribute.length>0&&ae===oe&&(ae=HJ(ae)),yJ&&yJ(e),Ye=e},$e=VJ({},[...GJ,...KJ,...MEe]),et=VJ({},[...qJ,...NEe]),tt=function(e,t,n){return t.namespaceURI===Ie?e===`svg`:t.namespaceURI===Pe?e===`svg`&&(n===`annotation-xml`||He[n]):!!$e[e]},nt=function(e,t,n){return t.namespaceURI===Ie?e===`math`:t.namespaceURI===Fe?e===`math`&&We[n]:!!et[e]},rt=function(e,t,n){return t.namespaceURI===Fe&&!We[n]||t.namespaceURI===Pe&&!He[n]?!1:!et[e]&&(Ge[e]||!$e[e])},it=function(e){let t=g(e);(!t||!t.tagName)&&(t={namespaceURI:Le,tagName:`template`});let n=kJ(e.tagName),r=kJ(t.tagName);return ze[e.namespaceURI]?e.namespaceURI===Fe?tt(n,t,r):e.namespaceURI===Pe?nt(n,t,r):e.namespaceURI===Ie?rt(n,t,r):!!(Ke===`application/xhtml+xml`&&ze[e.namespaceURI]):!1},at=function(e){DJ(t.removed,{element:e});try{g(e).removeChild(e)}catch{if(p(e),!g(e))throw zJ(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},ot=function(e){let t=h(e);if(t){let e=[];TJ(t,t=>{DJ(e,t)}),TJ(e,e=>{try{p(e)}catch{}})}let n=v(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;if(typeof i==`string`)try{e.removeAttribute(i)}catch{}}},st=function(e,n){try{DJ(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{DJ(t.removed,{attribute:null,from:n})}if(n.removeAttribute(e),e===`is`)if(ye||be)try{at(n)}catch{}else try{n.setAttribute(e,``)}catch{}},ct=function(e){let t=v(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;if(!(typeof i!=`string`||ae[Je(i)]))try{e.removeAttribute(i)}catch{}}},lt=function(e){let t=[e];for(;t.length>0;){let e=t.pop();(y?y(e):e.nodeType)===tY.element&&ct(e);let n=h(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},ut=function(e){let t=null,r=null;if(ve)e=``+e;else{let t=jJ(e,/^[\r\n\t ]+/);r=t&&t[0]}Ke===`application/xhtml+xml`&&Le===Ie&&(e=``+e+``);let i=x?D(e):e;if(Le===Ie)try{t=new l().parseFromString(i,Ke)}catch{}if(!t||!t.documentElement){t=j.createDocument(Le,`template`,null);try{t.documentElement.innerHTML=Re?S:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),Le===Ie?P.call(t,ge?`html`:`body`)[0]:ge?t.documentElement:a},dt=function(e){return M.call(e.ownerDocument||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},ft=function(e){return e=MJ(e,L,` `),e=MJ(e,R,` `),e=MJ(e,z,` `),e},pt=function(e){e.normalize();let t=M.call(e.ownerDocument||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),n=t.nextNode();for(;n;)n.data=ft(n.data),n=t.nextNode();let r=e.querySelectorAll?.call(e,`template`);r&&TJ(r,e=>{ht(e.content)&&pt(e.content)})},mt=function(e){let t=b?b(e):null;return typeof t!=`string`||Je(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==v(e)||typeof e.removeAttribute!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==y(e)||e.childNodes!==h(e)},ht=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return y(e)===tY.documentFragment}catch{return!1}},gt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return typeof y(e)==`number`}catch{return!1}};function _t(e,n,r){e.length!==0&&TJ(e,e=>{e.call(t,n,r,Ye)})}let vt=function(e,t){return!!(he&&e.hasChildNodes()&&!gt(e.firstElementChild)&&RJ(eY,e.textContent)&&RJ(eY,e.innerHTML)||he&&e.namespaceURI===Ie&&t===`style`&>(e.firstElementChild)||e.nodeType===tY.processingInstruction||he&&e.nodeType===tY.comment&&RJ(UEe,e.data))},yt=function(e,t){if(!se[t]&&Ct(t)&&(U.tagNameCheck instanceof RegExp&&RJ(U.tagNameCheck,t)||U.tagNameCheck instanceof Function&&U.tagNameCheck(t)))return!1;if(Te&&!Oe[t]){let t=g(e),n=h(e);if(n&&t){let r=n.length;for(let i=r-1;i>=0;--i){let r=Ee?n[i]:f(n[i],!0);t.insertBefore(r,m(e))}}}return at(e),!0},bt=function(e){if(_t(I.beforeSanitizeElements,e,null),mt(e))return at(e),!0;let n=Je(b?b(e):e.nodeName);if(_t(I.uponSanitizeElement,e,{tagName:n,allowedTags:ie}),vt(e,n))return at(e),!0;if(se[n]||!(le.tagCheck instanceof Function&&le.tagCheck(n))&&!ie[n])return yt(e,n);if((y?y(e):e.nodeType)===tY.element&&!it(e)||(n===`noscript`||n===`noembed`||n===`noframes`)&&RJ(WEe,e.innerHTML))return at(e),!0;if(me&&e.nodeType===tY.text){let n=ft(e.textContent);e.textContent!==n&&(DJ(t.removed,{element:e.cloneNode()}),e.textContent=n)}return _t(I.afterSanitizeElements,e,null),!1},xt=function(e,t,r){if(ce[t]||Se&&(t===`id`||t===`name`)&&(r in n||r in Xe))return!1;let i=ae[t]||le.attributeCheck instanceof Function&&le.attributeCheck(t,e);if(!(de&&RJ(B,t))&&!(ue&&RJ(ee,t))){if(!i){if(!(Ct(e)&&(U.tagNameCheck instanceof RegExp&&RJ(U.tagNameCheck,e)||U.tagNameCheck instanceof Function&&U.tagNameCheck(e))&&(U.attributeNameCheck instanceof RegExp&&RJ(U.attributeNameCheck,t)||U.attributeNameCheck instanceof Function&&U.attributeNameCheck(t,e))||t===`is`&&U.allowCustomizedBuiltInElements&&(U.tagNameCheck instanceof RegExp&&RJ(U.tagNameCheck,r)||U.tagNameCheck instanceof Function&&U.tagNameCheck(r))))return!1}else if(!Me[t]&&!RJ(re,MJ(r,V,``))&&!((t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&NJ(r,`data:`)===0&&Ae[e])&&!(fe&&!RJ(te,MJ(r,V,``)))&&r)return!1}return!0},St=VJ({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Ct=function(e){return!St[kJ(e)]&&RJ(ne,e)},wt=function(e,t,n,r){if(x&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return D(r);case`TrustedScriptURL`:return O(r)}return r},Tt=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),mt(e)?at(e):EJ(t.removed)}catch{st(n,e)}},Et=function(e){_t(I.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||mt(e))return;let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:ae,forceKeepAttr:void 0},r=t.length,i=Je(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=Je(o),u=c,d=o===`value`?u:TEe(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,_t(I.uponSanitizeAttribute,e,n),d=n.attrValue,Ce&&(l===`id`||l===`name`)&&NJ(d,we)!==0&&(st(o,e),d=we+d),he&&RJ(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){st(o,e);continue}if(l===`attributename`&&jJ(d,`href`)){st(o,e);continue}if(!n.forceKeepAttr){if(!n.keepAttr){st(o,e);continue}if(!pe&&RJ(GEe,d)){st(o,e);continue}if(me&&(d=ft(d)),!xt(i,l,d)){st(o,e);continue}d=wt(i,l,s,d),d!==u&&Tt(e,o,s,d)}}_t(I.afterSanitizeAttributes,e,null)},Dt=function(e){let t=null,n=dt(e);for(_t(I.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(_t(I.uponSanitizeShadowNode,t,null),bt(t),Et(t),ht(t.content)&&Dt(t.content),(y?y(t):t.nodeType)===tY.element){let e=_(t);ht(e)&&(Ot(e),Dt(e))}_t(I.afterSanitizeShadowDOM,e,null)},Ot=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){Dt(e.shadow);continue}let n=e.node,r=(y?y(n):n.nodeType)===tY.element,i=h(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=b?b(n):null;if(typeof e==`string`&&Je(e)===`template`){let e=n.content;ht(e)&&t.push({node:e,shadow:null})}}if(r){let e=_(n);ht(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(Re=!e,Re&&(e=``),typeof e!=`string`&&!gt(e)&&(e=AEe(e),typeof e!=`string`))throw zJ(`dirty is not a string, aborting`);if(!t.isSupported)return e;_e||Qe(n),t.removed=[];let c=Ee&&typeof e!=`string`&>(e);if(c){let t=b?b(e):e.nodeName;if(typeof t==`string`){let e=Je(t);if(!ie[e]||se[e])throw zJ(`root node is forbidden and cannot be sanitized in-place`)}if(mt(e))throw zJ(`root node is clobbered and cannot be sanitized in-place`);try{Ot(e)}catch(t){throw ot(e),t}}else if(gt(e))i=ut(``),a=i.ownerDocument.importNode(e,!0),a.nodeType===tY.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),Ot(a);else{if(!ye&&!me&&!ge&&e.indexOf(`<`)===-1)return x&&xe?D(e):e;if(i=ut(e),!i)return ye?null:xe?S:``}i&&ve&&at(i.firstChild);let l=dt(c?e:i);try{for(;o=l.nextNode();)bt(o),Et(o),ht(o.content)&&Dt(o.content)}catch(t){throw c&&ot(e),t}if(c)return TJ(t.removed,e=>{e.element&<(e.element)}),me&&pt(e),e;if(ye){if(me&&pt(i),be)for(s=N.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(ae.shadowroot||ae.shadowrootmode)&&(s=F.call(r,s,!0)),s}let u=ge?i.outerHTML:i.innerHTML;return ge&&ie[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&RJ(VEe,i.ownerDocument.doctype.name)&&(u=` -`+u),me&&(u=ft(u)),x&&xe?D(u):u},t.setConfig=function(){Qe(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}),_e=!0},t.clearConfig=function(){Ye=null,_e=!1,x=C,S=``},t.isValidAttribute=function(e,t,n){return Ye||Qe({}),xt(Je(e),Je(t),n)},t.addHook=function(e,t){typeof t==`function`&&DJ(I[e],t)},t.removeHook=function(e,t){if(t!==void 0){let n=CEe(I[e],t);return n===-1?void 0:wEe(I[e],n,1)[0]}return EJ(I[e])},t.removeHooks=function(e){I[e]=[]},t.removeAllHooks=function(){I=nY()},t}var aY=iY();function oY(e){this.content=e}oY.prototype={constructor:oY,find:function(e){for(var t=0;t>1}},oY.from=function(e){if(e instanceof oY)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new oY(t)};function sY(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){for(let e=0;i.text[e]==a.text[e];e++)n++;return n}if(i.content.size||a.content.size){let e=sY(i.content,a.content,n+1);if(e!=null)return e}n+=i.nodeSize}}function cY(e,t,n,r){for(let i=e.childCount,a=t.childCount;;){if(i==0||a==0)return i==a?null:{a:n,b:r};let o=e.child(--i),s=t.child(--a),c=o.nodeSize;if(o==s){n-=c,r-=c;continue}if(!o.sameMarkup(s))return{a:n,b:r};if(o.isText&&o.text!=s.text){let e=0,t=Math.min(o.text.length,s.text.length);for(;ee&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);at)for(let e=0,a=0;at&&((an)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?dY(t+1,i):dY(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return new e(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;ethis.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;te.type.rank-t.type.rank),n}};pY.none=[];var mY=class extends Error{},hY=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=_Y(this.content,t+this.openStart,n);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(gY(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(lY.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};hY.empty=new hY(lY.empty,0,0);function gY(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(gY(a.content,t-i-1,n-i-1)))}function _Y(e,t,n,r){let{index:i,offset:a}=e.findIndex(t),o=e.maybeChild(i);if(a==t||o.isText)return r&&!r.canReplace(i,i,n)?null:e.cut(0,t).append(n).append(e.cut(t));let s=_Y(o.content,t-a-1,n,o);return s&&e.replaceChild(i,o.copy(s))}function JEe(e,t,n){if(n.openStart>e.depth)throw new mY(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new mY(`Inconsistent open depths`);return vY(e,t,n,0)}function vY(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function SY(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(xY(e.nodeAfter,r),a++));for(let e=a;ei&&bY(e,t,i+1),o=r.depth>i&&bY(n,r,i+1),s=[];return SY(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(yY(a,o),xY(CY(a,wY(e,t,n,r,i+1)),s)):(a&&xY(CY(a,TY(e,t,i+1)),s),SY(t,n,i,s),o&&xY(CY(o,TY(n,r,i+1)),s)),SY(r,null,i,s),new lY(s)}function TY(e,t,n){let r=[];return SY(null,e,n,r),e.depth>n&&xY(CY(bY(e,t,n+1),TY(e,t,n+1)),r),SY(t,null,n,r),new lY(r)}function YEe(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(lY.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var EY=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position before the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position after the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new OY(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=DY.get(t);if(r)for(let e=0;ee&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),AY(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=lY.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;ee.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=lY.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};kY.prototype.text=void 0;var $Ee=class e extends kY{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):AY(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function AY(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var jY=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new eDe(t,n);if(r.next==null)return e.empty;let i=MY(r);r.next&&r.err(`Unexpected trailing text`);let a=sDe(oDe(i));return cDe(a,r),a}matchType(e){for(let t=0;te.createAndFill()));for(let e=0;e=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n`+e.indexOf(t.next[n].next);return r}).join(` +In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function vEe(e,t){return hEe(e)||gEe(e,t)||yEe(e,t)||_Ee()}function yEe(e,t){if(e){if(typeof e==`string`)return gJ(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?gJ(e,t):void 0}}var _J=Object.entries,vJ=Object.setPrototypeOf,bEe=Object.isFrozen,xEe=Object.getPrototypeOf,SEe=Object.getOwnPropertyDescriptor,yJ=Object.freeze,bJ=Object.seal,xJ=Object.create,SJ=typeof Reflect<`u`&&Reflect,CJ=SJ.apply,wJ=SJ.construct;yJ||=function(e){return e},bJ||=function(e){return e},CJ||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},wJ||=function(e){return new e(...[...arguments].slice(1))};var TJ=BJ(Array.prototype.forEach),CEe=BJ(Array.prototype.lastIndexOf),EJ=BJ(Array.prototype.pop),DJ=BJ(Array.prototype.push),wEe=BJ(Array.prototype.splice),OJ=Array.isArray,kJ=BJ(String.prototype.toLowerCase),AJ=BJ(String.prototype.toString),jJ=BJ(String.prototype.match),MJ=BJ(String.prototype.replace),NJ=BJ(String.prototype.indexOf),TEe=BJ(String.prototype.trim),EEe=BJ(Number.prototype.toString),DEe=BJ(Boolean.prototype.toString),PJ=typeof BigInt>`u`?null:BJ(BigInt.prototype.toString),FJ=typeof Symbol>`u`?null:BJ(Symbol.prototype.toString),IJ=BJ(Object.prototype.hasOwnProperty),LJ=BJ(Object.prototype.toString),RJ=BJ(RegExp.prototype.test),zJ=OEe(TypeError);function BJ(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return CJ(e,t,n)}}function OEe(e){return function(){return wJ(e,[...arguments])}}function VJ(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:kJ;if(vJ&&vJ(e,null),!OJ(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(bEe(t)||(t[r]=e),i=e)}e[i]=!0}return e}function kEe(e){for(let t=0;t/g),IEe=bJ(/\${[\w\W]*/g),LEe=bJ(/^data-[\-\w.\u00B7-\uFFFF]+$/),REe=bJ(/^aria-[\-\w]+$/),$J=bJ(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),zEe=bJ(/^(?:\w+script|data):/i),BEe=bJ(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),VEe=bJ(/^html$/i),HEe=bJ(/^[a-z][.\w]*(-[.\w]+)+$/i),eY=bJ(/<[/\w!]/g),UEe=bJ(/<[/\w]/g),WEe=bJ(/<\/no(script|embed|frames)/i),GEe=bJ(/\/>/i),tY={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},KEe=function(){return typeof window>`u`?null:window},qEe=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},nY=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},rY=function(e,t,n,r){return IJ(e,t)&&OJ(e[t])?VJ(r.base?HJ(r.base):{},e[t],r.transform):n};function iY(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:KEe(),t=e=>iY(e);if(t.version=`3.4.11`,t.removed=[],!e||!e.document||e.document.nodeType!==tY.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=UJ(d,`cloneNode`),p=UJ(d,`remove`),m=UJ(d,`nextSibling`),h=UJ(d,`childNodes`),g=UJ(d,`parentNode`),_=UJ(d,`shadowRoot`),v=UJ(d,`attributes`),y=o&&o.prototype?UJ(o.prototype,`nodeType`):null,b=o&&o.prototype?UJ(o.prototype,`nodeName`):null;if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let x,S=``,C,w=!1,T=0,E=function(){if(T>0)throw zJ(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},D=function(e){E(),T++;try{return x.createHTML(e)}finally{T--}},O=function(e){E(),T++;try{return x.createScriptURL(e)}finally{T--}},k=function(){return w||=(C=qEe(u,i),!0),C},A=n,j=A.implementation,M=A.createNodeIterator,N=A.createDocumentFragment,P=A.getElementsByTagName,F=r.importNode,I=nY();t.isSupported=typeof _J==`function`&&typeof g==`function`&&j&&j.createHTMLDocument!==void 0;let L=PEe,R=FEe,z=IEe,B=LEe,ee=REe,te=zEe,V=BEe,ne=HEe,re=$J,ie=null,H=VJ({},[...WJ,...GJ,...KJ,...qJ,...JJ]),ae=null,oe=VJ({},[...YJ,...XJ,...ZJ,...QJ]),U=Object.seal(xJ(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),se=null,ce=null,le=Object.seal(xJ(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),ue=!0,de=!0,fe=!1,pe=!0,me=!1,he=!0,ge=!1,_e=!1,ve=null,ye=null,be=!1,xe=!1,Se=!1,Ce=!1,we=!0,Te=!1,Ee=`user-content-`,De=!0,Oe=!1,ke={},Ae=null,je=VJ({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),Me=null,Ne=VJ({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Pe=null,Fe=VJ({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),Ie=`http://www.w3.org/1998/Math/MathML`,Le=`http://www.w3.org/2000/svg`,Re=`http://www.w3.org/1999/xhtml`,ze=Re,Be=!1,Ve=null,He=VJ({},[Ie,Le,Re],AJ),Ue=yJ([`mi`,`mo`,`mn`,`ms`,`mtext`]),We=VJ({},Ue),Ge=yJ([`annotation-xml`]),Ke=VJ({},Ge),qe=VJ({},[`title`,`style`,`font`,`a`,`script`]),Je=null,Ye=[`application/xhtml+xml`,`text/html`],Xe=null,Ze=null,Qe=n.createElement(`form`),$e=function(e){return e instanceof RegExp||e instanceof Function},et=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(Ze&&Ze===e)return;(!e||typeof e!=`object`)&&(e={}),e=HJ(e),Je=Ye.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,Xe=Je===`application/xhtml+xml`?AJ:kJ,ie=rY(e,`ALLOWED_TAGS`,H,{transform:Xe}),ae=rY(e,`ALLOWED_ATTR`,oe,{transform:Xe}),Ve=rY(e,`ALLOWED_NAMESPACES`,He,{transform:AJ}),Pe=rY(e,`ADD_URI_SAFE_ATTR`,Fe,{transform:Xe,base:Fe}),Me=rY(e,`ADD_DATA_URI_TAGS`,Ne,{transform:Xe,base:Ne}),Ae=rY(e,`FORBID_CONTENTS`,je,{transform:Xe}),se=rY(e,`FORBID_TAGS`,HJ({}),{transform:Xe}),ce=rY(e,`FORBID_ATTR`,HJ({}),{transform:Xe}),ke=IJ(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?HJ(e.USE_PROFILES):e.USE_PROFILES:!1,ue=e.ALLOW_ARIA_ATTR!==!1,de=e.ALLOW_DATA_ATTR!==!1,fe=e.ALLOW_UNKNOWN_PROTOCOLS||!1,pe=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,me=e.SAFE_FOR_TEMPLATES||!1,he=e.SAFE_FOR_XML!==!1,ge=e.WHOLE_DOCUMENT||!1,xe=e.RETURN_DOM||!1,Se=e.RETURN_DOM_FRAGMENT||!1,Ce=e.RETURN_TRUSTED_TYPE||!1,be=e.FORCE_BODY||!1,we=e.SANITIZE_DOM!==!1,Te=e.SANITIZE_NAMED_PROPS||!1,De=e.KEEP_CONTENT!==!1,Oe=e.IN_PLACE||!1,re=jEe(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:$J,ze=typeof e.NAMESPACE==`string`?e.NAMESPACE:Re,We=IJ(e,`MATHML_TEXT_INTEGRATION_POINTS`)&&e.MATHML_TEXT_INTEGRATION_POINTS&&typeof e.MATHML_TEXT_INTEGRATION_POINTS==`object`?HJ(e.MATHML_TEXT_INTEGRATION_POINTS):VJ({},Ue),Ke=IJ(e,`HTML_INTEGRATION_POINTS`)&&e.HTML_INTEGRATION_POINTS&&typeof e.HTML_INTEGRATION_POINTS==`object`?HJ(e.HTML_INTEGRATION_POINTS):VJ({},Ge);let t=IJ(e,`CUSTOM_ELEMENT_HANDLING`)&&e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING==`object`?HJ(e.CUSTOM_ELEMENT_HANDLING):xJ(null);if(U=xJ(null),IJ(t,`tagNameCheck`)&&$e(t.tagNameCheck)&&(U.tagNameCheck=t.tagNameCheck),IJ(t,`attributeNameCheck`)&&$e(t.attributeNameCheck)&&(U.attributeNameCheck=t.attributeNameCheck),IJ(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(U.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),bJ(U),me&&(de=!1),Se&&(xe=!0),ke&&(ie=VJ({},JJ),ae=xJ(null),ke.html===!0&&(VJ(ie,WJ),VJ(ae,YJ)),ke.svg===!0&&(VJ(ie,GJ),VJ(ae,XJ),VJ(ae,QJ)),ke.svgFilters===!0&&(VJ(ie,KJ),VJ(ae,XJ),VJ(ae,QJ)),ke.mathMl===!0&&(VJ(ie,qJ),VJ(ae,ZJ),VJ(ae,QJ))),le.tagCheck=null,le.attributeCheck=null,IJ(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?le.tagCheck=e.ADD_TAGS:OJ(e.ADD_TAGS)&&(ie===H&&(ie=HJ(ie)),VJ(ie,e.ADD_TAGS,Xe))),IJ(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?le.attributeCheck=e.ADD_ATTR:OJ(e.ADD_ATTR)&&(ae===oe&&(ae=HJ(ae)),VJ(ae,e.ADD_ATTR,Xe))),IJ(e,`ADD_URI_SAFE_ATTR`)&&OJ(e.ADD_URI_SAFE_ATTR)&&VJ(Pe,e.ADD_URI_SAFE_ATTR,Xe),IJ(e,`FORBID_CONTENTS`)&&OJ(e.FORBID_CONTENTS)&&(Ae===je&&(Ae=HJ(Ae)),VJ(Ae,e.FORBID_CONTENTS,Xe)),IJ(e,`ADD_FORBID_CONTENTS`)&&OJ(e.ADD_FORBID_CONTENTS)&&(Ae===je&&(Ae=HJ(Ae)),VJ(Ae,e.ADD_FORBID_CONTENTS,Xe)),De&&(ie[`#text`]=!0),ge&&VJ(ie,[`html`,`head`,`body`]),ie.table&&(VJ(ie,[`tbody`]),delete se.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw zJ(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw zJ(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=x;x=e.TRUSTED_TYPES_POLICY;try{S=D(``)}catch(e){throw x=t,e}}else e.TRUSTED_TYPES_POLICY===null?(x=void 0,S=``):(x===void 0&&(x=k()),x&&typeof S==`string`&&(S=D(``)));yJ&&yJ(e),Ze=e},tt=VJ({},[...GJ,...KJ,...MEe]),nt=VJ({},[...qJ,...NEe]),rt=function(e,t,n){return t.namespaceURI===Re?e===`svg`:t.namespaceURI===Ie?e===`svg`&&(n===`annotation-xml`||We[n]):!!tt[e]},it=function(e,t,n){return t.namespaceURI===Re?e===`math`:t.namespaceURI===Le?e===`math`&&Ke[n]:!!nt[e]},at=function(e,t,n){return t.namespaceURI===Le&&!Ke[n]||t.namespaceURI===Ie&&!We[n]?!1:!nt[e]&&(qe[e]||!tt[e])},ot=function(e){let t=g(e);(!t||!t.tagName)&&(t={namespaceURI:ze,tagName:`template`});let n=kJ(e.tagName),r=kJ(t.tagName);return Ve[e.namespaceURI]?e.namespaceURI===Le?rt(n,t,r):e.namespaceURI===Ie?it(n,t,r):e.namespaceURI===Re?at(n,t,r):!!(Je===`application/xhtml+xml`&&Ve[e.namespaceURI]):!1},st=function(e){DJ(t.removed,{element:e});try{g(e).removeChild(e)}catch{if(p(e),!g(e))throw zJ(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},ct=function(e){let t=h(e);if(t){let e=[];TJ(t,t=>{DJ(e,t)}),TJ(e,e=>{try{p(e)}catch{}})}let n=v(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;if(typeof i==`string`)try{e.removeAttribute(i)}catch{}}},lt=function(e,n){try{DJ(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{DJ(t.removed,{attribute:null,from:n})}if(n.removeAttribute(e),e===`is`)if(xe||Se)try{st(n)}catch{}else try{n.setAttribute(e,``)}catch{}},ut=function(e){let t=v(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;if(!(typeof i!=`string`||ae[Xe(i)]))try{e.removeAttribute(i)}catch{}}},dt=function(e){let t=[e];for(;t.length>0;){let e=t.pop();(y?y(e):e.nodeType)===tY.element&&ut(e);let n=h(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},ft=function(e){let t=null,r=null;if(be)e=``+e;else{let t=jJ(e,/^[\r\n\t ]+/);r=t&&t[0]}Je===`application/xhtml+xml`&&ze===Re&&(e=``+e+``);let i=x?D(e):e;if(ze===Re)try{t=new l().parseFromString(i,Je)}catch{}if(!t||!t.documentElement){t=j.createDocument(ze,`template`,null);try{t.documentElement.innerHTML=Be?S:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),ze===Re?P.call(t,ge?`html`:`body`)[0]:ge?t.documentElement:a},pt=function(e){return M.call(e.ownerDocument||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},mt=function(e){return e=MJ(e,L,` `),e=MJ(e,R,` `),e=MJ(e,z,` `),e},ht=function(e){e.normalize();let t=M.call(e.ownerDocument||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),n=t.nextNode();for(;n;)n.data=mt(n.data),n=t.nextNode();let r=e.querySelectorAll?.call(e,`template`);r&&TJ(r,e=>{_t(e.content)&&ht(e.content)})},gt=function(e){let t=b?b(e):null;return typeof t!=`string`||Xe(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==v(e)||typeof e.removeAttribute!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==y(e)||e.childNodes!==h(e)},_t=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return y(e)===tY.documentFragment}catch{return!1}},vt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return typeof y(e)==`number`}catch{return!1}};function yt(e,n,r){e.length!==0&&TJ(e,e=>{e.call(t,n,r,Ze)})}let bt=function(e,t){return!!(he&&e.hasChildNodes()&&!vt(e.firstElementChild)&&RJ(eY,e.textContent)&&RJ(eY,e.innerHTML)||he&&e.namespaceURI===Re&&t===`style`&&vt(e.firstElementChild)||e.nodeType===tY.processingInstruction||he&&e.nodeType===tY.comment&&RJ(UEe,e.data))},xt=function(e,t){if(!se[t]&&Tt(t)&&(U.tagNameCheck instanceof RegExp&&RJ(U.tagNameCheck,t)||U.tagNameCheck instanceof Function&&U.tagNameCheck(t)))return!1;if(De&&!Ae[t]){let t=g(e),n=h(e);if(n&&t){let r=n.length;for(let i=r-1;i>=0;--i){let r=Oe?n[i]:f(n[i],!0);t.insertBefore(r,m(e))}}}return st(e),!0},St=function(e){if(yt(I.beforeSanitizeElements,e,null),gt(e))return st(e),!0;let n=Xe(b?b(e):e.nodeName);if(yt(I.uponSanitizeElement,e,{tagName:n,allowedTags:ie}),bt(e,n))return st(e),!0;if(se[n]||!(le.tagCheck instanceof Function&&le.tagCheck(n))&&!ie[n])return xt(e,n);if((y?y(e):e.nodeType)===tY.element&&!ot(e)||(n===`noscript`||n===`noembed`||n===`noframes`)&&RJ(WEe,e.innerHTML))return st(e),!0;if(me&&e.nodeType===tY.text){let n=mt(e.textContent);e.textContent!==n&&(DJ(t.removed,{element:e.cloneNode()}),e.textContent=n)}return yt(I.afterSanitizeElements,e,null),!1},Ct=function(e,t,r){if(ce[t]||we&&(t===`id`||t===`name`)&&(r in n||r in Qe))return!1;let i=ae[t]||le.attributeCheck instanceof Function&&le.attributeCheck(t,e);if(!(de&&RJ(B,t))&&!(ue&&RJ(ee,t))){if(!i){if(!(Tt(e)&&(U.tagNameCheck instanceof RegExp&&RJ(U.tagNameCheck,e)||U.tagNameCheck instanceof Function&&U.tagNameCheck(e))&&(U.attributeNameCheck instanceof RegExp&&RJ(U.attributeNameCheck,t)||U.attributeNameCheck instanceof Function&&U.attributeNameCheck(t,e))||t===`is`&&U.allowCustomizedBuiltInElements&&(U.tagNameCheck instanceof RegExp&&RJ(U.tagNameCheck,r)||U.tagNameCheck instanceof Function&&U.tagNameCheck(r))))return!1}else if(!Pe[t]&&!RJ(re,MJ(r,V,``))&&!((t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&NJ(r,`data:`)===0&&Me[e])&&!(fe&&!RJ(te,MJ(r,V,``)))&&r)return!1}return!0},wt=VJ({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Tt=function(e){return!wt[kJ(e)]&&RJ(ne,e)},Et=function(e,t,n,r){if(x&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return D(r);case`TrustedScriptURL`:return O(r)}return r},Dt=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),gt(e)?st(e):EJ(t.removed)}catch{lt(n,e)}},Ot=function(e){yt(I.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||gt(e))return;let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:ae,forceKeepAttr:void 0},r=t.length,i=Xe(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=Xe(o),u=c,d=o===`value`?u:TEe(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,yt(I.uponSanitizeAttribute,e,n),d=n.attrValue,Te&&(l===`id`||l===`name`)&&NJ(d,Ee)!==0&&(lt(o,e),d=Ee+d),he&&RJ(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){lt(o,e);continue}if(l===`attributename`&&jJ(d,`href`)){lt(o,e);continue}if(!n.forceKeepAttr){if(!n.keepAttr){lt(o,e);continue}if(!pe&&RJ(GEe,d)){lt(o,e);continue}if(me&&(d=mt(d)),!Ct(i,l,d)){lt(o,e);continue}d=Et(i,l,s,d),d!==u&&Dt(e,o,s,d)}}yt(I.afterSanitizeAttributes,e,null)},kt=function(e){let t=null,n=pt(e);for(yt(I.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(yt(I.uponSanitizeShadowNode,t,null),St(t),Ot(t),_t(t.content)&&kt(t.content),(y?y(t):t.nodeType)===tY.element){let e=_(t);_t(e)&&(W(e),kt(e))}yt(I.afterSanitizeShadowDOM,e,null)},W=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){kt(e.shadow);continue}let n=e.node,r=(y?y(n):n.nodeType)===tY.element,i=h(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=b?b(n):null;if(typeof e==`string`&&Xe(e)===`template`){let e=n.content;_t(e)&&t.push({node:e,shadow:null})}}if(r){let e=_(n);_t(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(Be=!e,Be&&(e=``),typeof e!=`string`&&!vt(e)&&(e=AEe(e),typeof e!=`string`))throw zJ(`dirty is not a string, aborting`);if(!t.isSupported)return e;_e?(ie=ve,ae=ye):et(n),(I.uponSanitizeElement.length>0||I.uponSanitizeAttribute.length>0)&&(ie=HJ(ie)),I.uponSanitizeAttribute.length>0&&(ae=HJ(ae)),t.removed=[];let c=Oe&&typeof e!=`string`&&vt(e);if(c){let t=b?b(e):e.nodeName;if(typeof t==`string`){let e=Xe(t);if(!ie[e]||se[e])throw zJ(`root node is forbidden and cannot be sanitized in-place`)}if(gt(e))throw zJ(`root node is clobbered and cannot be sanitized in-place`);try{W(e)}catch(t){throw ct(e),t}}else if(vt(e))i=ft(``),a=i.ownerDocument.importNode(e,!0),a.nodeType===tY.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),W(a);else{if(!xe&&!me&&!ge&&e.indexOf(`<`)===-1)return x&&Ce?D(e):e;if(i=ft(e),!i)return xe?null:Ce?S:``}i&&be&&st(i.firstChild);let l=pt(c?e:i);try{for(;o=l.nextNode();)St(o),Ot(o),_t(o.content)&&kt(o.content)}catch(t){throw c&&ct(e),t}if(c)return TJ(t.removed,e=>{e.element&&dt(e.element)}),me&&ht(e),e;if(xe){if(me&&ht(i),Se)for(s=N.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(ae.shadowroot||ae.shadowrootmode)&&(s=F.call(r,s,!0)),s}let u=ge?i.outerHTML:i.innerHTML;return ge&&ie[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&RJ(VEe,i.ownerDocument.doctype.name)&&(u=` +`+u),me&&(u=mt(u)),x&&Ce?D(u):u},t.setConfig=function(){et(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}),_e=!0,ve=ie,ye=ae},t.clearConfig=function(){Ze=null,_e=!1,ve=null,ye=null,x=C,S=``},t.isValidAttribute=function(e,t,n){return Ze||et({}),Ct(Xe(e),Xe(t),n)},t.addHook=function(e,t){typeof t==`function`&&IJ(I,e)&&DJ(I[e],t)},t.removeHook=function(e,t){if(IJ(I,e)){if(t!==void 0){let n=CEe(I[e],t);return n===-1?void 0:wEe(I[e],n,1)[0]}return EJ(I[e])}},t.removeHooks=function(e){IJ(I,e)&&(I[e]=[])},t.removeAllHooks=function(){I=nY()},t}var aY=iY();function oY(e){this.content=e}oY.prototype={constructor:oY,find:function(e){for(var t=0;t>1}},oY.from=function(e){if(e instanceof oY)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new oY(t)};function sY(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){for(let e=0;i.text[e]==a.text[e];e++)n++;return n}if(i.content.size||a.content.size){let e=sY(i.content,a.content,n+1);if(e!=null)return e}n+=i.nodeSize}}function cY(e,t,n,r){for(let i=e.childCount,a=t.childCount;;){if(i==0||a==0)return i==a?null:{a:n,b:r};let o=e.child(--i),s=t.child(--a),c=o.nodeSize;if(o==s){n-=c,r-=c;continue}if(!o.sameMarkup(s))return{a:n,b:r};if(o.isText&&o.text!=s.text){let e=0,t=Math.min(o.text.length,s.text.length);for(;ee&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);at)for(let e=0,a=0;at&&((an)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?dY(t+1,i):dY(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return new e(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;ethis.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;te.type.rank-t.type.rank),n}};pY.none=[];var mY=class extends Error{},hY=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=_Y(this.content,t+this.openStart,n);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(gY(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(lY.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};hY.empty=new hY(lY.empty,0,0);function gY(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(gY(a.content,t-i-1,n-i-1)))}function _Y(e,t,n,r){let{index:i,offset:a}=e.findIndex(t),o=e.maybeChild(i);if(a==t||o.isText)return r&&!r.canReplace(i,i,n)?null:e.cut(0,t).append(n).append(e.cut(t));let s=_Y(o.content,t-a-1,n,o);return s&&e.replaceChild(i,o.copy(s))}function JEe(e,t,n){if(n.openStart>e.depth)throw new mY(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new mY(`Inconsistent open depths`);return vY(e,t,n,0)}function vY(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function SY(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(xY(e.nodeAfter,r),a++));for(let e=a;ei&&bY(e,t,i+1),o=r.depth>i&&bY(n,r,i+1),s=[];return SY(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(yY(a,o),xY(CY(a,wY(e,t,n,r,i+1)),s)):(a&&xY(CY(a,TY(e,t,i+1)),s),SY(t,n,i,s),o&&xY(CY(o,TY(n,r,i+1)),s)),SY(r,null,i,s),new lY(s)}function TY(e,t,n){let r=[];return SY(null,e,n,r),e.depth>n&&xY(CY(bY(e,t,n+1),TY(e,t,n+1)),r),SY(t,null,n,r),new lY(r)}function YEe(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(lY.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var EY=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position before the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position after the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new OY(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=DY.get(t);if(r)for(let e=0;ee&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),AY(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=lY.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;ee.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=lY.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};kY.prototype.text=void 0;var $Ee=class e extends kY{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):AY(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function AY(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var jY=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new eDe(t,n);if(r.next==null)return e.empty;let i=MY(r);r.next&&r.err(`Unexpected trailing text`);let a=sDe(oDe(i));return cDe(a,r),a}matchType(e){for(let t=0;te.createAndFill()));for(let e=0;e=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n`+e.indexOf(t.next[n].next);return r}).join(` `)}};jY.empty=new jY(!0);var eDe=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==``&&this.tokens.pop(),this.tokens[0]==``&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+` (in content expression '`+this.string+`')`)}};function MY(e){let t=[];do t.push(tDe(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function tDe(e){let t=[];do t.push(nDe(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function nDe(e){let t=aDe(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=rDe(e,t);else break;return t}function NY(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function rDe(e,t){let n=NY(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:NY(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function iDe(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return i.length==0&&e.err(`No node type or group '`+t+`' found`),i}function aDe(e){if(e.eat(`(`)){let t=MY(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}else if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=iDe(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function oDe(e){let t=[[]];return i(a(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}function a(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(a(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let o=a(e.exprs[r],t);if(r==e.exprs.length-1)return o;i(o,t=n())}else if(e.type==`star`){let o=n();return r(t,o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`plus`){let o=n();return i(a(e.expr,t),o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`opt`)return[r(t)].concat(a(e.expr,t));else if(e.type==`range`){let o=t;for(let t=0;t{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e{r||i.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let a=t[r.join(`,`)]=new jY(r.indexOf(e.length-1)>-1);for(let e=0;e-1}get whitespace(){return this.spec.whitespace||(this.spec.code?`pre`:`normal`)}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:LY(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new kY(this,this.computeAttrs(e),lY.from(t),pY.setFrom(n))}createChecked(e=null,t,n){return t=lY.from(t),this.checkContent(t),new kY(this,this.computeAttrs(e),t,pY.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=lY.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(lY.empty,!0);return i?new kY(this,e,t.append(i),pY.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[t]=new e(t,n,i));let i=n.spec.topNode||`doc`;if(!r[i])throw RangeError(`Schema is missing its top node type ('`+i+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function lDe(e,t,n){let r=n.split(`|`);return n=>{let i=n===null?`null`:typeof n;if(r.indexOf(i)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}var uDe=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?lDe(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},VY=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=zY(e,r.attrs),this.excluded=null;let i=IY(this.attrs);this.instance=i?new pY(this,i):null}create(e=null){return!e&&this.instance?this.instance:new pY(this,LY(this.attrs,e))}static compile(t,n){let r=Object.create(null),i=0;return t.forEach((t,a)=>r[t]=new e(t,i++,n,a)),r}removeFromSet(e){for(var t=0;t-1}},HY=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=oY.from(e.nodes),t.marks=oY.from(e.marks||{}),this.nodes=BY.compile(this.spec.nodes,this),this.marks=VY.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],r=t.spec.content||``,i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=jY.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=i==`_`?null:i?UY(this,i.split(` `)):i==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:UY(this,n.split(` `))}this.nodeFromJSON=e=>kY.fromJSON(this,e),this.markFromJSON=e=>pY.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof BY))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new $Ee(n,n.defaultAttrs,e,pY.setFrom(t))}mark(e,t){return typeof e==`string`&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type: `+e);return t}};function UY(e,t){let n=[];for(let r=0;r-1)&&n.push(o=r)}if(!o)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function dDe(e){return e.tag!=null}function fDe(e){return e.style!=null}var WY=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(dDe(e))this.tags.push(e);else if(fDe(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new QY(this,t,!1);return n.addAll(e,pY.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new QY(this,t,!0);return n.addAll(e,pY.none,t.from,t.to),hY.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;re.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r{n(e=$Y(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=$Y(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},GY={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},pDe={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},KY={ol:!0,ul:!0},qY=1,JY=2,YY=4;function XY(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?qY:0)|(t===`full`?JY:0)}var ZY=class{constructor(e,t,n,r,i,a){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=a,this.content=[],this.activeMarks=pY.none,this.match=i||(a&YY?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(lY.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&qY)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=lY.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(lY.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!GY.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},QY=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,a=XY(null,t.preserveWhitespace,0)|(n?YY:0);i=r?new ZY(r.type,r.attrs,pY.none,!0,t.topMatch||r.type.contentMatch,a):n?new ZY(null,null,pY.none,!0,null,a):new ZY(e.schema.topNodeType,null,pY.none,!0,null,a),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=r.options&JY?`full`:this.localPreserveWS||(r.options&qY)>0,{schema:a}=this.parser;if(i===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(!i){if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&i.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}}else if(i===`full`)n=n.replace(/\r\n?/g,` `);else if(a.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(a.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,a;if(t.node)if(a=this.parser.schema.nodes[t.node],a.isLeaf)this.insertNode(a.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(a,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let a=n?e.childNodes[n]:e.firstChild,o=r==null?null:e.childNodes[r];a!=o;a=a.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(a,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,a=0;t>=0;t--){let o=this.nodes[t],s=o.findWrapping(e);if(s&&(!r||r.length>s.length+a)&&(r=s,i=o,!s.length))break;if(o.solid){if(n)break;a+=2}}if(!r)return null;this.sync(i);for(let e=0;e(a.type?a.type.allowsMarkType(t.type):eX(t.type,e))?(s=t.addToSet(s),!1):!0),this.nodes.push(new ZY(e,t,s,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=qY);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split(`/`),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,a=(e,o)=>{for(;e>=0;e--){let s=t[e];if(s==``){if(e==t.length-1||e==0)continue;for(;o>=i;o--)if(a(e-1,o))return!0;return!1}else{let e=o>0||o==0&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;o--}}return!0};return a(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function mDe(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&KY.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function hDe(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function $Y(e){let t={};for(let n in e)t[n]=e[n];return t}function eX(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let a=[],o=e=>{a.push(e);for(let n=0;n{if(i.length||e.marks.length){let n=0,a=0;for(;n=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&aX(rX(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return aX(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=nX(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return nX(e.marks)}};function nX(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function rX(e){return e.document||window.document}var iX=new WeakMap;function gDe(e){let t=iX.get(e);return t===void 0&&iX.set(e,t=_De(e)),t}function _De(e){let t=null;function n(e){if(e&&typeof e==`object`)if(Array.isArray(e))if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t-1)throw RangeError(`Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.`);let o=i.indexOf(` `);o>0&&(n=i.slice(0,o),i=i.slice(o+1));let s,c=n?e.createElementNS(n,i):e.createElement(i),l=t[1],u=1;if(l&&typeof l==`object`&&l.nodeType==null&&!Array.isArray(l)){u=2;for(let e in l)if(l[e]!=null){let t=e.indexOf(` `);t>0?c.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):e==`style`&&c.style?c.style.cssText=l[e]:c.setAttribute(e,l[e])}}for(let i=u;iu)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:c,contentDOM:c}}else{let{dom:t,contentDOM:i}=aX(e,a,n,r);if(c.appendChild(t),i){if(s)throw RangeError(`Multiple content holes`);s=i}}}return{dom:c,contentDOM:s}}var oX=65535,sX=2**16;function vDe(e,t){return e+t*sX}function cX(e){return e&oX}function yDe(e){return(e-(e&oX))/sX}var bDe=1,xDe=2,lX=4,uX=8,dX=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&uX)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&lX)>0}},fX=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=cX(e);if(!this.inverted)for(let e=0;ee)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e==s?-1:e==u?1:t:t,a=s+r+(i<0?0:l);if(n)return a;let d=e==(t<0?s:u)?null:vDe(o/3,e-s),f=e==s?xDe:e==u?bDe:lX;return(t<0?e!=s:e!=u)&&(f|=uX),new dX(a,f,d)}r+=l-c}return n?e+r:new dX(e+r,0,null)}touches(e,t){let n=0,r=cX(t),i=this.inverted?2:1,a=this.inverted?1:2;for(let t=0;te)break;let s=this.ranges[t+i];if(e<=o+s&&t==r*3)return!0;n+=this.ranges[t+a]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let t=new e;return t.appendMappingInverted(this),t}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;nn&&t!e.isAtom||!t.type.allowsMarkType(this.mark.type)?e:e.mark(this.mark.addToSet(e.marks)),r),t.openStart,t.openEnd);return gX.fromReplace(e,this.from,this.to,i)}invert(){return new yX(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};hX.jsonID(`addMark`,vX);var yX=class e extends hX{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new hY(_X(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return gX.fromReplace(e,this.from,this.to,n)}invert(){return new vX(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};hX.jsonID(`removeMark`,yX);var bX=class e extends hX{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return gX.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return gX.fromReplace(e,this.pos,this.pos+1,new hY(lY.from(n),0,+!t.isLeaf))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;rr.pos?null:new e(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:`replaceAround`,from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`||typeof n.gapFrom!=`number`||typeof n.gapTo!=`number`||typeof n.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new e(n.from,n.to,n.gapFrom,n.gapTo,hY.fromJSON(t,n.slice),n.insert,!!n.structure)}};hX.jsonID(`replaceAround`,CX);function wX(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)==r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function SDe(e,t,n,r){let i=[],a=[],o,s;e.doc.nodesBetween(t,n,(e,c,l)=>{if(!e.isInline)return;let u=e.marks;if(!r.isInSet(u)&&l.type.allowsMarkType(r.type)){let l=Math.max(c,t),d=Math.min(c+e.nodeSize,n),f=r.addToSet(u);for(let e=0;ee.step(t)),a.forEach(t=>e.step(t))}function CDe(e,t,n,r){let i=[],a=0;e.doc.nodesBetween(t,n,(e,o)=>{if(!e.isInline)return;a++;let s=null;if(r instanceof VY){let t=e.marks,n;for(;n=r.isInSet(t);)(s||=[]).push(n),t=n.removeFromSet(t)}else r?r.isInSet(e.marks)&&(s=[r]):s=e.marks;if(s&&s.length){let r=Math.min(o+e.nodeSize,n);for(let e=0;ee.step(new yX(t.from,t.to,t.style)))}function TX(e,t,n,r=n.contentMatch,i=!0){let a=e.doc.nodeAt(t),o=[],s=t+1;for(let t=0;t=0;t--)e.step(o[t])}function wDe(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function EX(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let a=e.$from.node(n),o=e.$from.index(n)+r,s=e.$to.indexAfter(n)-i;if(nn;e--)t||r.index(e)>0?(t=!0,u=lY.from(r.node(e).copy(u)),d++):c--;let f=lY.empty,p=0;for(let e=a,t=!1;e>n;e--)t||i.after(e+1)=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError(`Wrapper type given to Transform.wrap does not form valid content of its parent wrapper`)}r=lY.from(n[e].type.create(n[e].attrs,r))}let i=t.start,a=t.end;e.step(new CX(i,a,i,a,new hY(r,0,0),n.length,!0))}function kDe(e,t,n,r,i){if(!r.isTextblock)throw RangeError(`Type given to setBlockType should be a textblock`);let a=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let o=typeof i==`function`?i(t):i;if(t.isTextblock&&!t.hasMarkup(r,o)&&ADe(e.doc,e.mapping.slice(a).map(n),r)){let i=null;if(r.schema.linebreakReplacement){let e=r.whitespace==`pre`,t=!!r.contentMatch.matchType(r.schema.linebreakReplacement);e&&!t?i=!1:!e&&t&&(i=!0)}i===!1&&AX(e,t,n,a),TX(e,e.mapping.slice(a).map(n,1),r,void 0,i===null);let s=e.mapping.slice(a),c=s.map(n,1),l=s.map(n+t.nodeSize,1);return e.step(new CX(c,l,c+1,l-1,new hY(lY.from(r.create(o,null,t.marks)),0,0),1,!0)),i===!0&&kX(e,t,n,a),!1}})}function kX(e,t,n,r){t.forEach((i,a)=>{if(i.isText){let o,s=/\r?\n|\r/g;for(;o=s.exec(i.text);){let i=e.mapping.slice(r).map(n+1+a+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function AX(e,t,n,r){t.forEach((i,a)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+a);e.replaceWith(i,i+1,t.type.schema.text(` diff --git a/static/index.html b/static/index.html index 9d3daa88e..1a3babee8 100644 --- a/static/index.html +++ b/static/index.html @@ -26,7 +26,7 @@ - +