auto-champion-select 1.8.0 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +4 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode('.dropdown-champions-default{position:inherit;inline-size:100%}.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-menu),.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-content),.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-options){top:auto;bottom:100%;transform-origin:bottom}.champion-priority-selector{display:grid;gap:0;padding:2px 0 3px}.champion-priority-selector__scroll{position:relative;inline-size:100%;height:58px;border:1px solid rgba(120,90,40,.7);border-top:0;background:rgba(30,35,40,.5);box-sizing:border-box}.champion-priority-selector__track{display:inline-flex;align-items:center;gap:6px;min-width:max-content;min-height:45px;padding:6px 8px 10px;box-sizing:border-box}.champion-priority-selector__empty{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;color:#5f5b4f;font-family:var(--font-body);font-size:11px;line-height:13px;text-align:center;white-space:nowrap;pointer-events:none}.champion-priority-selector__icon{position:relative;flex:0 0 auto;width:34px;height:34px;border:1px solid #c8aa6e;border-radius:50%;background:#1e2328;box-shadow:0 0 0 1px #010a13e6;box-sizing:border-box;cursor:grab;outline:none}.champion-priority-selector__icon:focus{border-color:#f0e6d2}.champion-priority-selector__icon--dragging{cursor:grabbing;filter:brightness(1.15);z-index:1}.champion-priority-selector__icon:before{content:attr(data-rank);position:absolute;left:-5px;top:-6px;width:15px;height:15px;border:1px solid #c8aa6e;border-radius:50%;background:#010a13;box-sizing:border-box;color:#f0e6d2;font-family:var(--font-body);font-size:9px;font-weight:700;line-height:13px;text-align:center;pointer-events:none}.champion-priority-selector__icon img{display:block;width:100%;height:100%;border-radius:50%;object-fit:cover;pointer-events:none}.champion-priority-selector__remove{position:absolute;right:-5px;bottom:-5px;width:16px;height:16px;padding:0;border:1px solid #785a28;border-radius:50%;background:#1e2328;box-sizing:border-box;color:#c8aa6e;cursor:pointer;font-family:var(--font-body);font-size:10px;font-weight:700;line-height:13px;text-align:center}.champion-priority-selector__remove:hover{border-color:#c8aa6e;color:#f0e6d2}.champion-priority-selector__position-badge{position:absolute;left:-5px;bottom:-5px;display:grid;place-items:center;width:16px;height:16px;border:1px solid #785a28;border-radius:50%;background:#010a13;box-sizing:border-box;pointer-events:none}.champion-priority-selector__position-badge img{display:block;width:10px;height:10px;object-fit:contain}.champion-priority-selector__position-badge:after{content:attr(data-count);position:absolute;right:-4px;top:-5px;display:none;min-width:10px;height:10px;border:1px solid #785a28;border-radius:50%;background:#010a13;box-sizing:border-box;color:#f0e6d2;font-family:var(--font-body);font-size:7px;font-weight:700;line-height:8px;text-align:center}.champion-priority-selector__position-badge[data-count]:after{display:block}.champion-priority-selector__position-menu{position:fixed;z-index:10002;display:flex;gap:4px;padding:5px;border:1px solid #785a28;background:#010a13;box-shadow:0 0 0 1px #010a13d9,0 4px 16px #0000008c;box-sizing:border-box}.champion-priority-selector__position-menu[hidden]{display:none}.champion-priority-selector__position-option{display:grid;place-items:center;width:28px;height:28px;padding:0;border:1px solid #463714;background:#1e2328;box-sizing:border-box;cursor:pointer}.champion-priority-selector__position-option:hover,.champion-priority-selector__position-option--selected{border-color:#c8aa6e;background:#0f1b2d}.champion-priority-selector__position-option img{display:block;width:18px;height:18px;pointer-events:none}.auto-select-checkboxes-div{display:flex;border-top:thin solid #1e282d}.auto-select-checkbox{margin:auto}.auto-select-checkbox:last-child{margin-right:17px}.auto-select-champ-select-menu{position:absolute;right:0;bottom:36px;z-index:10000;width:min(340px,calc(100vw - 32px));color:#a09b8c;font-family:var(--font-body);font-size:12px;font-weight:400;line-height:normal;pointer-events:none;text-transform:none}.auto-select-champ-select-menu-button-wrapper{position:relative;display:block;width:38px;height:32px;z-index:10000;flex:0 0 38px;box-sizing:border-box}.auto-select-champ-select-menu__header{position:relative;display:block;width:38px;height:32px;border:none;background-image:url(/fe/lol-social/chat_button.png);background-color:transparent;background-position:0 0;background-repeat:no-repeat;background-size:cover;box-shadow:none;cursor:pointer;outline:none;padding:0}.auto-select-champ-select-menu-button-wrapper:after{content:"🐧 New";position:absolute;left:50%;top:-8px;z-index:2;display:flex;align-items:center;justify-content:center;height:16px;box-sizing:border-box;min-width:44px;padding:0 5px;border-radius:3px;background-color:#ffe610;box-shadow:#010a1380 0 0 2px;color:#010a13;font-family:var(--font-body);font-size:12px;font-weight:700;line-height:16px;pointer-events:none;transform:translate(-50%);white-space:nowrap}.auto-select-champ-select-menu__header:before{content:"";position:absolute;left:50%;top:50%;width:20px;height:20px;background:url(/fe/lol-static-assets/images/nav-icon-collections.svg) center / 20px 20px no-repeat;filter:drop-shadow(0 0 1px #010a13);transform:translate(-50%,-50%)}.auto-select-champ-select-menu__header:hover{background-position:0 -32px}.auto-select-champ-select-menu__header:active{background-position:0 -64px}.auto-select-champ-select-menu-button-wrapper--open .auto-select-champ-select-menu__header{background-position:0 -96px}.auto-select-champ-select-menu-button-wrapper--open .auto-select-champ-select-menu__header:hover{background-position:0 -128px}.auto-select-champ-select-menu-button-wrapper--open .auto-select-champ-select-menu__header:active{background-position:0 -160px}.auto-select-champ-select-menu__content{display:grid;gap:4px;width:100%;margin-bottom:4px;border:1px solid #785a28;background:rgba(1,10,19,.96);box-shadow:0 0 18px #000000a6;box-sizing:border-box;pointer-events:auto;padding:8px}.auto-select-champ-select-menu__title{display:flex;align-items:center;justify-content:center;min-height:24px;padding-bottom:4px;border-bottom:thin solid #1e282d;color:#f0e6d2;font-family:var(--font-display);font-size:14px;font-weight:700;text-align:center}.auto-select-champ-select-menu .auto-select-checkboxes-div{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));align-items:center;border-top:0;border-bottom:thin solid #1e282d;padding-bottom:6px}.auto-select-champ-select-menu .auto-select-checkbox{justify-self:center;margin:0}.auto-select-champ-select-menu .dropdown-champions-default{min-height:32px}.auto-select-champ-select-menu .champion-priority-selector__scroll{height:56px}.auto-select-champ-select-menu--collapsed .auto-select-champ-select-menu__content{display:none}')),document.head.appendChild(e)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
1
+ (function(){"use strict";try{if(typeof document<"u"){var o=document.createElement("style");o.appendChild(document.createTextNode('.dropdown-champions-default{position:inherit;inline-size:100%}.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-menu),.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-content),.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-options){top:auto;bottom:100%;transform-origin:bottom}.champion-priority-selector{display:grid;gap:0;padding:2px 0 3px}.champion-priority-selector__scroll{position:relative;inline-size:100%;height:58px;border:1px solid rgba(120,90,40,.7);border-top:0;background:rgba(30,35,40,.5);box-sizing:border-box}.champion-priority-selector__track{display:inline-flex;align-items:center;gap:6px;min-width:max-content;min-height:45px;padding:6px 8px 10px;box-sizing:border-box}.champion-priority-selector__empty{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;color:#5f5b4f;font-family:var(--font-body);font-size:11px;line-height:13px;text-align:center;white-space:nowrap;pointer-events:none}.champion-priority-selector__icon{position:relative;flex:0 0 auto;width:34px;height:34px;border:1px solid #c8aa6e;border-radius:50%;background:#1e2328;box-shadow:0 0 0 1px #010a13e6;box-sizing:border-box;cursor:grab;outline:none}.champion-priority-selector__icon:focus{border-color:#f0e6d2}.champion-priority-selector__icon--dragging{cursor:grabbing;filter:brightness(1.15);z-index:1}.champion-priority-selector__icon:before{content:attr(data-rank);position:absolute;left:-5px;top:-6px;width:15px;height:15px;border:1px solid #c8aa6e;border-radius:50%;background:#010a13;box-sizing:border-box;color:#f0e6d2;font-family:var(--font-body);font-size:9px;font-weight:700;line-height:13px;text-align:center;pointer-events:none}.champion-priority-selector__icon img{display:block;width:100%;height:100%;border-radius:50%;object-fit:cover;pointer-events:none}.champion-priority-selector__remove{position:absolute;right:-5px;bottom:-5px;width:16px;height:16px;padding:0;border:1px solid #785a28;border-radius:50%;background:#1e2328;box-sizing:border-box;color:#c8aa6e;cursor:pointer;font-family:var(--font-body);font-size:10px;font-weight:700;line-height:13px;text-align:center}.champion-priority-selector__remove:hover{border-color:#c8aa6e;color:#f0e6d2}.champion-priority-selector__position-badge{position:absolute;left:-5px;bottom:-5px;display:grid;place-items:center;width:16px;height:16px;-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:0;border:1px solid #785a28;border-radius:50%;background:#010a13;box-sizing:border-box;color:#c8aa6e;cursor:pointer;font-family:var(--font-body);font-size:12px;font-weight:700;line-height:14px}.champion-priority-selector__position-badge:hover,.champion-priority-selector__position-badge:focus{border-color:#c8aa6e;color:#f0e6d2;outline:none}.champion-priority-selector__position-badge--empty{background:#1e2328}.champion-priority-selector__position-badge img{display:block;width:10px;height:10px;object-fit:contain}.champion-priority-selector__position-badge:after{content:attr(data-count);position:absolute;right:-4px;top:-5px;display:none;min-width:10px;height:10px;border:1px solid #785a28;border-radius:50%;background:#010a13;box-sizing:border-box;color:#f0e6d2;font-family:var(--font-body);font-size:7px;font-weight:700;line-height:8px;text-align:center}.champion-priority-selector__position-badge[data-count]:after{display:block}.champion-priority-selector__position-menu{position:fixed;z-index:10002;display:flex;gap:4px;padding:5px;border:1px solid #785a28;background:#010a13;box-shadow:0 0 0 1px #010a13d9,0 4px 16px #0000008c;box-sizing:border-box}.champion-priority-selector__position-menu[hidden]{display:none}.champion-priority-selector__position-option{display:grid;place-items:center;width:28px;height:28px;padding:0;border:1px solid #463714;background:#1e2328;box-sizing:border-box;cursor:pointer}.champion-priority-selector__position-option:hover,.champion-priority-selector__position-option--selected{border-color:#c8aa6e;background:#0f1b2d}.champion-priority-selector__position-option img{display:block;width:18px;height:18px;pointer-events:none}.auto-select-checkboxes-div{display:flex;border-top:thin solid #1e282d}.auto-select-checkbox{margin:auto}.auto-select-checkbox:last-child{margin-right:17px}.auto-select-champ-select-menu{position:absolute;right:0;bottom:36px;z-index:10000;width:min(340px,calc(100vw - 32px));color:#a09b8c;font-family:var(--font-body);font-size:12px;font-weight:400;line-height:normal;pointer-events:none;text-transform:none}.auto-select-champ-select-menu-button-wrapper{position:relative;display:block;width:38px;height:32px;z-index:10000;flex:0 0 38px;box-sizing:border-box}.auto-select-champ-select-menu__header{position:relative;display:block;width:38px;height:32px;border:none;background-image:url(/fe/lol-social/chat_button.png);background-color:transparent;background-position:0 0;background-repeat:no-repeat;background-size:cover;box-shadow:none;cursor:pointer;outline:none;padding:0}.auto-select-champ-select-menu-button-wrapper:after{content:"🐧 New";position:absolute;left:50%;top:-8px;z-index:2;display:flex;align-items:center;justify-content:center;height:16px;box-sizing:border-box;min-width:44px;padding:0 5px;border-radius:3px;background-color:#ffe610;box-shadow:#010a1380 0 0 2px;color:#010a13;font-family:var(--font-body);font-size:12px;font-weight:700;line-height:16px;pointer-events:none;transform:translate(-50%);white-space:nowrap}.auto-select-champ-select-menu__header:before{content:"";position:absolute;left:50%;top:50%;width:20px;height:20px;background:url(/fe/lol-static-assets/images/nav-icon-collections.svg) center / 20px 20px no-repeat;filter:drop-shadow(0 0 1px #010a13);transform:translate(-50%,-50%)}.auto-select-champ-select-menu__header:hover{background-position:0 -32px}.auto-select-champ-select-menu__header:active{background-position:0 -64px}.auto-select-champ-select-menu-button-wrapper--open .auto-select-champ-select-menu__header{background-position:0 -96px}.auto-select-champ-select-menu-button-wrapper--open .auto-select-champ-select-menu__header:hover{background-position:0 -128px}.auto-select-champ-select-menu-button-wrapper--open .auto-select-champ-select-menu__header:active{background-position:0 -160px}.auto-select-champ-select-menu__content{display:grid;gap:4px;width:100%;margin-bottom:4px;border:1px solid #785a28;background:rgba(1,10,19,.96);box-shadow:0 0 18px #000000a6;box-sizing:border-box;pointer-events:auto;padding:8px}.auto-select-champ-select-menu__title{display:flex;align-items:center;justify-content:center;min-height:24px;padding-bottom:4px;border-bottom:thin solid #1e282d;color:#f0e6d2;font-family:var(--font-display);font-size:14px;font-weight:700;text-align:center}.auto-select-champ-select-menu .auto-select-checkboxes-div{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));align-items:center;border-top:0;border-bottom:thin solid #1e282d;padding-bottom:6px}.auto-select-champ-select-menu .auto-select-checkbox{justify-self:center;margin:0}.auto-select-champ-select-menu .dropdown-champions-default{min-height:32px}.auto-select-champ-select-menu .champion-priority-selector__scroll{height:56px}.auto-select-champ-select-menu--collapsed .auto-select-champ-select-menu__content{display:none}')),document.head.appendChild(o)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
2
2
  /**
3
3
  * @author balaclava
4
4
  * @name auto-champion-select
5
5
  * @link https://github.com/controlado/auto-champion-select#readme
6
6
  * @description Pick or ban automatically! 🐧
7
- * @version 1.8.0
7
+ * @version 1.8.1
8
8
  * @license GPL-3.0-or-later
9
9
  */
10
- import{request as f,sleep as g,linkEndpoint as x}from"https://cdn.jsdelivr.net/npm/balaclava-utils@latest";const ht="1.8.0",dt={enabled:!1},ut={enabled:!1,force:!1,champions:[432,235],positionsByChampionId:{235:["BOTTOM","UTILITY"],432:["UTILITY"]}},pt={enabled:!1,force:!1,champions:[157,777,238,38]},mt={controladoAutoAccept:dt,controladoPick:ut,controladoBan:pt};function h(o){const t=Number(o);return Number.isSafeInteger(t)&&t>0?t:null}function X(o,t=null){const e=[],n=new Set,i=ft(t);if(!Array.isArray(o))return e;for(const s of o){const a=h(s);a===null||n.has(a)||i&&!i.has(a)||(e.push(a),n.add(a))}return e}function ft(o){return o?new Set(Array.from(o,h).filter(t=>t!==null)):null}const P=[{value:"TOP",label:"Top",iconPath:"/fe/lol-parties/icon-position-top.png"},{value:"JUNGLE",label:"Jungle",iconPath:"/fe/lol-parties/icon-position-jungle.png"},{value:"MIDDLE",label:"Mid",iconPath:"/fe/lol-parties/icon-position-middle.png"},{value:"BOTTOM",label:"ADC",iconPath:"/fe/lol-parties/icon-position-bottom.png"},{value:"UTILITY",label:"Support",iconPath:"/fe/lol-parties/icon-position-utility.png"}],gt=new Set(P.map(o=>o.value));function I(o){const t=String(o??"").toUpperCase();return gt.has(t)?t:null}function _(o,t=null){const e={};if(!o||typeof o!="object"||Array.isArray(o))return e;const n=Ct(t);for(const[i,s]of Object.entries(o)){const a=h(i),r=String(a);if(a===null||n&&!n.has(r)||!Array.isArray(s))continue;const c=[],p=new Set;for(const lt of s){const E=I(lt);!E||p.has(E)||(c.push(E),p.add(E))}c.length>0&&(e[r]=c)}return e}function Ct(o){if(!o)return null;const t=new Set;for(const e of o){const n=h(e);n!==null&&t.add(String(n))}return t}function F(o){return P.find(t=>t.value===o)}function J(o,t){var n;const e=h(t);return e===null?[]:((n=o==null?void 0:o.positionsByChampionId)==null?void 0:n[String(e)])||[]}function wt(o,t,e){const n=J(o,t);if(n.length===0)return!0;const i=I(e);return i!==null&&n.includes(i)}const N=new Set;function St(o,t){return Object.prototype.hasOwnProperty.call(o,t)}function A(o,t){return St(o,t)}function M(){if(!globalThis.DataStore)throw new Error("DataStore is not available");return globalThis.DataStore}function bt(o){return o!==null&&typeof o=="object"&&!Array.isArray(o)}function R(o){if(o!==void 0)return JSON.parse(JSON.stringify(o))}function K(o){const t=mt[o];if(!t)throw new Error(`Unknown auto-champion-select config key: ${o}`);return R(t)}function Q(o,t,e={}){const n=K(o),i=bt(t)?R(t):{},s={...n,...i},a={enabled:s.enabled===!0};return A(n,"force")&&(a.force=s.force===!0),A(n,"champions")&&(a.champions=X(s.champions,e.allowedChampionIds)),A(n,"positionsByChampionId")&&(a.positionsByChampionId=_(s.positionsByChampionId,e.selectedChampionIds||a.champions)),a}function Z(o,t,e={}){const n=t===void 0?K(o):t;return Q(o,n,e)}function C(o,t={}){const n=M().get(o);return Z(o,n,t)}function Et(o,t,e={}){const n=M(),i=Q(o,t,e);return n.set(o,i),i}function yt(o,t){return JSON.stringify(o)===JSON.stringify(t)}function Pt(o,t,e){N.has(o)||(N.add(o),console.warn(`auto-champion-select: Repaired ${o} in DataStore. The stored value used a different schema; plugins like reynbow/auto-champ-lock write this shape. Saved normalized config.`,{storedConfig:t,normalizedConfig:e}))}function tt(o,t={}){const e=M(),n=e.get(o),i=Z(o,n,t);return(n===void 0||!yt(n,i))&&(n!==void 0&&Pt(o,n,i),e.set(o,i)),i}function B(o,t,e={}){const n=C(o,e),i=R(n),s=t(i)||i;return Et(o,s,e)}const d=Object.freeze({readyCheckAccept:"/lol-matchmaking/v1/ready-check/accept",gameflowPhase:"/lol-gameflow/v1/gameflow-phase",wallet:"/lol-inventory/v1/wallet",ownedChampions:"/lol-champions/v1/owned-champions-minimal",championSummary:"/lol-game-data/assets/v1/champion-summary.json",champSelectSession:"/lol-champ-select/v1/session",championIcon(o){return`/lol-game-data/assets/v1/champion-icons/${o}.png`},champSelectAction(o){return`/lol-champ-select/v1/session/actions/${o}`}}),It=1e3;function et(o){let t=null;return function(){return t||(t=Promise.resolve().then(o).finally(()=>{t=null})),t}}function nt(o){const t=[],e=new Set;if(!Array.isArray(o))return t;for(const n of o){if(!n||typeof n!="object")continue;const i=h(n.id),s=typeof n.name=="string"?n.name:"";i===null||!s||e.has(s)||(t.push({...n,id:i,name:s,squarePortraitPath:n.squarePortraitPath||d.championIcon(i)}),e.add(s))}return t.sort((n,i)=>n.name.localeCompare(i.name)),t}async function At(){let o=await f("GET",d.ownedChampions);for(;!o.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),o=await f("GET",d.ownedChampions),await g(It);return nt(await o.json())}async function Ot(){const o=await f("GET",d.championSummary);return nt(await o.json())}const Tt=et(At),kt=et(Ot),$=300,m=Object.freeze({APPLIED:"applied",TRY_NEXT_CHAMPION:"try-next-champion",ABORT_ACTION:"abort-action"});function v(o){return Array.isArray(o)?o.flat():[]}function _t(o){return v(o).filter(t=>t.type==="ban"&&t.completed===!0).map(t=>t.championId)}function z(o){return Array.isArray(o)?o:[]}function O(o){const t=new Set;for(const e of o){const n=h(e);n!==null&&t.add(n)}return t}function G(o){return o.type==="pick"?0:1}function vt(){return{pickConfig:C("controladoPick"),banConfig:C("controladoBan")}}class Lt{constructor(){this.session=null,this.actions=null,this.localPlayerCellId=null,this.teammateIntentChampionIds=new Set,this.pickedChampionIds=new Set,this.bannedChampionIds=new Set,this.localPlayerAssignedPosition=null,this.watchTask=null,this.watchVersion=0,this.mounted=!1}mount(){this.mounted||(this.mounted=!0,this.watchVersion+=1,this.watchTask||(this.watchTask=this.watch()))}unmount(){this.mounted&&(this.mounted=!1,this.watchVersion+=1)}async watch(){try{for(;this.mounted;){const t=this.watchVersion;let e=!1;try{await this.refreshSessionState(),e=!0}catch(n){console.debug("auto-champion-select: Failed to update champion select",n)}if(!e||!this.mounted||t!==this.watchVersion){this.mounted&&t===this.watchVersion&&await g($);continue}try{await this.runAutoSelectCycle()}catch(n){console.debug("auto-champion-select: Failed to run champion select cycle",n)}this.mounted&&t===this.watchVersion&&await g($)}}finally{this.watchTask=null}}async refreshSessionState(){var s,a;const t=await f("GET",d.champSelectSession);if(!t.ok)throw new Error(`Session request failed with status ${t.status}`);this.session=await t.json(),this.actions=this.session.actions,this.localPlayerCellId=this.session.localPlayerCellId;const e=z(this.session.myTeam),n=z(this.session.theirTeam),i=e.find(r=>r.cellId===this.localPlayerCellId);this.localPlayerAssignedPosition=I(i==null?void 0:i.assignedPosition),this.pickedChampionIds=O([...e,...n].map(r=>r.championId)),this.bannedChampionIds=O([...((s=this.session.bans)==null?void 0:s.myTeamBans)||[],...((a=this.session.bans)==null?void 0:a.theirTeamBans)||[],..._t(this.actions)]),this.teammateIntentChampionIds=O(e.map(r=>r.championPickIntent))}async runAutoSelectCycle(){const{pickConfig:t,banConfig:e}=vt();if(!t.enabled&&!e.enabled)return;const n=this.getLocalPlayerActions();if(n.length===0){console.debug("auto-champion-select: No local player sub actions found, skipping..."),this.unmount();return}for(const i of n){if(!this.isActionAvailable(i))continue;const s=this.getConfigForActionType(i.type,{pickConfig:t,banConfig:e});if(s!=null&&s.enabled)for(const a of s.champions){const r=await this.attemptChampionForAction(i,a,s);if(r===m.APPLIED)break;if(r===m.ABORT_ACTION)return}}}getLocalPlayerActions(){return v(this.actions).filter(t=>this.isPendingLocalPlayerAction(t)).sort((t,e)=>G(t)-G(e))}isPendingLocalPlayerAction(t){return t.actorCellId===this.localPlayerCellId&&t.completed===!1}isActionAvailable(t){return t.type==="pick"||t.isInProgress===!0}getConfigForActionType(t,e){return t==="pick"?e.pickConfig:t==="ban"?e.banConfig:null}async attemptChampionForAction(t,e,n){const i=h(e);if(i===null||this.isChampionUnavailableForAction(t,i,n))return m.TRY_NEXT_CHAMPION;if(console.debug(`auto-champion-select: Trying to ${t.type} ${i}...`),(await this.selectChampion(t.id,i)).ok)return m.APPLIED;console.debug(`auto-champion-select: Failed to ${t.type} ${i}, refreshing champ select state...`);const a=await this.refreshActionAfterFailedAttempt(t);return!a||!this.isActionAvailable(a)||!this.isChampionUnavailableForAction(a,i,n)?m.ABORT_ACTION:(console.debug(`auto-champion-select: ${i} is unavailable after refresh, trying next ${t.type}...`),m.TRY_NEXT_CHAMPION)}async refreshActionAfterFailedAttempt(t){try{await this.refreshSessionState()}catch(e){return console.debug("auto-champion-select: Failed to refresh champion select after select failure",e),null}return v(this.actions).find(e=>e.id===t.id&&e.actorCellId===t.actorCellId&&e.type===t.type&&e.completed===!1)||null}isChampionUnavailableForAction(t,e,n){if(t.type==="pick"&&!wt(n,e,this.localPlayerAssignedPosition)){const i=J(n,e);return this.localPlayerAssignedPosition?console.debug(`auto-champion-select: Picking ${e} but assigned position ${this.localPlayerAssignedPosition} is not in ${i.join(", ")}, skipping...`):console.debug(`auto-champion-select: Picking ${e} but no assigned position is available for ${i.join(", ")} restriction, skipping...`),!0}if(this.bannedChampionIds.has(e))return console.debug(`auto-champion-select: Banning ${e} but it's already banned, skipping...`),!0;if(t.type==="ban"&&this.teammateIntentChampionIds.has(e))if(n.force===!0)console.debug(`auto-champion-select: Banning ${e} but it's already picked, forcing...`);else return console.debug(`auto-champion-select: Banning ${e} but it's already picked, skipping...`),!0;if(t.type==="pick"&&this.pickedChampionIds.has(e))if(n.force===!0)console.debug(`auto-champion-select: Picking ${e} but it's already picked, forcing...`);else return console.debug(`auto-champion-select: Picking ${e} but it's already picked, skipping...`),!0;return!1}selectChampion(t,e){const n=d.champSelectAction(t);return f("PATCH",n,{body:{championId:e,completed:!0}})}}const u=Object.freeze({dropdown:"lol-uikit-framed-dropdown",dropdownOption:"lol-uikit-dropdown-option",radioInputOption:"lol-uikit-radio-input-option",scrollable:"lol-uikit-scrollable",socialRosterGroup:"lol-social-roster-group"}),l=Object.freeze({socialRoster:".lol-social-roster",champSelectButtons:".bottom-right-buttons",firstChampSelectSquareButton:"lol-social-chat-toggle-button, .missions-tracker-button-component, .champ-select-voice-button-wrapper",dropdownCurrent:".ui-dropdown-current",dropdownOption:u.dropdownOption,dropdownOptionSelected:`${u.dropdownOption}[selected]`,dropdownOptionsContainer:".ui-dropdown-options-container",dropdownScrollable:u.scrollable,socialRosterGroupArrow:".arrow",socialRosterGroupHeader:".group-header",socialRosterGroupLabel:"span"});function q(){return document.querySelector(l.socialRoster)}function L(){return document.querySelector(l.champSelectButtons)}const Mt=50,Rt=100,U="controlado-placeholder",W="controlado-search",ot="controlado-filter-icon",w="controlado-filter-icon--trash",it="controlado-filter-input",st="controlado-tag",at="controlado-tag--search",Bt=`
10
+ import{request as f,sleep as g,linkEndpoint as x}from"https://cdn.jsdelivr.net/npm/balaclava-utils@latest";const dt="1.8.1",ht={enabled:!1},ut={enabled:!1,force:!1,champions:[432,235],positionsByChampionId:{235:["BOTTOM","UTILITY"],432:["UTILITY"]}},pt={enabled:!1,force:!1,champions:[157,777,238,38]},mt={controladoAutoAccept:ht,controladoPick:ut,controladoBan:pt};function d(o){const t=Number(o);return Number.isSafeInteger(t)&&t>0?t:null}function X(o,t=null){const e=[],n=new Set,i=ft(t);if(!Array.isArray(o))return e;for(const s of o){const a=d(s);a===null||n.has(a)||i&&!i.has(a)||(e.push(a),n.add(a))}return e}function ft(o){return o?new Set(Array.from(o,d).filter(t=>t!==null)):null}const P=[{value:"TOP",label:"Top",iconPath:"/fe/lol-parties/icon-position-top.png"},{value:"JUNGLE",label:"Jungle",iconPath:"/fe/lol-parties/icon-position-jungle.png"},{value:"MIDDLE",label:"Mid",iconPath:"/fe/lol-parties/icon-position-middle.png"},{value:"BOTTOM",label:"ADC",iconPath:"/fe/lol-parties/icon-position-bottom.png"},{value:"UTILITY",label:"Support",iconPath:"/fe/lol-parties/icon-position-utility.png"}],gt=new Set(P.map(o=>o.value));function I(o){const t=String(o??"").toUpperCase();return gt.has(t)?t:null}function _(o,t=null){const e={};if(!o||typeof o!="object"||Array.isArray(o))return e;const n=Ct(t);for(const[i,s]of Object.entries(o)){const a=d(i),r=String(a);if(a===null||n&&!n.has(r)||!Array.isArray(s))continue;const c=[],p=new Set;for(const lt of s){const y=I(lt);!y||p.has(y)||(c.push(y),p.add(y))}c.length>0&&(e[r]=c)}return e}function Ct(o){if(!o)return null;const t=new Set;for(const e of o){const n=d(e);n!==null&&t.add(String(n))}return t}function F(o){return P.find(t=>t.value===o)}function J(o,t){var n;const e=d(t);return e===null?[]:((n=o==null?void 0:o.positionsByChampionId)==null?void 0:n[String(e)])||[]}function wt(o,t,e){const n=J(o,t);if(n.length===0)return!0;const i=I(e);return i!==null&&n.includes(i)}const N=new Set;function bt(o,t){return Object.prototype.hasOwnProperty.call(o,t)}function A(o,t){return bt(o,t)}function M(){if(!globalThis.DataStore)throw new Error("DataStore is not available");return globalThis.DataStore}function St(o){return o!==null&&typeof o=="object"&&!Array.isArray(o)}function R(o){if(o!==void 0)return JSON.parse(JSON.stringify(o))}function K(o){const t=mt[o];if(!t)throw new Error(`Unknown auto-champion-select config key: ${o}`);return R(t)}function Q(o,t,e={}){const n=K(o),i=St(t)?R(t):{},s={...n,...i},a={enabled:s.enabled===!0};return A(n,"force")&&(a.force=s.force===!0),A(n,"champions")&&(a.champions=X(s.champions,e.allowedChampionIds)),A(n,"positionsByChampionId")&&(a.positionsByChampionId=_(s.positionsByChampionId,e.selectedChampionIds||a.champions)),a}function Z(o,t,e={}){const n=t===void 0?K(o):t;return Q(o,n,e)}function C(o,t={}){const n=M().get(o);return Z(o,n,t)}function yt(o,t,e={}){const n=M(),i=Q(o,t,e);return n.set(o,i),i}function Et(o,t){return JSON.stringify(o)===JSON.stringify(t)}function Pt(o,t,e){N.has(o)||(N.add(o),console.warn(`auto-champion-select: Repaired ${o} in DataStore. The stored value used a different schema; plugins like reynbow/auto-champ-lock write this shape. Saved normalized config.`,{storedConfig:t,normalizedConfig:e}))}function tt(o,t={}){const e=M(),n=e.get(o),i=Z(o,n,t);return(n===void 0||!Et(n,i))&&(n!==void 0&&Pt(o,n,i),e.set(o,i)),i}function B(o,t,e={}){const n=C(o,e),i=R(n),s=t(i)||i;return yt(o,s,e)}const h=Object.freeze({readyCheckAccept:"/lol-matchmaking/v1/ready-check/accept",gameflowPhase:"/lol-gameflow/v1/gameflow-phase",wallet:"/lol-inventory/v1/wallet",ownedChampions:"/lol-champions/v1/owned-champions-minimal",championSummary:"/lol-game-data/assets/v1/champion-summary.json",champSelectSession:"/lol-champ-select/v1/session",championIcon(o){return`/lol-game-data/assets/v1/champion-icons/${o}.png`},champSelectAction(o){return`/lol-champ-select/v1/session/actions/${o}`}}),It=1e3;function et(o){let t=null;return function(){return t||(t=Promise.resolve().then(o).finally(()=>{t=null})),t}}function nt(o){const t=[],e=new Set;if(!Array.isArray(o))return t;for(const n of o){if(!n||typeof n!="object")continue;const i=d(n.id),s=typeof n.name=="string"?n.name:"";i===null||!s||e.has(s)||(t.push({...n,id:i,name:s,squarePortraitPath:n.squarePortraitPath||h.championIcon(i)}),e.add(s))}return t.sort((n,i)=>n.name.localeCompare(i.name)),t}async function At(){let o=await f("GET",h.ownedChampions);for(;!o.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),o=await f("GET",h.ownedChampions),await g(It);return nt(await o.json())}async function Ot(){const o=await f("GET",h.championSummary);return nt(await o.json())}const Tt=et(At),kt=et(Ot),$=300,m=Object.freeze({APPLIED:"applied",TRY_NEXT_CHAMPION:"try-next-champion",ABORT_ACTION:"abort-action"});function L(o){return Array.isArray(o)?o.flat():[]}function _t(o){return L(o).filter(t=>t.type==="ban"&&t.completed===!0).map(t=>t.championId)}function z(o){return Array.isArray(o)?o:[]}function O(o){const t=new Set;for(const e of o){const n=d(e);n!==null&&t.add(n)}return t}function G(o){return o.type==="pick"?0:1}function Lt(){return{pickConfig:C("controladoPick"),banConfig:C("controladoBan")}}class vt{constructor(){this.session=null,this.actions=null,this.localPlayerCellId=null,this.teammateIntentChampionIds=new Set,this.pickedChampionIds=new Set,this.bannedChampionIds=new Set,this.localPlayerAssignedPosition=null,this.watchTask=null,this.watchVersion=0,this.mounted=!1}mount(){this.mounted||(this.mounted=!0,this.watchVersion+=1,this.watchTask||(this.watchTask=this.watch()))}unmount(){this.mounted&&(this.mounted=!1,this.watchVersion+=1)}async watch(){try{for(;this.mounted;){const t=this.watchVersion;let e=!1;try{await this.refreshSessionState(),e=!0}catch(n){console.debug("auto-champion-select: Failed to update champion select",n)}if(!e||!this.mounted||t!==this.watchVersion){this.mounted&&t===this.watchVersion&&await g($);continue}try{await this.runAutoSelectCycle()}catch(n){console.debug("auto-champion-select: Failed to run champion select cycle",n)}this.mounted&&t===this.watchVersion&&await g($)}}finally{this.watchTask=null}}async refreshSessionState(){var s,a;const t=await f("GET",h.champSelectSession);if(!t.ok)throw new Error(`Session request failed with status ${t.status}`);this.session=await t.json(),this.actions=this.session.actions,this.localPlayerCellId=this.session.localPlayerCellId;const e=z(this.session.myTeam),n=z(this.session.theirTeam),i=e.find(r=>r.cellId===this.localPlayerCellId);this.localPlayerAssignedPosition=I(i==null?void 0:i.assignedPosition),this.pickedChampionIds=O([...e,...n].map(r=>r.championId)),this.bannedChampionIds=O([...((s=this.session.bans)==null?void 0:s.myTeamBans)||[],...((a=this.session.bans)==null?void 0:a.theirTeamBans)||[],..._t(this.actions)]),this.teammateIntentChampionIds=O(e.map(r=>r.championPickIntent))}async runAutoSelectCycle(){const{pickConfig:t,banConfig:e}=Lt();if(!t.enabled&&!e.enabled)return;const n=this.getLocalPlayerActions();if(n.length===0){console.debug("auto-champion-select: No local player sub actions found, skipping..."),this.unmount();return}for(const i of n){if(!this.isActionAvailable(i))continue;const s=this.getConfigForActionType(i.type,{pickConfig:t,banConfig:e});if(s!=null&&s.enabled)for(const a of s.champions){const r=await this.attemptChampionForAction(i,a,s);if(r===m.APPLIED)break;if(r===m.ABORT_ACTION)return}}}getLocalPlayerActions(){return L(this.actions).filter(t=>this.isPendingLocalPlayerAction(t)).sort((t,e)=>G(t)-G(e))}isPendingLocalPlayerAction(t){return t.actorCellId===this.localPlayerCellId&&t.completed===!1}isActionAvailable(t){return t.type==="pick"||t.isInProgress===!0}getConfigForActionType(t,e){return t==="pick"?e.pickConfig:t==="ban"?e.banConfig:null}async attemptChampionForAction(t,e,n){const i=d(e);if(i===null||this.isChampionUnavailableForAction(t,i,n))return m.TRY_NEXT_CHAMPION;if(console.debug(`auto-champion-select: Trying to ${t.type} ${i}...`),(await this.selectChampion(t.id,i)).ok)return m.APPLIED;console.debug(`auto-champion-select: Failed to ${t.type} ${i}, refreshing champ select state...`);const a=await this.refreshActionAfterFailedAttempt(t);return!a||!this.isActionAvailable(a)||!this.isChampionUnavailableForAction(a,i,n)?m.ABORT_ACTION:(console.debug(`auto-champion-select: ${i} is unavailable after refresh, trying next ${t.type}...`),m.TRY_NEXT_CHAMPION)}async refreshActionAfterFailedAttempt(t){try{await this.refreshSessionState()}catch(e){return console.debug("auto-champion-select: Failed to refresh champion select after select failure",e),null}return L(this.actions).find(e=>e.id===t.id&&e.actorCellId===t.actorCellId&&e.type===t.type&&e.completed===!1)||null}isChampionUnavailableForAction(t,e,n){if(t.type==="pick"&&!wt(n,e,this.localPlayerAssignedPosition)){const i=J(n,e);return this.localPlayerAssignedPosition?console.debug(`auto-champion-select: Picking ${e} but assigned position ${this.localPlayerAssignedPosition} is not in ${i.join(", ")}, skipping...`):console.debug(`auto-champion-select: Picking ${e} but no assigned position is available for ${i.join(", ")} restriction, skipping...`),!0}if(this.bannedChampionIds.has(e))return console.debug(`auto-champion-select: Banning ${e} but it's already banned, skipping...`),!0;if(t.type==="ban"&&this.teammateIntentChampionIds.has(e))if(n.force===!0)console.debug(`auto-champion-select: Banning ${e} but it's already picked, forcing...`);else return console.debug(`auto-champion-select: Banning ${e} but it's already picked, skipping...`),!0;if(t.type==="pick"&&this.pickedChampionIds.has(e))if(n.force===!0)console.debug(`auto-champion-select: Picking ${e} but it's already picked, forcing...`);else return console.debug(`auto-champion-select: Picking ${e} but it's already picked, skipping...`),!0;return!1}selectChampion(t,e){const n=h.champSelectAction(t);return f("PATCH",n,{body:{championId:e,completed:!0}})}}const u=Object.freeze({dropdown:"lol-uikit-framed-dropdown",dropdownOption:"lol-uikit-dropdown-option",radioInputOption:"lol-uikit-radio-input-option",scrollable:"lol-uikit-scrollable",socialRosterGroup:"lol-social-roster-group"}),l=Object.freeze({socialRoster:".lol-social-roster",champSelectButtons:".bottom-right-buttons",firstChampSelectSquareButton:"lol-social-chat-toggle-button, .missions-tracker-button-component, .champ-select-voice-button-wrapper",dropdownCurrent:".ui-dropdown-current",dropdownOption:u.dropdownOption,dropdownOptionSelected:`${u.dropdownOption}[selected]`,dropdownOptionsContainer:".ui-dropdown-options-container",dropdownScrollable:u.scrollable,socialRosterGroupArrow:".arrow",socialRosterGroupHeader:".group-header",socialRosterGroupLabel:"span"});function q(){return document.querySelector(l.socialRoster)}function v(){return document.querySelector(l.champSelectButtons)}const Mt=50,Rt=100,U="controlado-placeholder",W="controlado-search",ot="controlado-filter-icon",w="controlado-filter-icon--trash",it="controlado-filter-input",st="controlado-tag",at="controlado-tag--search",Bt=`
11
11
  ${l.dropdownCurrent} {
12
12
  display: flex;
13
13
  justify-content: space-between;
@@ -81,4 +81,4 @@ import{request as f,sleep as g,linkEndpoint as x}from"https://cdn.jsdelivr.net/n
81
81
  text-transform: none;
82
82
  font-weight: 500;
83
83
  }
84
- `;function H(o){const t=document.createElement(u.dropdownOption);return t.setAttribute("slot",u.dropdownOption),t.innerText=o,t}class Dt{constructor(t,e,n){this.dropdownElement=t,this.placeholderText=e,this.onChampionSelected=n,this.placeholderOption=null}renderOptions(t){this.dropdownElement.replaceChildren(),this.placeholderOption=H(this.placeholderText),this.placeholderOption.setAttribute("selected","true"),this.dropdownElement.appendChild(this.placeholderOption);for(const e of t){const n=this.createChampionOption(e);this.dropdownElement.appendChild(n)}}createChampionOption(t){const e=H(t.name);return e.addEventListener("click",()=>{this.onChampionSelected(t.id),requestAnimationFrame(()=>this.reset())}),e}async waitForRender(){for(let t=0;t<Mt;t++){const e=this.dropdownElement.shadowRoot;if(this.dropdownElement.isConnected&&(e!=null&&e.querySelector(l.dropdownCurrent)))return e;await g(Rt)}return null}ensureSearchPlaceholder(t){if(t.querySelector(`#${U}`))return;const e=t.querySelector(l.dropdownCurrent);e&&e.appendChild(this.createSearchPlaceholder())}createSearchPlaceholder(){const t=document.createElement("div");t.classList.add(st,at),t.id=U;const e=document.createElement("input");e.classList.add(it),e.id=W,e.type="text",e.placeholder="Search";const n=document.createElement("span");return n.classList.add(ot),n.addEventListener("click",()=>{n.classList.contains(w)&&this.clearSearch(e,n)}),e.addEventListener("input",i=>{this.ensureOpen(),this.filterOptions(i.target.value),n.classList.toggle(w,!!i.target.value)}),["pointerdown","click"].forEach(i=>{t.addEventListener(i,s=>s.stopPropagation()),n.addEventListener(i,s=>s.stopPropagation())}),["pointerdown","focusin"].forEach(i=>{e.addEventListener(i,s=>s.stopPropagation(),!0)}),t.appendChild(n),t.appendChild(e),t}clearSearch(t,e){t.value="",this.filterOptions(""),e.classList.toggle(w,!1)}filterOptions(t){const e=t.toLowerCase();this.dropdownElement.querySelectorAll(l.dropdownOption).forEach(i=>{(i.textContent??"").toLowerCase().includes(e)?i.style.display="":i.style.display="none"})}reset(){var t;this.dropdownElement.querySelectorAll(l.dropdownOptionSelected).forEach(e=>{e.removeAttribute("selected")}),(t=this.placeholderOption)==null||t.setAttribute("selected","true"),this.withShadowRoot(e=>{var s;const n=e.querySelector(`#${W}`),i=e.querySelector(`.${w}`);n&&i?this.clearSearch(n,i):(n&&(n.value="",this.filterOptions("")),i&&i.classList.remove(w)),this.isOpen()&&((s=e.querySelector(l.dropdownCurrent))==null||s.click())})}isOpen(){return this.dropdownElement.classList.contains("active")}ensureOpen(){this.isOpen()||this.withShadowRoot(t=>{const e=t.querySelector(l.dropdownCurrent);e&&e.click()})}patchDropdownShadowDom(){this.withShadowRoot(t=>{this.injectDropdownSearchStyles(t)})}injectDropdownSearchStyles(t){if(t.querySelector("style[data-controlado='dropdown-tags']"))return;const e=document.createElement("style");e.dataset.controlado="dropdown-tags",e.textContent=Bt,t.appendChild(e)}withShadowRoot(t){const e=this.dropdownElement.shadowRoot;e&&t(e)}}const xt=".champion-priority-selector__position-badge",Ft=".champion-priority-selector__position-option",Nt=".champion-priority-selector__remove",y=8,$t=5,zt=150,Gt="cubic-bezier(0.2, 0, 0, 1)";class Y{constructor(t,e,n,i={}){this.element=this.createRootElement(),this.dropdownElement=this.createDropdownElement(),this.championDropdown=new Dt(this.dropdownElement,t,r=>this.addChampion(r));const{scrollElement:s,trackElement:a}=this.createSelectedChampionsScroll();this.scrollElement=s,this.trackElement=a,this.enablePositionRestrictions=i.enablePositionRestrictions===!0,this.positionMenuElement=this.enablePositionRestrictions?this.createPositionMenu():null,this.positionMenuChampionId=null,this.positionsByChampionId={},this.emptyElement=this.createEmptyState(t),this.element.append(this.dropdownElement,this.scrollElement),this.positionMenuElement&&this.element.appendChild(this.positionMenuElement),this.config=null,this.configKey=e,this.loadChampions=n,this.champions=[],this.championById=new Map,this.selectedChampionIds=[],this.iconButtons=new Map,this.dragState=null,this.handleWindowPointerMove=r=>this.moveDrag(r),this.handleWindowPointerUp=r=>this.finishDrag(r),this.handleWindowPointerCancel=r=>this.cancelDrag(r),this.handlePositionMenuOutsidePointerDown=r=>this.closePositionMenuOnOutsidePointerDown(r),this.handlePositionMenuKeyDown=r=>this.closePositionMenuOnKeyDown(r),this.setupInFlight=null,this.setupPending=!1}createRootElement(){const t=document.createElement("div");return t.classList.add("champion-priority-selector"),t}createDropdownElement(){const t=document.createElement(u.dropdown);return t.classList.add("dropdown-champions-default","dropdown-drop-up"),t}createSelectedChampionsScroll(){const t=document.createElement(u.scrollable);t.classList.add("champion-priority-selector__scroll"),t.setAttribute("direction","horizontal"),t.setAttribute("overflow-masks","disabled"),t.setAttribute("side-scroll-wheel","true");const e=document.createElement("div");return e.classList.add("champion-priority-selector__track"),t.appendChild(e),{scrollElement:t,trackElement:e}}createEmptyState(t){const e=document.createElement("div");e.classList.add("champion-priority-selector__empty");const n=document.createElement("span");n.innerText="No champions";const i=document.createElement("span"),s=t.replace(/^Add\s+/i,"").toLowerCase();return i.innerText=`Use dropdown to add ${s} option`,e.append(n,i),e}createPositionMenu(){const t=document.createElement("div");t.classList.add("champion-priority-selector__position-menu"),t.hidden=!0;for(const e of P)t.appendChild(this.createPositionOption(e));return t}createPositionOption(t){const e=document.createElement("button");e.classList.add("champion-priority-selector__position-option"),e.type="button",e.dataset.position=t.value,e.title=t.label,e.setAttribute("aria-label",t.label),e.setAttribute("aria-pressed","false"),e.addEventListener("pointerdown",i=>i.stopPropagation()),e.addEventListener("click",i=>{i.stopPropagation(),this.toggleChampionPosition(t.value)});const n=document.createElement("img");return n.src=t.iconPath,n.alt=t.label,n.draggable=!1,e.appendChild(n),e}async setup(){return this.setupPending=!0,this.setupInFlight||(this.setupInFlight=this.runSetupLoop()),this.setupInFlight}refresh(){return this.setup()}async runSetupLoop(){try{for(;this.setupPending;)this.setupPending=!1,await this.performSetup()}finally{this.setupInFlight=null}}async performSetup(){this.champions=await this.loadChampions(),this.championById=new Map(this.champions.map(n=>[n.id,n]));const t=this.getAllowedChampionIds();this.config=tt(this.configKey,{allowedChampionIds:t}),this.selectedChampionIds=X(this.config.champions,t),this.enablePositionRestrictions&&(this.positionsByChampionId=_(this.config.positionsByChampionId,this.selectedChampionIds)),this.championDropdown.renderOptions(this.champions),this.renderSelectedChampions();const e=await this.championDropdown.waitForRender();e&&(this.championDropdown.ensureSearchPlaceholder(e),this.championDropdown.patchDropdownShadowDom())}getAllowedChampionIds(){return new Set(this.championById.keys())}addChampion(t){const e=h(t);e===null||!this.championById.has(e)||this.selectedChampionIds.includes(e)||(this.selectedChampionIds.push(e),this.renderSelectedChampions(),this.saveConfig())}removeChampion(t){const e=h(t),n=this.selectedChampionIds.indexOf(e);e===null||n===-1||(this.selectedChampionIds.splice(n,1),this.positionMenuChampionId===e&&this.closePositionMenu(),this.enablePositionRestrictions&&delete this.positionsByChampionId[String(e)],this.renderSelectedChampions(),this.saveConfig())}moveChampionToIndex(t,e){const n=h(t),i=this.selectedChampionIds.indexOf(n);if(n===null||i===-1)return!1;const[s]=this.selectedChampionIds.splice(i,1),a=Math.max(0,Math.min(e,this.selectedChampionIds.length));return this.selectedChampionIds.splice(a,0,s),i!==a}syncPositionsByChampionId(){this.enablePositionRestrictions&&(this.positionsByChampionId=_(this.positionsByChampionId,this.selectedChampionIds))}saveConfig(){this.syncPositionsByChampionId();const t=this.getAllowedChampionIds();this.config=B(this.configKey,e=>(e.champions=[...this.selectedChampionIds],this.enablePositionRestrictions&&(e.positionsByChampionId={...this.positionsByChampionId}),e),{allowedChampionIds:t,selectedChampionIds:this.selectedChampionIds}),this.enablePositionRestrictions&&(this.positionsByChampionId=this.config.positionsByChampionId||{}),console.debug(this.configKey,this.config)}renderSelectedChampions(t=null,e=null){this.positionMenuChampionId!==null&&this.closePositionMenu();const n=new Set(this.selectedChampionIds);for(const[s,a]of this.iconButtons)n.has(s)||(a.remove(),this.iconButtons.delete(s));if(this.selectedChampionIds.length===0){this.trackElement.replaceChildren(this.emptyElement);return}this.emptyElement.remove();const i=this.selectedChampionIds.map((s,a)=>this.getIconButton(s,a)).filter(Boolean);this.trackElement.append(...i),t&&this.animateReorder(t,e)}getIconButton(t,e){const n=this.championById.get(t);if(!n)return null;let i=this.iconButtons.get(t);i||(i=this.createIconButton(n),this.iconButtons.set(t,i)),i.dataset.rank=String(e+1);const s=this.getChampionPositionTitleSuffix(t);i.title=`${e+1}. ${n.name}${s}`,i.setAttribute("aria-label",`${e+1}. ${n.name}${s}`);const a=i.querySelector("img");a.src=n.squarePortraitPath,a.alt=n.name;const r=i.querySelector(Nt);return r.setAttribute("aria-label",`Remove ${n.name}`),r.title=`Remove ${n.name}`,this.renderPositionBadge(i,t),i}createIconButton(t){const e=document.createElement("div");e.classList.add("champion-priority-selector__icon"),e.setAttribute("role","button"),e.tabIndex=0;const n=document.createElement("img");n.draggable=!1;const i=document.createElement("button");return i.classList.add("champion-priority-selector__remove"),i.type="button",i.innerText="x",i.addEventListener("pointerdown",s=>s.stopPropagation()),i.addEventListener("click",s=>{s.stopPropagation(),this.removeChampion(t.id)}),e.addEventListener("pointerdown",s=>this.startDrag(s,t.id)),this.enablePositionRestrictions&&e.addEventListener("contextmenu",s=>this.openPositionMenu(s,t.id)),e.append(n,i),e}getChampionAllowedPositions(t){const e=h(t);return e===null?[]:this.positionsByChampionId[String(e)]||[]}getChampionAllowedPositionLabels(t){return this.getChampionAllowedPositions(t).map(e=>{var n;return(n=F(e))==null?void 0:n.label}).filter(Boolean)}getChampionPositionTitleSuffix(t){const e=this.getChampionAllowedPositionLabels(t);return e.length>0?` (${e.join(", ")})`:""}renderPositionBadge(t,e){var r;if((r=t.querySelector(xt))==null||r.remove(),!this.enablePositionRestrictions)return;const n=this.getChampionAllowedPositions(e);if(n.length===0)return;const i=F(n[0]);if(!i)return;const s=document.createElement("span");s.classList.add("champion-priority-selector__position-badge"),s.title=this.getChampionAllowedPositionLabels(e).join(", "),n.length>1&&(s.dataset.count=String(n.length));const a=document.createElement("img");a.src=i.iconPath,a.alt=i.label,a.draggable=!1,s.appendChild(a),t.appendChild(s)}openPositionMenu(t,e){if(!this.enablePositionRestrictions||!this.positionMenuElement)return;const n=h(e);if(n===null||!this.selectedChampionIds.includes(n))return;t.preventDefault(),t.stopPropagation(),this.positionMenuChampionId=n,this.renderPositionMenu(),this.positionMenuElement.hidden=!1,this.positionMenuElement.style.left="0px",this.positionMenuElement.style.top="0px";const{left:i,top:s}=this.getPositionMenuCoordinates(t);this.positionMenuElement.style.left=`${i}px`,this.positionMenuElement.style.top=`${s}px`,document.addEventListener("pointerdown",this.handlePositionMenuOutsidePointerDown,!0),document.addEventListener("keydown",this.handlePositionMenuKeyDown,!0)}getPositionMenuCoordinates(t){const e=this.positionMenuElement.getBoundingClientRect(),n=Math.min(Math.max(t.clientX,y),window.innerWidth-e.width-y),i=Math.min(Math.max(t.clientY,y),window.innerHeight-e.height-y);return{left:n,top:i}}renderPositionMenu(){if(!this.positionMenuElement||this.positionMenuChampionId===null)return;const t=new Set(this.getChampionAllowedPositions(this.positionMenuChampionId));this.positionMenuElement.querySelectorAll(Ft).forEach(e=>{const n=t.has(e.dataset.position);e.classList.toggle("champion-priority-selector__position-option--selected",n),e.setAttribute("aria-pressed",String(n))})}toggleChampionPosition(t){if(!this.enablePositionRestrictions||this.positionMenuChampionId===null)return;const e=I(t);if(!e)return;const n=String(this.positionMenuChampionId),i=new Set(this.positionsByChampionId[n]||[]);i.has(e)?i.delete(e):i.add(e);const s=P.map(c=>c.value).filter(c=>i.has(c));s.length>0?this.positionsByChampionId[n]=s:delete this.positionsByChampionId[n],this.renderPositionMenu();const a=this.iconButtons.get(this.positionMenuChampionId),r=this.selectedChampionIds.indexOf(this.positionMenuChampionId);a&&r!==-1&&this.getIconButton(this.positionMenuChampionId,r),this.saveConfig()}closePositionMenuOnOutsidePointerDown(t){var e;(e=this.positionMenuElement)!=null&&e.contains(t.target)||this.closePositionMenu()}closePositionMenuOnKeyDown(t){t.key==="Escape"&&this.closePositionMenu()}closePositionMenu(){this.positionMenuElement&&(this.positionMenuElement.hidden=!0,this.positionMenuChampionId=null,document.removeEventListener("pointerdown",this.handlePositionMenuOutsidePointerDown,!0),document.removeEventListener("keydown",this.handlePositionMenuKeyDown,!0))}startDrag(t,e){var i;if(t.button!==0)return;this.dragState&&this.clearDragState();const n=this.iconButtons.get(e);if(n){this.dragState={championId:e,pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,active:!1,moved:!1};try{(i=n.setPointerCapture)==null||i.call(n,t.pointerId)}catch{}window.addEventListener("pointermove",this.handleWindowPointerMove),window.addEventListener("pointerup",this.handleWindowPointerUp),window.addEventListener("pointercancel",this.handleWindowPointerCancel)}}moveDrag(t){var p;if(!this.dragState||this.dragState.pointerId!==t.pointerId)return;const e=this.dragState.championId,n=t.clientX-this.dragState.startX,i=t.clientY-this.dragState.startY,s=Math.hypot(n,i);if(!this.dragState.active){if(s<$t)return;this.dragState.active=!0,(p=this.iconButtons.get(e))==null||p.classList.add("champion-priority-selector__icon--dragging")}t.preventDefault();const a=this.getDropIndex(t.clientX,e),r=this.selectedChampionIds.indexOf(e);if(a===r||a===-1)return;const c=this.getIconPositions();this.moveChampionToIndex(e,a)&&(this.dragState.moved=!0,this.renderSelectedChampions(c,e))}finishDrag(t){if(!this.dragState||this.dragState.pointerId!==t.pointerId)return;const e=this.dragState.active,n=this.dragState.moved;this.clearDragState(),e&&n&&this.saveConfig()}cancelDrag(t){!this.dragState||this.dragState.pointerId!==t.pointerId||this.clearDragState()}clearDragState(){var i;if(!this.dragState)return;const{championId:t,pointerId:e}=this.dragState,n=this.iconButtons.get(t);n==null||n.classList.remove("champion-priority-selector__icon--dragging");try{(i=n==null?void 0:n.releasePointerCapture)==null||i.call(n,e)}catch{}window.removeEventListener("pointermove",this.handleWindowPointerMove),window.removeEventListener("pointerup",this.handleWindowPointerUp),window.removeEventListener("pointercancel",this.handleWindowPointerCancel),this.dragState=null}getDropIndex(t,e){const n=this.selectedChampionIds.filter(i=>i!==e);for(let i=0;i<n.length;i++){const s=this.iconButtons.get(n[i]);if(!s)continue;const a=s.getBoundingClientRect();if(t<a.left+a.width/2)return i}return n.length}getIconPositions(){const t=new Map;for(const e of this.selectedChampionIds){const n=this.iconButtons.get(e);n&&t.set(e,n.getBoundingClientRect())}return t}animateReorder(t,e){for(const n of this.selectedChampionIds){if(n===e)continue;const i=this.iconButtons.get(n),s=t.get(n);if(!i||!s||typeof i.animate!="function")continue;const a=i.getBoundingClientRect(),r=s.left-a.left,c=s.top-a.top;r===0&&c===0||i.animate([{transform:`translate(${r}px, ${c}px)`},{transform:"translate(0, 0)"}],{duration:zt,easing:Gt})}}}const qt=200,T="auto-select-champ-select-menu--collapsed",Ut="auto-select-champ-select-menu-button-wrapper--open";class k{constructor(t,e){this.element=document.createElement(u.radioInputOption),this.element.classList.add("lol-settings-voice-input-mode-option","auto-select-checkbox"),this.element.innerText=t,this.config=null,this.configKey=e,this.setupComplete=!1}setup(){this.syncFromConfig(),this.setupComplete||(this.element.addEventListener("click",()=>this.toggle()),this.setupComplete=!0)}syncFromConfig(){this.config=tt(this.configKey),this.element.toggleAttribute("selected",this.config.enabled===!0)}toggle(){return console.debug("auto-champion-select: Toggling",this.configKey),this.config=B(this.configKey,t=>(t.enabled=!t.enabled,t)),this.element.toggleAttribute("selected",this.config.enabled===!0),this.config.enabled}}class Wt{constructor(t,e,n){this.element=document.createElement("div"),this.element.classList.add("auto-select-champ-select-menu",T),this.buttonWrapper=document.createElement("div"),this.buttonWrapper.classList.add("auto-select-champ-select-menu-button-wrapper"),this.headerElement=document.createElement("button"),this.headerElement.classList.add("auto-select-champ-select-menu__header"),this.headerElement.type="button",this.headerElement.setAttribute("aria-label",t),this.headerElement.setAttribute("aria-expanded","false"),this.headerElement.addEventListener("click",()=>this.toggle()),this.contentElement=document.createElement("div"),this.contentElement.classList.add("auto-select-champ-select-menu__content"),this.titleElement=document.createElement("div"),this.titleElement.classList.add("auto-select-champ-select-menu__title"),this.titleElement.textContent=t,this.buttonWrapper.append(this.headerElement,this.element),this.contentElement.appendChild(this.titleElement),this.element.appendChild(this.contentElement),this.returnControlsToSocialRoster=e,this.controlElements=n,this.boundCloseOnOutsideInteraction=i=>this.closeOnOutsideInteraction(i),this.buttonObserver=null,this.buttonMountFrame=null,this.buttonMountTask=null,this.hiddenStates=new WeakMap,this.mounted=!1}async mount(){return this.mounted?this.mountButton():(this.mounted=!0,this.controlElements.forEach(t=>{this.hiddenStates.set(t,t.classList.contains("hidden")),t.classList.remove("hidden"),this.contentElement.appendChild(t)}),this.observeButtonContainer(),document.addEventListener("pointerdown",this.boundCloseOnOutsideInteraction,!0),this.mountButton())}unmount(){return this.mounted?(this.mounted=!1,this.stopButtonMounting(),document.removeEventListener("pointerdown",this.boundCloseOnOutsideInteraction,!0),this.setOpen(!1),this.buttonWrapper.remove(),this.restoreHiddenStates(),this.returnControlsToSocialRoster()):this.returnControlsToSocialRoster()}stopButtonMounting(){var t;(t=this.buttonObserver)==null||t.disconnect(),this.buttonObserver=null,this.buttonMountFrame!==null&&(cancelAnimationFrame(this.buttonMountFrame),this.buttonMountFrame=null),this.buttonMountTask=null}restoreHiddenStates(){this.controlElements.forEach(t=>{t.classList.toggle("hidden",this.hiddenStates.get(t)===!0),this.hiddenStates.delete(t)})}isOpen(){return!this.element.classList.contains(T)}setOpen(t){this.element.classList.toggle(T,!t),this.buttonWrapper.classList.toggle(Ut,t),this.headerElement.setAttribute("aria-expanded",String(t))}toggle(){this.setOpen(!this.isOpen())}closeOnOutsideInteraction(t){if(!this.isOpen())return;(typeof t.composedPath=="function"?t.composedPath():[]).includes(this.buttonWrapper)||this.buttonWrapper.contains(t.target)||this.setOpen(!1)}observeButtonContainer(){this.buttonObserver=new MutationObserver(()=>this.scheduleMountButton()),this.buttonObserver.observe(document.body,{childList:!0,subtree:!0})}scheduleMountButton(){this.buttonMountFrame===null&&(this.buttonMountFrame=requestAnimationFrame(()=>{this.buttonMountFrame=null,this.mountButton()}))}mountButton(){return this.buttonMountTask||(this.buttonMountTask=this.appendButtonToContainer().finally(()=>{this.buttonMountTask=null})),this.buttonMountTask}async appendButtonToContainer(){let t=L();for(;this.mounted&&!t;)await g(qt),t=L();if(!this.mounted||!t)return;const e=t.querySelector(l.firstChampSelectSquareButton);this.buttonWrapper.parentNode===t&&this.buttonWrapper.nextSibling===e||t.insertBefore(this.buttonWrapper,e)}}class Ht{constructor(t,...e){this.element=document.createElement(u.socialRosterGroup),this.element.addEventListener("post-render",()=>this.onPostRender()),this.element.addEventListener("click",()=>this.onClick()),this.label=t,this.collapsibleElements=e,this.waitRender()}waitRender(){new MutationObserver((t,e)=>{if(this.element.querySelector(l.socialRosterGroupLabel)){const n=new Event("post-render");this.element.dispatchEvent(n),e.disconnect()}}).observe(this.element,{childList:!0})}onPostRender(){var t;this.element.querySelector(l.socialRosterGroupLabel).innerText=this.label,(t=this.element.querySelector(l.socialRosterGroupHeader))==null||t.removeAttribute("draggable")}onClick(){var t;this.collapsibleElements.forEach(e=>{e.closest(".auto-select-champ-select-menu")||e.classList.toggle("hidden")}),(t=this.element.querySelector(l.socialRosterGroupArrow))==null||t.toggleAttribute("open")}}const b="Balaclava: Auto Champion Select";function Yt(o){return typeof(o==null?void 0:o.then)=="function"}class D{constructor({id:t,name:e,legend:n,tags:i,group:s,callback:a,toasts:r}){this.id=t,this.name=e,this.legend=n,this.tags=i,this.group=s,this.perform=this.perform.bind(this),this.callback=a,this.toasts=r}perform(){try{const t=this.callback();if(Yt(t))return Toast.promise(t,{loading:this.toasts.loading,success:this.toasts.success,error:this.toasts.error});const e=this.toasts.success||(t?this.toasts.on:this.toasts.off);Toast.success(e)}catch(t){Toast.error(this.toasts.error),console.error(t)}}}class rt extends D{constructor(t,e,n){super({id:`${e}Switch`,name:()=>`Auto ${t} [${C(e).enabled?"ON":"OFF"}]`,legend:()=>C(e).enabled?"Turn OFF":"Turn ON",tags:[b,e,"switch"],group:b,callback:n,toasts:{on:`Auto ${t} is ON!`,off:`Auto ${t} is OFF!`,error:`Failed to toggle Auto ${t}. Check console.`}})}}function jt(o){return B(o,e=>(e.force=!e.force,e)).force}class ct extends D{constructor(t,e){super({id:`${e}ForceSwitch`,name:()=>`Force ${t} [${C(e).force?"ON":"OFF"}]`,legend:()=>`Ignore team intent and force ${t} the selected champion`,tags:[b,e,"force","switch"],group:b,callback:()=>jt(e),toasts:{on:`Force ${t} is ON!`,off:`Force ${t} is OFF!`,error:`Failed to toggle Force ${t}. Check console.`}})}}class Vt extends D{constructor(t){super({id:"RefreshDropdowns",name:()=>"Refresh Champions",legend:()=>"Normally champion selectors refresh automatically...",tags:[b,"refresh"],group:b,callback:t,toasts:{success:"Refreshed Champions!",error:"Failed to refresh Champions. Check console."}})}}class Xt extends rt{constructor(t){super("Pick","controladoPick",t)}}class Jt extends rt{constructor(t){super("Ban","controladoBan",t)}}class Kt extends ct{constructor(){super("Pick","controladoPick")}}class Qt extends ct{constructor(){super("Ban","controladoBan")}}function Zt(o){for(const t of o)CommandBar.addAction(t)}const te=2e3,ee=200,ne=6e4,oe=".auto-select-champ-select-menu__header",S=Object.freeze({autoAccept:"controladoAutoAccept",pick:"controladoPick",ban:"controladoBan"});async function ie(){C(S.autoAccept).enabled===!0&&(console.debug("auto-champion-select(auto-accept): Ready check detected, accepting in 2 seconds..."),await g(te),await se())}async function se(){const o=await f("POST",d.readyCheckAccept);o.ok?console.debug("auto-champion-select(auto-accept): Accepted ready check"):console.error("auto-champion-select(auto-accept): Failed to accept ready check",o)}async function ae(o){const t=await f("GET",d.gameflowPhase),e=t.ok?await t.json():null;o.handleGameflowPhase(e)}function re({championSelect:o,champSelectControlsMenu:t,setupChampionSelectors:e}){let n=0;return async function(r){const c=++n;try{await i(r,c)}catch(p){console.error("auto-champion-select: Failed to handle gameflow phase",p)}};async function i(a,r){a==="ReadyCheck"&&ie().catch(c=>console.error("auto-champion-select(auto-accept): Failed to handle ready check",c)),await s(a),r===n&&await e()}async function s(a){a==="ChampSelect"?(o.mount(),await t.mount()):(o.unmount(),await t.unmount())}}function ce(){const o=new Lt,t=new k("Accept",S.autoAccept),e=new k("Pick",S.pick),n=new Y("Add pick",S.pick,Tt,{enablePositionRestrictions:!0}),i=new k("Ban",S.ban),s=new Y("Add ban",S.ban,kt),a=le(n,s),r=he(t,e,i),c=new Ht("Auto champion select",a,r);return{championSelect:o,autoAcceptToggle:t,pickToggle:e,banToggle:i,pickChampionSelector:n,banChampionSelector:s,selectorsContainer:a,checkboxesContainer:r,pluginSection:c,championSelectors:[n,s]}}function le(...o){const t=document.createElement("div");return t.append(...o.map(e=>e.element)),t}function he(...o){const t=document.createElement("div");return t.classList.add("auto-select-checkboxes-div"),t.append(...o.map(e=>e.element)),t}function de({pluginSection:o,checkboxesContainer:t,selectorsContainer:e}){let n=null,i=0,s=()=>!1;async function a(r){let c=q();for(;!c;){if(s()||r!==i)return;await g(ee),c=q()}s()||r!==i||c.append(o.element,t,e)}return{setIsChampSelectControlsMounted(r){s=r},returnControlsToSocialRoster(){if(n)return n;const r=++i;return n=a(r).catch(c=>console.error("auto-champion-select: Failed to return controls to social roster",c)).finally(()=>{n=null}),n}}}function ue({autoAcceptToggle:o,pickToggle:t,banToggle:e}){o.setup(),t.setup(),e.setup()}async function pe(o){await Promise.all(o.map(t=>t.setup()))}async function me(o){await Promise.all(o.map(t=>t.refresh()))}function fe(){const o=ce(),t=de(o),e=new Wt("Auto Champion Select",t.returnControlsToSocialRoster,[o.checkboxesContainer,o.selectorsContainer]);t.setIsChampSelectControlsMounted(()=>e.mounted);const n={...o,champSelectControlsMenu:e,setupToggles:()=>ue(o),setupChampionSelectors:()=>pe(o.championSelectors),refreshChampionSelectors:()=>me(o.championSelectors),refreshPickChampionSelector:async()=>{await o.pickChampionSelector.refresh()}};return n.handleGameflowPhase=re(n),n}function ge(o){x(d.gameflowPhase,t=>{o.handleGameflowPhase(t.data)}),x(d.wallet,async t=>{if(t.eventType==="Update"){console.debug("auto-champion-select(wallet): Refreshing champion selectors...");try{await o.refreshPickChampionSelector()}catch(e){console.error("auto-champion-select(wallet): Failed to refresh champion selectors",e)}}})}function Ce({pickToggle:o,banToggle:t,refreshChampionSelectors:e}){Zt([new Xt(()=>o.toggle()),new Jt(()=>t.toggle()),new Kt,new Qt,new Vt(e)])}function we(o){let t=null,e=null;function n(){e==null||e.disconnect(),e=null,t!==null&&(cancelAnimationFrame(t),t=null)}const i=setTimeout(()=>{n()},ne);function s(){if(!(L()!==null))return;clearTimeout(i),n(),document.querySelector(oe)!==null||o.handleGameflowPhase("ChampSelect")}e=new MutationObserver(()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,s()}))}),e.observe(document.body,{childList:!0,subtree:!0}),s()}async function Se(){const o=fe();o.setupToggles(),Ce(o),ge(o),await ae(o),we(o),console.debug(`auto-champion-select(${ht}): Report bugs to Balaclava#1912`)}let j=!1;function V(){j||(j=!0,Se().catch(o=>console.error("auto-champion-select: Failed to initialize",o)))}document.readyState==="loading"?window.addEventListener("load",V,{once:!0}):V();export{V as load};
84
+ `;function H(o){const t=document.createElement(u.dropdownOption);return t.setAttribute("slot",u.dropdownOption),t.innerText=o,t}class Dt{constructor(t,e,n){this.dropdownElement=t,this.placeholderText=e,this.onChampionSelected=n,this.placeholderOption=null}renderOptions(t){this.dropdownElement.replaceChildren(),this.placeholderOption=H(this.placeholderText),this.placeholderOption.setAttribute("selected","true"),this.dropdownElement.appendChild(this.placeholderOption);for(const e of t){const n=this.createChampionOption(e);this.dropdownElement.appendChild(n)}}createChampionOption(t){const e=H(t.name);return e.addEventListener("click",()=>{this.onChampionSelected(t.id),requestAnimationFrame(()=>this.reset())}),e}async waitForRender(){for(let t=0;t<Mt;t++){const e=this.dropdownElement.shadowRoot;if(this.dropdownElement.isConnected&&(e!=null&&e.querySelector(l.dropdownCurrent)))return e;await g(Rt)}return null}ensureSearchPlaceholder(t){if(t.querySelector(`#${U}`))return;const e=t.querySelector(l.dropdownCurrent);e&&e.appendChild(this.createSearchPlaceholder())}createSearchPlaceholder(){const t=document.createElement("div");t.classList.add(st,at),t.id=U;const e=document.createElement("input");e.classList.add(it),e.id=W,e.type="text",e.placeholder="Search";const n=document.createElement("span");return n.classList.add(ot),n.addEventListener("click",()=>{n.classList.contains(w)&&this.clearSearch(e,n)}),e.addEventListener("input",i=>{this.ensureOpen(),this.filterOptions(i.target.value),n.classList.toggle(w,!!i.target.value)}),["pointerdown","click"].forEach(i=>{t.addEventListener(i,s=>s.stopPropagation()),n.addEventListener(i,s=>s.stopPropagation())}),["pointerdown","focusin"].forEach(i=>{e.addEventListener(i,s=>s.stopPropagation(),!0)}),t.appendChild(n),t.appendChild(e),t}clearSearch(t,e){t.value="",this.filterOptions(""),e.classList.toggle(w,!1)}filterOptions(t){const e=t.toLowerCase();this.dropdownElement.querySelectorAll(l.dropdownOption).forEach(i=>{(i.textContent??"").toLowerCase().includes(e)?i.style.display="":i.style.display="none"})}reset(){var t;this.dropdownElement.querySelectorAll(l.dropdownOptionSelected).forEach(e=>{e.removeAttribute("selected")}),(t=this.placeholderOption)==null||t.setAttribute("selected","true"),this.withShadowRoot(e=>{var s;const n=e.querySelector(`#${W}`),i=e.querySelector(`.${w}`);n&&i?this.clearSearch(n,i):(n&&(n.value="",this.filterOptions("")),i&&i.classList.remove(w)),this.isOpen()&&((s=e.querySelector(l.dropdownCurrent))==null||s.click())})}isOpen(){return this.dropdownElement.classList.contains("active")}ensureOpen(){this.isOpen()||this.withShadowRoot(t=>{const e=t.querySelector(l.dropdownCurrent);e&&e.click()})}patchDropdownShadowDom(){this.withShadowRoot(t=>{this.injectDropdownSearchStyles(t)})}injectDropdownSearchStyles(t){if(t.querySelector("style[data-controlado='dropdown-tags']"))return;const e=document.createElement("style");e.dataset.controlado="dropdown-tags",e.textContent=Bt,t.appendChild(e)}withShadowRoot(t){const e=this.dropdownElement.shadowRoot;e&&t(e)}}const xt=".champion-priority-selector__position-badge",Ft=".champion-priority-selector__position-option",Nt=".champion-priority-selector__remove",E=8,$t=5,zt=150,Gt="cubic-bezier(0.2, 0, 0, 1)";class Y{constructor(t,e,n,i={}){this.element=this.createRootElement(),this.dropdownElement=this.createDropdownElement(),this.championDropdown=new Dt(this.dropdownElement,t,r=>this.addChampion(r));const{scrollElement:s,trackElement:a}=this.createSelectedChampionsScroll();this.scrollElement=s,this.trackElement=a,this.enablePositionRestrictions=i.enablePositionRestrictions===!0,this.positionMenuElement=this.enablePositionRestrictions?this.createPositionMenu():null,this.positionMenuChampionId=null,this.positionsByChampionId={},this.emptyElement=this.createEmptyState(t),this.element.append(this.dropdownElement,this.scrollElement),this.positionMenuElement&&this.element.appendChild(this.positionMenuElement),this.config=null,this.configKey=e,this.loadChampions=n,this.champions=[],this.championById=new Map,this.selectedChampionIds=[],this.iconButtons=new Map,this.dragState=null,this.handleWindowPointerMove=r=>this.moveDrag(r),this.handleWindowPointerUp=r=>this.finishDrag(r),this.handleWindowPointerCancel=r=>this.cancelDrag(r),this.handlePositionMenuOutsidePointerDown=r=>this.closePositionMenuOnOutsidePointerDown(r),this.handlePositionMenuKeyDown=r=>this.closePositionMenuOnKeyDown(r),this.setupInFlight=null,this.setupPending=!1}createRootElement(){const t=document.createElement("div");return t.classList.add("champion-priority-selector"),t}createDropdownElement(){const t=document.createElement(u.dropdown);return t.classList.add("dropdown-champions-default","dropdown-drop-up"),t}createSelectedChampionsScroll(){const t=document.createElement(u.scrollable);t.classList.add("champion-priority-selector__scroll"),t.setAttribute("direction","horizontal"),t.setAttribute("overflow-masks","disabled"),t.setAttribute("side-scroll-wheel","true");const e=document.createElement("div");return e.classList.add("champion-priority-selector__track"),t.appendChild(e),{scrollElement:t,trackElement:e}}createEmptyState(t){const e=document.createElement("div");e.classList.add("champion-priority-selector__empty");const n=document.createElement("span");n.innerText="No champions";const i=document.createElement("span"),s=t.replace(/^Add\s+/i,"").toLowerCase();return i.innerText=`Use dropdown to add ${s} option`,e.append(n,i),e}createPositionMenu(){const t=document.createElement("div");t.classList.add("champion-priority-selector__position-menu"),t.hidden=!0;for(const e of P)t.appendChild(this.createPositionOption(e));return t}createPositionOption(t){const e=document.createElement("button");e.classList.add("champion-priority-selector__position-option"),e.type="button",e.dataset.position=t.value,e.title=t.label,e.setAttribute("aria-label",t.label),e.setAttribute("aria-pressed","false"),e.addEventListener("pointerdown",i=>i.stopPropagation()),e.addEventListener("click",i=>{i.stopPropagation(),this.toggleChampionPosition(t.value)});const n=document.createElement("img");return n.src=t.iconPath,n.alt=t.label,n.draggable=!1,e.appendChild(n),e}async setup(){return this.setupPending=!0,this.setupInFlight||(this.setupInFlight=this.runSetupLoop()),this.setupInFlight}refresh(){return this.setup()}async runSetupLoop(){try{for(;this.setupPending;)this.setupPending=!1,await this.performSetup()}finally{this.setupInFlight=null}}async performSetup(){this.champions=await this.loadChampions(),this.championById=new Map(this.champions.map(n=>[n.id,n]));const t=this.getAllowedChampionIds();this.config=tt(this.configKey,{allowedChampionIds:t}),this.selectedChampionIds=X(this.config.champions,t),this.enablePositionRestrictions&&(this.positionsByChampionId=_(this.config.positionsByChampionId,this.selectedChampionIds)),this.championDropdown.renderOptions(this.champions),this.renderSelectedChampions();const e=await this.championDropdown.waitForRender();e&&(this.championDropdown.ensureSearchPlaceholder(e),this.championDropdown.patchDropdownShadowDom())}getAllowedChampionIds(){return new Set(this.championById.keys())}addChampion(t){const e=d(t);e===null||!this.championById.has(e)||this.selectedChampionIds.includes(e)||(this.selectedChampionIds.push(e),this.renderSelectedChampions(),this.saveConfig())}removeChampion(t){const e=d(t),n=this.selectedChampionIds.indexOf(e);e===null||n===-1||(this.selectedChampionIds.splice(n,1),this.positionMenuChampionId===e&&this.closePositionMenu(),this.enablePositionRestrictions&&delete this.positionsByChampionId[String(e)],this.renderSelectedChampions(),this.saveConfig())}moveChampionToIndex(t,e){const n=d(t),i=this.selectedChampionIds.indexOf(n);if(n===null||i===-1)return!1;const[s]=this.selectedChampionIds.splice(i,1),a=Math.max(0,Math.min(e,this.selectedChampionIds.length));return this.selectedChampionIds.splice(a,0,s),i!==a}syncPositionsByChampionId(){this.enablePositionRestrictions&&(this.positionsByChampionId=_(this.positionsByChampionId,this.selectedChampionIds))}saveConfig(){this.syncPositionsByChampionId();const t=this.getAllowedChampionIds();this.config=B(this.configKey,e=>(e.champions=[...this.selectedChampionIds],this.enablePositionRestrictions&&(e.positionsByChampionId={...this.positionsByChampionId}),e),{allowedChampionIds:t,selectedChampionIds:this.selectedChampionIds}),this.enablePositionRestrictions&&(this.positionsByChampionId=this.config.positionsByChampionId||{}),console.debug(this.configKey,this.config)}renderSelectedChampions(t=null,e=null){this.positionMenuChampionId!==null&&this.closePositionMenu();const n=new Set(this.selectedChampionIds);for(const[s,a]of this.iconButtons)n.has(s)||(a.remove(),this.iconButtons.delete(s));if(this.selectedChampionIds.length===0){this.trackElement.replaceChildren(this.emptyElement);return}this.emptyElement.remove();const i=this.selectedChampionIds.map((s,a)=>this.getIconButton(s,a)).filter(Boolean);this.trackElement.append(...i),t&&this.animateReorder(t,e)}getIconButton(t,e){const n=this.championById.get(t);if(!n)return null;let i=this.iconButtons.get(t);i||(i=this.createIconButton(n),this.iconButtons.set(t,i)),i.dataset.rank=String(e+1);const s=this.getChampionPositionTitleSuffix(t);i.title=`${e+1}. ${n.name}${s}`,i.setAttribute("aria-label",`${e+1}. ${n.name}${s}`);const a=i.querySelector("img");a.src=n.squarePortraitPath,a.alt=n.name;const r=i.querySelector(Nt);return r.setAttribute("aria-label",`Remove ${n.name}`),r.title=`Remove ${n.name}`,this.renderPositionBadge(i,t),i}createIconButton(t){const e=document.createElement("div");e.classList.add("champion-priority-selector__icon"),e.setAttribute("role","button"),e.tabIndex=0;const n=document.createElement("img");n.draggable=!1;const i=document.createElement("button");return i.classList.add("champion-priority-selector__remove"),i.type="button",i.innerText="x",i.addEventListener("pointerdown",s=>s.stopPropagation()),i.addEventListener("click",s=>{s.stopPropagation(),this.removeChampion(t.id)}),e.addEventListener("pointerdown",s=>this.startDrag(s,t.id)),this.enablePositionRestrictions&&e.addEventListener("contextmenu",s=>this.openPositionMenu(s,t.id)),e.append(n,i),e}getChampionAllowedPositions(t){const e=d(t);return e===null?[]:this.positionsByChampionId[String(e)]||[]}getChampionAllowedPositionLabels(t){return this.getChampionAllowedPositions(t).map(e=>{var n;return(n=F(e))==null?void 0:n.label}).filter(Boolean)}getChampionPositionTitleSuffix(t){const e=this.getChampionAllowedPositionLabels(t);return e.length>0?` (${e.join(", ")})`:""}renderPositionBadge(t,e){var i;if((i=t.querySelector(xt))==null||i.remove(),!this.enablePositionRestrictions)return;const n=this.createPositionBadge(e);n&&t.appendChild(n)}createPositionBadge(t){const e=this.getChampionAllowedPositions(t),n=this.getChampionAllowedPositionLabels(t),i=document.createElement("button");if(i.classList.add("champion-priority-selector__position-badge"),i.type="button",i.title=n.length>0?`${n.join(", ")}. Click to edit positions.`:"Any position. Click to restrict positions.",i.setAttribute("aria-label",i.title),i.addEventListener("pointerdown",r=>r.stopPropagation()),i.addEventListener("click",r=>this.openPositionMenu(r,t,i)),e.length===0)return i.classList.add("champion-priority-selector__position-badge--empty"),i.innerText="+",i;const s=F(e[0]);if(!s)return null;e.length>1&&(i.dataset.count=String(e.length));const a=document.createElement("img");return a.src=s.iconPath,a.alt=s.label,a.draggable=!1,i.appendChild(a),i}openPositionMenu(t,e,n=null){if(!this.enablePositionRestrictions||!this.positionMenuElement)return;const i=d(e);if(i===null||!this.selectedChampionIds.includes(i))return;t.preventDefault(),t.stopPropagation(),this.positionMenuChampionId=i,this.renderPositionMenu(),this.positionMenuElement.hidden=!1,this.positionMenuElement.style.left="0px",this.positionMenuElement.style.top="0px";const{left:s,top:a}=this.getPositionMenuCoordinates(t,n);this.positionMenuElement.style.left=`${s}px`,this.positionMenuElement.style.top=`${a}px`,document.addEventListener("pointerdown",this.handlePositionMenuOutsidePointerDown,!0),document.addEventListener("keydown",this.handlePositionMenuKeyDown,!0)}getPositionMenuCoordinates(t,e=null){const n=this.positionMenuElement.getBoundingClientRect();let i=t.clientX,s=t.clientY;if(e&&t.type==="click"&&t.detail===0){const c=e.getBoundingClientRect();i=c.left+c.width/2,s=c.bottom}const a=Math.min(Math.max(i,E),window.innerWidth-n.width-E),r=Math.min(Math.max(s,E),window.innerHeight-n.height-E);return{left:a,top:r}}renderPositionMenu(){if(!this.positionMenuElement||this.positionMenuChampionId===null)return;const t=new Set(this.getChampionAllowedPositions(this.positionMenuChampionId));this.positionMenuElement.querySelectorAll(Ft).forEach(e=>{const n=t.has(e.dataset.position);e.classList.toggle("champion-priority-selector__position-option--selected",n),e.setAttribute("aria-pressed",String(n))})}toggleChampionPosition(t){if(!this.enablePositionRestrictions||this.positionMenuChampionId===null)return;const e=I(t);if(!e)return;const n=String(this.positionMenuChampionId),i=new Set(this.positionsByChampionId[n]||[]);i.has(e)?i.delete(e):i.add(e);const s=P.map(c=>c.value).filter(c=>i.has(c));s.length>0?this.positionsByChampionId[n]=s:delete this.positionsByChampionId[n],this.renderPositionMenu();const a=this.iconButtons.get(this.positionMenuChampionId),r=this.selectedChampionIds.indexOf(this.positionMenuChampionId);a&&r!==-1&&this.getIconButton(this.positionMenuChampionId,r),this.saveConfig()}closePositionMenuOnOutsidePointerDown(t){var e;(e=this.positionMenuElement)!=null&&e.contains(t.target)||this.closePositionMenu()}closePositionMenuOnKeyDown(t){t.key==="Escape"&&this.closePositionMenu()}closePositionMenu(){this.positionMenuElement&&(this.positionMenuElement.hidden=!0,this.positionMenuChampionId=null,document.removeEventListener("pointerdown",this.handlePositionMenuOutsidePointerDown,!0),document.removeEventListener("keydown",this.handlePositionMenuKeyDown,!0))}startDrag(t,e){var i;if(t.button!==0)return;this.dragState&&this.clearDragState();const n=this.iconButtons.get(e);if(n){this.dragState={championId:e,pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,active:!1,moved:!1};try{(i=n.setPointerCapture)==null||i.call(n,t.pointerId)}catch{}window.addEventListener("pointermove",this.handleWindowPointerMove),window.addEventListener("pointerup",this.handleWindowPointerUp),window.addEventListener("pointercancel",this.handleWindowPointerCancel)}}moveDrag(t){var p;if(!this.dragState||this.dragState.pointerId!==t.pointerId)return;const e=this.dragState.championId,n=t.clientX-this.dragState.startX,i=t.clientY-this.dragState.startY,s=Math.hypot(n,i);if(!this.dragState.active){if(s<$t)return;this.dragState.active=!0,(p=this.iconButtons.get(e))==null||p.classList.add("champion-priority-selector__icon--dragging")}t.preventDefault();const a=this.getDropIndex(t.clientX,e),r=this.selectedChampionIds.indexOf(e);if(a===r||a===-1)return;const c=this.getIconPositions();this.moveChampionToIndex(e,a)&&(this.dragState.moved=!0,this.renderSelectedChampions(c,e))}finishDrag(t){if(!this.dragState||this.dragState.pointerId!==t.pointerId)return;const e=this.dragState.active,n=this.dragState.moved;this.clearDragState(),e&&n&&this.saveConfig()}cancelDrag(t){!this.dragState||this.dragState.pointerId!==t.pointerId||this.clearDragState()}clearDragState(){var i;if(!this.dragState)return;const{championId:t,pointerId:e}=this.dragState,n=this.iconButtons.get(t);n==null||n.classList.remove("champion-priority-selector__icon--dragging");try{(i=n==null?void 0:n.releasePointerCapture)==null||i.call(n,e)}catch{}window.removeEventListener("pointermove",this.handleWindowPointerMove),window.removeEventListener("pointerup",this.handleWindowPointerUp),window.removeEventListener("pointercancel",this.handleWindowPointerCancel),this.dragState=null}getDropIndex(t,e){const n=this.selectedChampionIds.filter(i=>i!==e);for(let i=0;i<n.length;i++){const s=this.iconButtons.get(n[i]);if(!s)continue;const a=s.getBoundingClientRect();if(t<a.left+a.width/2)return i}return n.length}getIconPositions(){const t=new Map;for(const e of this.selectedChampionIds){const n=this.iconButtons.get(e);n&&t.set(e,n.getBoundingClientRect())}return t}animateReorder(t,e){for(const n of this.selectedChampionIds){if(n===e)continue;const i=this.iconButtons.get(n),s=t.get(n);if(!i||!s||typeof i.animate!="function")continue;const a=i.getBoundingClientRect(),r=s.left-a.left,c=s.top-a.top;r===0&&c===0||i.animate([{transform:`translate(${r}px, ${c}px)`},{transform:"translate(0, 0)"}],{duration:zt,easing:Gt})}}}const qt=200,T="auto-select-champ-select-menu--collapsed",Ut="auto-select-champ-select-menu-button-wrapper--open";class k{constructor(t,e){this.element=document.createElement(u.radioInputOption),this.element.classList.add("lol-settings-voice-input-mode-option","auto-select-checkbox"),this.element.innerText=t,this.config=null,this.configKey=e,this.setupComplete=!1}setup(){this.syncFromConfig(),this.setupComplete||(this.element.addEventListener("click",()=>this.toggle()),this.setupComplete=!0)}syncFromConfig(){this.config=tt(this.configKey),this.element.toggleAttribute("selected",this.config.enabled===!0)}toggle(){return console.debug("auto-champion-select: Toggling",this.configKey),this.config=B(this.configKey,t=>(t.enabled=!t.enabled,t)),this.element.toggleAttribute("selected",this.config.enabled===!0),this.config.enabled}}class Wt{constructor(t,e,n){this.element=document.createElement("div"),this.element.classList.add("auto-select-champ-select-menu",T),this.buttonWrapper=document.createElement("div"),this.buttonWrapper.classList.add("auto-select-champ-select-menu-button-wrapper"),this.headerElement=document.createElement("button"),this.headerElement.classList.add("auto-select-champ-select-menu__header"),this.headerElement.type="button",this.headerElement.setAttribute("aria-label",t),this.headerElement.setAttribute("aria-expanded","false"),this.headerElement.addEventListener("click",()=>this.toggle()),this.contentElement=document.createElement("div"),this.contentElement.classList.add("auto-select-champ-select-menu__content"),this.titleElement=document.createElement("div"),this.titleElement.classList.add("auto-select-champ-select-menu__title"),this.titleElement.textContent=t,this.buttonWrapper.append(this.headerElement,this.element),this.contentElement.appendChild(this.titleElement),this.element.appendChild(this.contentElement),this.returnControlsToSocialRoster=e,this.controlElements=n,this.boundCloseOnOutsideInteraction=i=>this.closeOnOutsideInteraction(i),this.buttonObserver=null,this.buttonMountFrame=null,this.buttonMountTask=null,this.hiddenStates=new WeakMap,this.mounted=!1}async mount(){return this.mounted?this.mountButton():(this.mounted=!0,this.controlElements.forEach(t=>{this.hiddenStates.set(t,t.classList.contains("hidden")),t.classList.remove("hidden"),this.contentElement.appendChild(t)}),this.observeButtonContainer(),document.addEventListener("pointerdown",this.boundCloseOnOutsideInteraction,!0),this.mountButton())}unmount(){return this.mounted?(this.mounted=!1,this.stopButtonMounting(),document.removeEventListener("pointerdown",this.boundCloseOnOutsideInteraction,!0),this.setOpen(!1),this.buttonWrapper.remove(),this.restoreHiddenStates(),this.returnControlsToSocialRoster()):this.returnControlsToSocialRoster()}stopButtonMounting(){var t;(t=this.buttonObserver)==null||t.disconnect(),this.buttonObserver=null,this.buttonMountFrame!==null&&(cancelAnimationFrame(this.buttonMountFrame),this.buttonMountFrame=null),this.buttonMountTask=null}restoreHiddenStates(){this.controlElements.forEach(t=>{t.classList.toggle("hidden",this.hiddenStates.get(t)===!0),this.hiddenStates.delete(t)})}isOpen(){return!this.element.classList.contains(T)}setOpen(t){this.element.classList.toggle(T,!t),this.buttonWrapper.classList.toggle(Ut,t),this.headerElement.setAttribute("aria-expanded",String(t))}toggle(){this.setOpen(!this.isOpen())}closeOnOutsideInteraction(t){if(!this.isOpen())return;(typeof t.composedPath=="function"?t.composedPath():[]).includes(this.buttonWrapper)||this.buttonWrapper.contains(t.target)||this.setOpen(!1)}observeButtonContainer(){this.buttonObserver=new MutationObserver(()=>this.scheduleMountButton()),this.buttonObserver.observe(document.body,{childList:!0,subtree:!0})}scheduleMountButton(){this.buttonMountFrame===null&&(this.buttonMountFrame=requestAnimationFrame(()=>{this.buttonMountFrame=null,this.mountButton()}))}mountButton(){return this.buttonMountTask||(this.buttonMountTask=this.appendButtonToContainer().finally(()=>{this.buttonMountTask=null})),this.buttonMountTask}async appendButtonToContainer(){let t=v();for(;this.mounted&&!t;)await g(qt),t=v();if(!this.mounted||!t)return;const e=t.querySelector(l.firstChampSelectSquareButton);this.buttonWrapper.parentNode===t&&this.buttonWrapper.nextSibling===e||t.insertBefore(this.buttonWrapper,e)}}class Ht{constructor(t,...e){this.element=document.createElement(u.socialRosterGroup),this.element.addEventListener("post-render",()=>this.onPostRender()),this.element.addEventListener("click",()=>this.onClick()),this.label=t,this.collapsibleElements=e,this.waitRender()}waitRender(){new MutationObserver((t,e)=>{if(this.element.querySelector(l.socialRosterGroupLabel)){const n=new Event("post-render");this.element.dispatchEvent(n),e.disconnect()}}).observe(this.element,{childList:!0})}onPostRender(){var t;this.element.querySelector(l.socialRosterGroupLabel).innerText=this.label,(t=this.element.querySelector(l.socialRosterGroupHeader))==null||t.removeAttribute("draggable")}onClick(){var t;this.collapsibleElements.forEach(e=>{e.closest(".auto-select-champ-select-menu")||e.classList.toggle("hidden")}),(t=this.element.querySelector(l.socialRosterGroupArrow))==null||t.toggleAttribute("open")}}const S="Balaclava: Auto Champion Select";function Yt(o){return typeof(o==null?void 0:o.then)=="function"}class D{constructor({id:t,name:e,legend:n,tags:i,group:s,callback:a,toasts:r}){this.id=t,this.name=e,this.legend=n,this.tags=i,this.group=s,this.perform=this.perform.bind(this),this.callback=a,this.toasts=r}perform(){try{const t=this.callback();if(Yt(t))return Toast.promise(t,{loading:this.toasts.loading,success:this.toasts.success,error:this.toasts.error});const e=this.toasts.success||(t?this.toasts.on:this.toasts.off);Toast.success(e)}catch(t){Toast.error(this.toasts.error),console.error(t)}}}class rt extends D{constructor(t,e,n){super({id:`${e}Switch`,name:()=>`Auto ${t} [${C(e).enabled?"ON":"OFF"}]`,legend:()=>C(e).enabled?"Turn OFF":"Turn ON",tags:[S,e,"switch"],group:S,callback:n,toasts:{on:`Auto ${t} is ON!`,off:`Auto ${t} is OFF!`,error:`Failed to toggle Auto ${t}. Check console.`}})}}function jt(o){return B(o,e=>(e.force=!e.force,e)).force}class ct extends D{constructor(t,e){super({id:`${e}ForceSwitch`,name:()=>`Force ${t} [${C(e).force?"ON":"OFF"}]`,legend:()=>`Ignore team intent and force ${t} the selected champion`,tags:[S,e,"force","switch"],group:S,callback:()=>jt(e),toasts:{on:`Force ${t} is ON!`,off:`Force ${t} is OFF!`,error:`Failed to toggle Force ${t}. Check console.`}})}}class Vt extends D{constructor(t){super({id:"RefreshDropdowns",name:()=>"Refresh Champions",legend:()=>"Normally champion selectors refresh automatically...",tags:[S,"refresh"],group:S,callback:t,toasts:{success:"Refreshed Champions!",error:"Failed to refresh Champions. Check console."}})}}class Xt extends rt{constructor(t){super("Pick","controladoPick",t)}}class Jt extends rt{constructor(t){super("Ban","controladoBan",t)}}class Kt extends ct{constructor(){super("Pick","controladoPick")}}class Qt extends ct{constructor(){super("Ban","controladoBan")}}function Zt(o){for(const t of o)CommandBar.addAction(t)}const te=2e3,ee=200,ne=6e4,oe=".auto-select-champ-select-menu__header",b=Object.freeze({autoAccept:"controladoAutoAccept",pick:"controladoPick",ban:"controladoBan"});async function ie(){C(b.autoAccept).enabled===!0&&(console.debug("auto-champion-select(auto-accept): Ready check detected, accepting in 2 seconds..."),await g(te),await se())}async function se(){const o=await f("POST",h.readyCheckAccept);o.ok?console.debug("auto-champion-select(auto-accept): Accepted ready check"):console.error("auto-champion-select(auto-accept): Failed to accept ready check",o)}async function ae(o){const t=await f("GET",h.gameflowPhase),e=t.ok?await t.json():null;o.handleGameflowPhase(e)}function re({championSelect:o,champSelectControlsMenu:t,setupChampionSelectors:e}){let n=0;return async function(r){const c=++n;try{await i(r,c)}catch(p){console.error("auto-champion-select: Failed to handle gameflow phase",p)}};async function i(a,r){a==="ReadyCheck"&&ie().catch(c=>console.error("auto-champion-select(auto-accept): Failed to handle ready check",c)),await s(a),r===n&&await e()}async function s(a){a==="ChampSelect"?(o.mount(),await t.mount()):(o.unmount(),await t.unmount())}}function ce(){const o=new vt,t=new k("Accept",b.autoAccept),e=new k("Pick",b.pick),n=new Y("Add pick",b.pick,Tt,{enablePositionRestrictions:!0}),i=new k("Ban",b.ban),s=new Y("Add ban",b.ban,kt),a=le(n,s),r=de(t,e,i),c=new Ht("Auto champion select",a,r);return{championSelect:o,autoAcceptToggle:t,pickToggle:e,banToggle:i,pickChampionSelector:n,banChampionSelector:s,selectorsContainer:a,checkboxesContainer:r,pluginSection:c,championSelectors:[n,s]}}function le(...o){const t=document.createElement("div");return t.append(...o.map(e=>e.element)),t}function de(...o){const t=document.createElement("div");return t.classList.add("auto-select-checkboxes-div"),t.append(...o.map(e=>e.element)),t}function he({pluginSection:o,checkboxesContainer:t,selectorsContainer:e}){let n=null,i=0,s=()=>!1;async function a(r){let c=q();for(;!c;){if(s()||r!==i)return;await g(ee),c=q()}s()||r!==i||c.append(o.element,t,e)}return{setIsChampSelectControlsMounted(r){s=r},returnControlsToSocialRoster(){if(n)return n;const r=++i;return n=a(r).catch(c=>console.error("auto-champion-select: Failed to return controls to social roster",c)).finally(()=>{n=null}),n}}}function ue({autoAcceptToggle:o,pickToggle:t,banToggle:e}){o.setup(),t.setup(),e.setup()}async function pe(o){await Promise.all(o.map(t=>t.setup()))}async function me(o){await Promise.all(o.map(t=>t.refresh()))}function fe(){const o=ce(),t=he(o),e=new Wt("Auto Champion Select",t.returnControlsToSocialRoster,[o.checkboxesContainer,o.selectorsContainer]);t.setIsChampSelectControlsMounted(()=>e.mounted);const n={...o,champSelectControlsMenu:e,setupToggles:()=>ue(o),setupChampionSelectors:()=>pe(o.championSelectors),refreshChampionSelectors:()=>me(o.championSelectors),refreshPickChampionSelector:async()=>{await o.pickChampionSelector.refresh()}};return n.handleGameflowPhase=re(n),n}function ge(o){x(h.gameflowPhase,t=>{o.handleGameflowPhase(t.data)}),x(h.wallet,async t=>{if(t.eventType==="Update"){console.debug("auto-champion-select(wallet): Refreshing champion selectors...");try{await o.refreshPickChampionSelector()}catch(e){console.error("auto-champion-select(wallet): Failed to refresh champion selectors",e)}}})}function Ce({pickToggle:o,banToggle:t,refreshChampionSelectors:e}){Zt([new Xt(()=>o.toggle()),new Jt(()=>t.toggle()),new Kt,new Qt,new Vt(e)])}function we(o){let t=null,e=null;function n(){e==null||e.disconnect(),e=null,t!==null&&(cancelAnimationFrame(t),t=null)}const i=setTimeout(()=>{n()},ne);function s(){if(!(v()!==null))return;clearTimeout(i),n(),document.querySelector(oe)!==null||o.handleGameflowPhase("ChampSelect")}e=new MutationObserver(()=>{t===null&&(t=requestAnimationFrame(()=>{t=null,s()}))}),e.observe(document.body,{childList:!0,subtree:!0}),s()}async function be(){const o=fe();o.setupToggles(),Ce(o),ge(o),await ae(o),we(o),console.debug(`auto-champion-select(${dt}): Report bugs to Balaclava#1912`)}let j=!1;function V(){j||(j=!0,be().catch(o=>console.error("auto-champion-select: Failed to initialize",o)))}document.readyState==="loading"?window.addEventListener("load",V,{once:!0}):V();export{V as load};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auto-champion-select",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Pick or ban automatically! 🐧",
5
5
  "author": "balaclava",
6
6
  "repository": {