auto-champion-select 1.9.2 → 1.9.3
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.
- package/dist/index.js +31 -31
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
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.9.
|
|
7
|
+
* @version 1.9.3
|
|
8
8
|
* @license GPL-3.0-or-later
|
|
9
9
|
*/
|
|
10
|
-
import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/npm/balaclava-utils@latest";const jt="1.9.2",Wt={enabled:!1},Kt={enabled:!1,force:!1,quickAction:!1,champions:[432,235],randomPositions:[],positionsByChampionId:{235:["BOTTOM","UTILITY"],432:["UTILITY"]}},Vt={enabled:!1,force:!1,quickAction:!1,champions:[157,777,238,38],randomPositions:[]},Xt={controladoAutoAccept:Wt,controladoPick:Kt,controladoBan:Vt};function h(o){const t=Number(o);return Number.isSafeInteger(t)&&t>0?t:null}function Jt(o,t=null){const e=[],n=new Set,i=Zt(t);if(!Array.isArray(o))return e;for(const s of o){const r=h(s);r===null||n.has(r)||i&&!i.has(r)||(e.push(r),n.add(r))}return e}function Zt(o){return o?new Set(Array.from(o,h).filter(t=>t!==null)):null}const L=[{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"}],te=new Set(L.map(o=>o.value));function v(o){const t=String(o??"").toUpperCase();return te.has(t)?t:null}function B(o){if(!Array.isArray(o))return[];const t=new Set;for(const e of o){const n=v(e);n&&t.add(n)}return L.map(e=>e.value).filter(e=>t.has(e))}function q(o,t=null){const e={};if(!o||typeof o!="object"||Array.isArray(o))return e;const n=ee(t);for(const[i,s]of Object.entries(o)){const r=h(i);if(r===null||!Array.isArray(s))continue;const a=String(r);if(n&&!n.has(a))continue;const c=[],d=new Set;for(const O of s){const N=v(O);!N||d.has(N)||(c.push(N),d.add(N))}c.length>0&&(e[a]=c)}return e}function ee(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 Y(o){return L.find(t=>t.value===o)}function Rt(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 ne(o,t,e){const n=Rt(o,t);if(n.length===0)return!0;const i=v(e);return i!==null&&n.includes(i)}const m="random";function u(o){return o===m}function w(o){return u(o)?m:h(o)}function C(o){const t=w(o);return t===null?null:String(t)}function nt(o,t=null){const e=[],n=new Set,i=oe(t);if(!Array.isArray(o))return e;for(const s of o){const r=w(s);if(r===null)continue;const a=String(r);n.has(a)||!u(r)&&i&&!i.has(r)||(e.push(r),n.add(a))}return e}function T(o){return o?Array.from(o,h).filter(t=>t!==null):[]}function oe(o){return o?new Set(Array.from(o,h).filter(t=>t!==null)):null}const ct=new Set;function ie(o,t){return Object.prototype.hasOwnProperty.call(o,t)}function M(o,t){return ie(o,t)}function se(o){return Array.isArray(o.priorityOptions)?o.priorityOptions:o.champions}function ot(){if(!globalThis.DataStore)throw new Error("DataStore is not available");return globalThis.DataStore}function re(o){return o!==null&&typeof o=="object"&&!Array.isArray(o)}function it(o){if(o!==void 0)return JSON.parse(JSON.stringify(o))}function vt(o){const t=Xt[o];if(!t)throw new Error(`Unknown auto-champion-select config key: ${o}`);return it(t)}function Mt(o,t,e={}){const n=vt(o),i=re(t)?it(t):{},s={...n,...i},r={enabled:s.enabled===!0};return M(n,"force")&&(r.force=s.force===!0),M(n,"quickAction")&&(r.quickAction=s.quickAction===!0),M(n,"champions")&&(r.priorityOptions=nt(se(s),e.allowedChampionIds),r.champions=T(r.priorityOptions)),M(n,"randomPositions")&&(r.randomPositions=B(s.randomPositions)),M(n,"positionsByChampionId")&&(r.positionsByChampionId=q(s.positionsByChampionId,e.selectedChampionIds||r.champions)),r}function xt(o,t,e={}){const n=t===void 0?vt(o):t;return Mt(o,n,e)}function A(o,t={}){const n=ot().get(o);return xt(o,n,t)}function ae(o,t,e={}){const n=ot(),i=Mt(o,t,e);return n.set(o,i),i}function ce(o,t){return JSON.stringify(o)===JSON.stringify(t)}function le(o,t,e){ct.has(o)||(ct.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 Ft(o,t={}){const e=ot(),n=e.get(o),i=xt(o,n,t);return(n===void 0||!ce(n,i))&&(n!==void 0&&le(o,n,i),e.set(o,i)),i}function z(o,t,e={}){const n=A(o,e),i=it(n),s=t(i)||i;return ae(o,s,e)}const p=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",recommendedChampionPositions:"/lol-perks/v1/recommended-champion-positions",champSelectSession:"/lol-champ-select/v1/session",pickableChampionIds:"/lol-champ-select/v1/pickable-champion-ids",bannableChampionIds:"/lol-champ-select/v1/bannable-champion-ids",championIcon(o){return`/lol-game-data/assets/v1/champion-icons/${o}.png`},champSelectAction(o){return`/lol-champ-select/v1/session/actions/${o}`}}),de=1e3;function st(o){let t=null;return function(){return t||(t=Promise.resolve().then(o).finally(()=>{t=null})),t}}function Bt(o,t={}){const e=[],n=new Set;if(!Array.isArray(o))return e;for(const i of o){if(!i||typeof i!="object")continue;const s=h(i.id),r=typeof i.name=="string"?i.name:"";s===null||!r||n.has(r)||(e.push({...i,id:s,name:r,squarePortraitPath:i.squarePortraitPath||p.championIcon(s),recommendedPositions:t[String(s)]||[]}),n.add(r))}return e.sort((i,s)=>i.name.localeCompare(s.name)),e}function he(o){const t={};if(!o||typeof o!="object"||Array.isArray(o))return t;for(const[e,n]of Object.entries(o))!n||typeof n!="object"||Array.isArray(n)||(t[e]=n.recommendedPositions);return q(t)}async function ue(){try{const o=await P("GET",p.recommendedChampionPositions);return o.ok?he(await o.json()):(console.warn("auto-champion-select(recommended-champion-positions): Request failed",o),{})}catch(o){return console.warn("auto-champion-select(recommended-champion-positions): Failed to load",o),{}}}const U=st(ue);async function pe(){let o=await P("GET",p.ownedChampions);for(;!o.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),o=await P("GET",p.ownedChampions),await S(de);return Bt(await o.json(),await U())}async function me(){const[o,t]=await Promise.all([P("GET",p.championSummary),U()]);return Bt(await o.json(),t)}const fe=st(pe),Nt=st(me),lt=300,dt=2e3,ge=4e3,Pe=-1,f=Object.freeze({SATISFIED:"satisfied",TRY_NEXT_CHAMPION:"try-next-champion",STOP_CYCLE:"stop-cycle"}),E=Object.freeze({CONTINUE:"continue-cycle",STOP:"stop-cycle"}),g=Object.freeze({READY:"ready",SKIP_ACTION:"skip-action",STOP_CYCLE:"stop-cycle"}),I=Object.freeze({SATISFIED:"satisfied",TRY_NEXT_PRIORITY_OPTION:"try-next-priority-option",STOP_CYCLE:"stop-cycle"});function X(o){return Array.isArray(o)?o.flat():[]}function ye(o){return X(o).filter(t=>t.type==="ban"&&t.completed===!0).map(t=>t.championId)}function ht(o){return Array.isArray(o)?o:[]}function G(o){const t=new Set;for(const e of o){const n=h(e);n!==null&&t.add(n)}return t}function ut(o){return o.type==="pick"?0:1}function pt(){return{pickConfig:A("controladoPick"),banConfig:A("controladoBan")}}function Ce(o){return o.quickAction===!0}function be(){const o=ge-dt;return dt+Math.floor(Math.random()*(o+1))}function Se(o){const t=[...o];for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t}function we(o){return Array.isArray(o)&&o.length===1&&o[0]===Pe}class Ae{constructor(){this.session=null,this.actions=null,this.localPlayerCellId=null,this.teammateIntentChampionIds=new Set,this.localPlayerIntentChampionId=null,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 S(lt);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 S(lt)}}finally{this.watchTask=null}}async refreshSessionState(){var s,r;const t=await P("GET",p.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=ht(this.session.myTeam),n=ht(this.session.theirTeam),i=e.find(a=>a.cellId===this.localPlayerCellId);this.localPlayerAssignedPosition=v(i==null?void 0:i.assignedPosition),this.localPlayerIntentChampionId=h(i==null?void 0:i.championPickIntent),this.pickedChampionIds=G([...e,...n].map(a=>a.championId)),this.bannedChampionIds=G([...((s=this.session.bans)==null?void 0:s.myTeamBans)||[],...((r=this.session.bans)==null?void 0:r.theirTeamBans)||[],...ye(this.actions)]),this.teammateIntentChampionIds=G(e.map(a=>a.championPickIntent))}async runAutoSelectCycle(){const t=pt();if(!t.pickConfig.enabled&&!t.banConfig.enabled)return;const e=this.getLocalPlayerActions();if(e.length===0){console.debug("auto-champion-select: No local player sub actions found, skipping..."),this.unmount();return}for(const n of e)if(await this.runAutoSelectForAction(n,t)===E.STOP)return}async runAutoSelectForAction(t,e){const n=await this.prepareActionForAutoSelect(t,e);switch(n.status){case g.READY:return this.tryAutoSelectPlan(n.plan);case g.SKIP_ACTION:return E.CONTINUE;case g.STOP_CYCLE:return E.STOP;default:throw new Error(`Unexpected auto-select plan status: ${n.status}`)}}async prepareActionForAutoSelect(t,e){if(!this.isActionAvailable(t))return{status:g.SKIP_ACTION};const n=this.getConfigForActionType(t.type,e);if(!(n!=null&&n.enabled))return{status:g.SKIP_ACTION};const i=this.createAutoSelectPlan(t,n);if(!i)return{status:g.SKIP_ACTION};const s=this.createPlanLimitedToAlreadySatisfiedPriorityOption(i);if(s)return{status:g.READY,plan:s};if(Ce(n))return{status:g.READY,plan:i};const r=await this.delayAndRefreshAutoSelectPlan(t);return r?{status:g.READY,plan:this.createPlanLimitedToAlreadySatisfiedPriorityOption(r)||r}:{status:g.STOP_CYCLE}}async tryAutoSelectPlan(t){for(const e of t.priorityOptions){const n=await this.tryPriorityOptionForAction(t.action,e,t.config);if(n===I.SATISFIED)return E.CONTINUE;if(n===I.STOP_CYCLE)return E.STOP}return E.CONTINUE}async tryPriorityOptionForAction(t,e,n){if(this.isPriorityOptionAlreadySatisfied(t,e))return I.SATISFIED;const i=await this.resolveChampionIdsForPriorityOption(t,e,n),s=u(e)&&!this.isLockingExistingPickIntent(t,i);for(const r of i){const a={tryNextRandomCandidateOnFailure:s},c=await this.attemptChampionForAction(t,r,n,a);if(c===f.SATISFIED)return I.SATISFIED;if(c===f.STOP_CYCLE)return I.STOP_CYCLE}return I.TRY_NEXT_PRIORITY_OPTION}getLocalPlayerActions(){return X(this.actions).filter(t=>this.isPendingLocalPlayerAction(t)).sort((t,e)=>ut(t)-ut(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}createAutoSelectPlan(t,e){const n=this.getAvailablePriorityOptionsForAction(t,e);return n.length===0?null:{action:t,config:e,priorityOptions:n}}getAvailablePriorityOptionsForAction(t,e){return nt(e.priorityOptions||e.champions).filter(n=>!this.isPriorityOptionUnavailableForAction(t,n,e))}isPriorityOptionUnavailableForAction(t,e,n){return!u(e)&&this.isChampionUnavailableForAction(t,e,n)}createPlanLimitedToAlreadySatisfiedPriorityOption(t){const e=t.priorityOptions.find(n=>this.isPriorityOptionAlreadySatisfied(t.action,n));return e===void 0?null:{...t,priorityOptions:[e]}}isPriorityOptionAlreadySatisfied(t,e){return u(e)?this.hasAnyPickIntentSet(t):this.isPickIntentSetToChampion(t,e)}hasAnyPickIntentSet(t){return t.type==="pick"&&t.isInProgress!==!0&&(this.localPlayerIntentChampionId!==null||h(t.championId)!==null)}isLockingExistingPickIntent(t,e){return t.type==="pick"&&t.isInProgress===!0&&e.length===1&&e[0]===this.getPickIntentChampionId(t)}getPickIntentChampionId(t){return t.type!=="pick"?null:h(t.championId)??this.localPlayerIntentChampionId}async delayAndRefreshAutoSelectPlan(t){const e=be();console.debug(`auto-champion-select: Quick action is off, waiting ${e}ms before ${t.type}...`);const n=this.watchVersion;if(await S(e),!this.mounted||n!==this.watchVersion)return null;let i=null;try{await this.refreshSessionState(),i=this.findPendingAction(t)}catch(r){return console.debug("auto-champion-select: Failed to refresh champion select after action delay",r),null}if(!i||!this.isActionAvailable(i))return null;const s=this.getConfigForActionType(t.type,pt());return s!=null&&s.enabled?this.createAutoSelectPlan(i,s):null}async resolveChampionIdsForPriorityOption(t,e,n){return u(e)?this.resolveRandomChampionIdsForAction(t,n):[e]}async resolveRandomChampionIdsForAction(t,e){if(t.type==="pick"&&t.isInProgress===!0){const r=this.getPickIntentChampionId(t);if(r!==null&&!this.isChampionUnavailableForAction(t,r,e))return[r]}const n=await this.fetchRandomCandidateChampionIds(t);if(n.length===0)return[];const i=n.filter(r=>!this.isChampionUnavailableForAction(t,r,e)),s=t.type==="pick"&&!this.hasConfiguredRandomPositions(e)?await this.preferAssignedPositionRandomPickCandidates(i):await this.filterRandomChampionIdsByConfiguredPositions(i,e);return Se(s)}async fetchRandomCandidateChampionIds(t){const e=t.type==="pick"?p.pickableChampionIds:p.bannableChampionIds;try{const n=await P("GET",e);if(!n.ok)return console.debug(`auto-champion-select: Failed to load random ${t.type} candidates`,n),[];const i=await n.json();return t.type==="ban"&&we(i)?(console.debug("auto-champion-select: Random ban endpoint returned unrestricted sentinel, falling back to all champions..."),await this.fetchAllChampionIdsForRandomBan()):Jt(i)}catch(n){return console.debug(`auto-champion-select: Failed to load random ${t.type} candidates`,n),[]}}async fetchAllChampionIdsForRandomBan(){return(await Nt()).map(e=>e.id)}hasConfiguredRandomPositions(t){return B(t.randomPositions).length>0}async filterRandomChampionIdsByConfiguredPositions(t,e){const n=B(e.randomPositions);if(n.length===0)return t;const i=new Set(n),s=await U(),r=t.filter(a=>{var c;return(c=s[String(a)])==null?void 0:c.some(d=>i.has(d))});return r.length===0&&console.debug(`auto-champion-select: No random candidates matched ${n.join(", ")} restriction.`),r}async preferAssignedPositionRandomPickCandidates(t){if(!this.localPlayerAssignedPosition)return t;const e=await U(),n=t.filter(i=>{var s;return(s=e[String(i)])==null?void 0:s.includes(this.localPlayerAssignedPosition)});return n.length>0?n:t}async attemptChampionForAction(t,e,n,i={}){const s=h(e);if(s===null||this.isChampionUnavailableForAction(t,s,n))return f.TRY_NEXT_CHAMPION;if(this.isPickIntentSetToChampion(t,s)||(console.debug(`auto-champion-select: Trying to ${t.type} ${s}...`),(await this.selectChampion(t.id,s)).ok))return f.SATISFIED;console.debug(`auto-champion-select: Failed to ${t.type} ${s}, refreshing champ select state...`);const a=await this.refreshPendingAction(t);return!a||!this.isActionAvailable(a)?f.STOP_CYCLE:i.tryNextRandomCandidateOnFailure===!0?this.hasAnyPickIntentSet(a)?f.SATISFIED:(console.debug(`auto-champion-select: Failed random ${t.type} candidate ${s}, trying next ${t.type}...`),f.TRY_NEXT_CHAMPION):this.isChampionUnavailableForAction(a,s,n)?(console.debug(`auto-champion-select: ${s} is unavailable after refresh, trying next ${t.type}...`),f.TRY_NEXT_CHAMPION):f.STOP_CYCLE}isPickIntentSetToChampion(t,e){return t.type==="pick"&&t.isInProgress!==!0&&(this.localPlayerIntentChampionId===e||h(t.championId)===e)}async refreshPendingAction(t){try{await this.refreshSessionState()}catch(e){return console.debug("auto-champion-select: Failed to refresh champion select action",e),null}return this.findPendingAction(t)}findPendingAction(t){return X(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"&&!ne(n,e,this.localPlayerAssignedPosition)){const i=Rt(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=p.champSelectAction(t);return P("PATCH",n,{body:{championId:e,completed:!0}})}}const y=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",dropdownRoot:".ui-dropdown",dropdownCurrent:".ui-dropdown-current",dropdownCurrentContent:".ui-dropdown-current-content",dropdownOption:y.dropdownOption,dropdownOptionSelected:`${y.dropdownOption}[selected]`,dropdownOptionsContainer:".ui-dropdown-options-container",dropdownOptions:".ui-dropdown-options",dropdownScrollable:y.scrollable,socialRosterGroupArrow:".arrow",socialRosterGroupHeader:".group-header",socialRosterGroupLabel:"span"});function mt(){return document.querySelector(l.socialRoster)}function J(){return document.querySelector(l.champSelectButtons)}const Oe=50,Ee=100,H=210,Q=40,$="controlado-position-filter",Z="controlado-position-filter-visible",b="controlado-position-filter__badge",tt="controlado-position-filter__badge--active",ft="controlado-placeholder",gt="controlado-search",Dt="controlado-filter-input",$t="controlado-tag--search",j="controlado-quick-action",F="controlado-quick-action-toggle",qt="controlado-quick-action-toggle--active",Ie=`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M13.1 2 4 13.2h6.7L9.9 22 20 9.8h-6.9L13.1 2z'/%3E%3C/svg%3E")`,zt="controlado-tag",Ut="controlado-filter-icon",_="controlado-filter-icon--trash",Pt="controlado-champion-option__content",yt="controlado-champion-option__icon",Te="controlado-champion-option__text",Ct="controlado-champion-option__name",_e="controlado-champion-option__description",ke="controlado-champion-option__static-icon",bt=`
|
|
11
|
-
${
|
|
10
|
+
import{request as b,sleep as O,linkEndpoint as at}from"https://cdn.jsdelivr.net/npm/balaclava-utils@latest";const Kt="1.9.3",Vt={enabled:!1},Xt={enabled:!1,force:!1,quickAction:!1,champions:[432,235],randomAssignedPositions:[],randomPoolPositions:[],positionsByChampionId:{235:["BOTTOM","UTILITY"],432:["UTILITY"]}},Jt={enabled:!1,force:!1,quickAction:!1,champions:[157,777,238,38],randomPoolPositions:[]},Zt={controladoAutoAccept:Vt,controladoPick:Xt,controladoBan:Jt};function p(o){const t=Number(o);return Number.isSafeInteger(t)&&t>0?t:null}function te(o,t=null){const e=[],n=new Set,i=ee(t);if(!Array.isArray(o))return e;for(const s of o){const r=p(s);r===null||n.has(r)||i&&!i.has(r)||(e.push(r),n.add(r))}return e}function ee(o){return o?new Set(Array.from(o,p).filter(t=>t!==null)):null}const M=[{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"}],ne=new Set(M.map(o=>o.value));function N(o){const t=String(o??"").toUpperCase();return ne.has(t)?t:null}function C(o){if(!Array.isArray(o))return[];const t=new Set;for(const e of o){const n=N(e);n&&t.add(n)}return M.map(e=>e.value).filter(e=>t.has(e))}function z(o,t=null){const e={};if(!o||typeof o!="object"||Array.isArray(o))return e;const n=oe(t);for(const[i,s]of Object.entries(o)){const r=p(i);if(r===null||!Array.isArray(s))continue;const a=String(r);if(n&&!n.has(a))continue;const l=[],d=new Set;for(const f of s){const B=N(f);!B||d.has(B)||(l.push(B),d.add(B))}l.length>0&&(e[a]=l)}return e}function oe(o){if(!o)return null;const t=new Set;for(const e of o){const n=p(e);n!==null&&t.add(String(n))}return t}function lt(o){return M.find(t=>t.value===o)}function vt(o,t){var n;const e=p(t);return e===null?[]:((n=o==null?void 0:o.positionsByChampionId)==null?void 0:n[String(e)])||[]}function ie(o,t,e){const n=vt(o,t);if(n.length===0)return!0;const i=N(e);return i!==null&&n.includes(i)}const y="random";function u(o){return o===y}function E(o){return u(o)?y:p(o)}function S(o){const t=E(o);return t===null?null:String(t)}function nt(o,t=null){const e=[],n=new Set,i=se(t);if(!Array.isArray(o))return e;for(const s of o){const r=E(s);if(r===null)continue;const a=String(r);n.has(a)||!u(r)&&i&&!i.has(r)||(e.push(r),n.add(a))}return e}function R(o){return o?Array.from(o,p).filter(t=>t!==null):[]}function se(o){return o?new Set(Array.from(o,p).filter(t=>t!==null)):null}const ct=new Set;function Mt(o,t){return Object.prototype.hasOwnProperty.call(o,t)}function T(o,t){return Mt(o,t)}function re(o){return Array.isArray(o.priorityOptions)?o.priorityOptions:o.champions}function ae(o,t){return Mt(o,"randomPoolPositions")?o.randomPoolPositions:t.randomPositions}function ot(){if(!globalThis.DataStore)throw new Error("DataStore is not available");return globalThis.DataStore}function le(o){return o!==null&&typeof o=="object"&&!Array.isArray(o)}function it(o){if(o!==void 0)return JSON.parse(JSON.stringify(o))}function Ft(o){const t=Zt[o];if(!t)throw new Error(`Unknown auto-champion-select config key: ${o}`);return it(t)}function Nt(o,t,e={}){const n=Ft(o),i=le(t)?it(t):{},s={...n,...i},r={enabled:s.enabled===!0};return T(n,"force")&&(r.force=s.force===!0),T(n,"quickAction")&&(r.quickAction=s.quickAction===!0),T(n,"champions")&&(r.priorityOptions=nt(re(s),e.allowedChampionIds),r.champions=R(r.priorityOptions)),T(n,"randomAssignedPositions")&&(r.randomAssignedPositions=C(s.randomAssignedPositions)),T(n,"randomPoolPositions")&&(r.randomPoolPositions=C(ae(i,s))),T(n,"positionsByChampionId")&&(r.positionsByChampionId=z(s.positionsByChampionId,e.selectedChampionIds||r.champions)),r}function xt(o,t,e={}){const n=t===void 0?Ft(o):t;return Nt(o,n,e)}function I(o,t={}){const n=ot().get(o);return xt(o,n,t)}function ce(o,t,e={}){const n=ot(),i=Nt(o,t,e);return n.set(o,i),i}function de(o,t){return JSON.stringify(o)===JSON.stringify(t)}function he(o,t,e){ct.has(o)||(ct.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 Dt(o,t={}){const e=ot(),n=e.get(o),i=xt(o,n,t);return(n===void 0||!de(n,i))&&(n!==void 0&&he(o,n,i),e.set(o,i)),i}function U(o,t,e={}){const n=I(o,e),i=it(n),s=t(i)||i;return ce(o,s,e)}const m=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",recommendedChampionPositions:"/lol-perks/v1/recommended-champion-positions",champSelectSession:"/lol-champ-select/v1/session",pickableChampionIds:"/lol-champ-select/v1/pickable-champion-ids",bannableChampionIds:"/lol-champ-select/v1/bannable-champion-ids",championIcon(o){return`/lol-game-data/assets/v1/champion-icons/${o}.png`},champSelectAction(o){return`/lol-champ-select/v1/session/actions/${o}`}}),ue=1e3;function st(o){let t=null;return function(){return t||(t=Promise.resolve().then(o).finally(()=>{t=null})),t}}function Bt(o,t={}){const e=[],n=new Set;if(!Array.isArray(o))return e;for(const i of o){if(!i||typeof i!="object")continue;const s=p(i.id),r=typeof i.name=="string"?i.name:"";s===null||!r||n.has(r)||(e.push({...i,id:s,name:r,squarePortraitPath:i.squarePortraitPath||m.championIcon(s),recommendedPositions:t[String(s)]||[]}),n.add(r))}return e.sort((i,s)=>i.name.localeCompare(s.name)),e}function pe(o){const t={};if(!o||typeof o!="object"||Array.isArray(o))return t;for(const[e,n]of Object.entries(o))!n||typeof n!="object"||Array.isArray(n)||(t[e]=n.recommendedPositions);return z(t)}async function me(){try{const o=await b("GET",m.recommendedChampionPositions);return o.ok?pe(await o.json()):(console.warn("auto-champion-select(recommended-champion-positions): Request failed",o),{})}catch(o){return console.warn("auto-champion-select(recommended-champion-positions): Failed to load",o),{}}}const G=st(me);async function fe(){let o=await b("GET",m.ownedChampions);for(;!o.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),o=await b("GET",m.ownedChampions),await O(ue);return Bt(await o.json(),await G())}async function ge(){const[o,t]=await Promise.all([b("GET",m.championSummary),G()]);return Bt(await o.json(),t)}const Pe=st(fe),$t=st(ge),dt=300,ht=2e3,ye=4e3,Ce=-1,g=Object.freeze({SATISFIED:"satisfied",TRY_NEXT_CHAMPION:"try-next-champion",STOP_CYCLE:"stop-cycle"}),_=Object.freeze({CONTINUE:"continue-cycle",STOP:"stop-cycle"}),P=Object.freeze({READY:"ready",SKIP_ACTION:"skip-action",STOP_CYCLE:"stop-cycle"}),k=Object.freeze({SATISFIED:"satisfied",TRY_NEXT_PRIORITY_OPTION:"try-next-priority-option",STOP_CYCLE:"stop-cycle"});function X(o){return Array.isArray(o)?o.flat():[]}function be(o){return X(o).filter(t=>t.type==="ban"&&t.completed===!0).map(t=>t.championId)}function ut(o){return Array.isArray(o)?o:[]}function Y(o){const t=new Set;for(const e of o){const n=p(e);n!==null&&t.add(n)}return t}function pt(o){return o.type==="pick"?0:1}function mt(){return{pickConfig:I("controladoPick"),banConfig:I("controladoBan")}}function Ae(o){return o.quickAction===!0}function Se(){const o=ye-ht;return ht+Math.floor(Math.random()*(o+1))}function we(o){const t=[...o];for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t}function Oe(o){return Array.isArray(o)&&o.length===1&&o[0]===Ce}class Ee{constructor(){this.session=null,this.actions=null,this.localPlayerCellId=null,this.teammateIntentChampionIds=new Set,this.localPlayerIntentChampionId=null,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 O(dt);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 O(dt)}}finally{this.watchTask=null}}async refreshSessionState(){var s,r;const t=await b("GET",m.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=ut(this.session.myTeam),n=ut(this.session.theirTeam),i=e.find(a=>a.cellId===this.localPlayerCellId);this.localPlayerAssignedPosition=N(i==null?void 0:i.assignedPosition),this.localPlayerIntentChampionId=p(i==null?void 0:i.championPickIntent),this.pickedChampionIds=Y([...e,...n].map(a=>a.championId)),this.bannedChampionIds=Y([...((s=this.session.bans)==null?void 0:s.myTeamBans)||[],...((r=this.session.bans)==null?void 0:r.theirTeamBans)||[],...be(this.actions)]),this.teammateIntentChampionIds=Y(e.map(a=>a.championPickIntent))}async runAutoSelectCycle(){const t=mt();if(!t.pickConfig.enabled&&!t.banConfig.enabled)return;const e=this.getLocalPlayerActions();if(e.length===0){console.debug("auto-champion-select: No local player sub actions found, skipping..."),this.unmount();return}for(const n of e)if(await this.runAutoSelectForAction(n,t)===_.STOP)return}async runAutoSelectForAction(t,e){const n=await this.prepareActionForAutoSelect(t,e);switch(n.status){case P.READY:return this.tryAutoSelectPlan(n.plan);case P.SKIP_ACTION:return _.CONTINUE;case P.STOP_CYCLE:return _.STOP;default:throw new Error(`Unexpected auto-select plan status: ${n.status}`)}}async prepareActionForAutoSelect(t,e){if(!this.isActionAvailable(t))return{status:P.SKIP_ACTION};const n=this.getConfigForActionType(t.type,e);if(!(n!=null&&n.enabled))return{status:P.SKIP_ACTION};const i=this.createAutoSelectPlan(t,n);if(!i)return{status:P.SKIP_ACTION};const s=this.createPlanLimitedToAlreadySatisfiedPriorityOption(i);if(s)return{status:P.READY,plan:s};if(Ae(n))return{status:P.READY,plan:i};const r=await this.delayAndRefreshAutoSelectPlan(t);return r?{status:P.READY,plan:this.createPlanLimitedToAlreadySatisfiedPriorityOption(r)||r}:{status:P.STOP_CYCLE}}async tryAutoSelectPlan(t){for(const e of t.priorityOptions){const n=await this.tryPriorityOptionForAction(t.action,e,t.config);if(n===k.SATISFIED)return _.CONTINUE;if(n===k.STOP_CYCLE)return _.STOP}return _.CONTINUE}async tryPriorityOptionForAction(t,e,n){if(this.isPriorityOptionAlreadySatisfied(t,e))return k.SATISFIED;const i=await this.resolveChampionIdsForPriorityOption(t,e,n),s=u(e)&&!this.isLockingExistingPickIntent(t,i);for(const r of i){const a={tryNextRandomCandidateOnFailure:s},l=await this.attemptChampionForAction(t,r,n,a);if(l===g.SATISFIED)return k.SATISFIED;if(l===g.STOP_CYCLE)return k.STOP_CYCLE}return k.TRY_NEXT_PRIORITY_OPTION}getLocalPlayerActions(){return X(this.actions).filter(t=>this.isPendingLocalPlayerAction(t)).sort((t,e)=>pt(t)-pt(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}createAutoSelectPlan(t,e){const n=this.getAvailablePriorityOptionsForAction(t,e);return n.length===0?null:{action:t,config:e,priorityOptions:n}}getAvailablePriorityOptionsForAction(t,e){return nt(e.priorityOptions||e.champions).filter(n=>!this.isPriorityOptionUnavailableForAction(t,n,e))}isPriorityOptionUnavailableForAction(t,e,n){return u(e)?this.isRandomPriorityOptionUnavailableForAction(t,n):this.isChampionUnavailableForAction(t,e,n)}isRandomPriorityOptionUnavailableForAction(t,e){if(t.type!=="pick")return!1;const n=C(e.randomAssignedPositions);return n.length===0?!1:this.localPlayerAssignedPosition?n.includes(this.localPlayerAssignedPosition)?!1:(console.debug(`auto-champion-select: Skipping random pick because assigned position ${this.localPlayerAssignedPosition} is not in ${n.join(", ")}.`),!0):(console.debug(`auto-champion-select: Skipping random pick because no assigned position is available for ${n.join(", ")} restriction.`),!0)}createPlanLimitedToAlreadySatisfiedPriorityOption(t){const e=t.priorityOptions.find(n=>this.isPriorityOptionAlreadySatisfied(t.action,n));return e===void 0?null:{...t,priorityOptions:[e]}}isPriorityOptionAlreadySatisfied(t,e){return u(e)?this.hasAnyPickIntentSet(t):this.isPickIntentSetToChampion(t,e)}hasAnyPickIntentSet(t){return t.type==="pick"&&t.isInProgress!==!0&&(this.localPlayerIntentChampionId!==null||p(t.championId)!==null)}isLockingExistingPickIntent(t,e){return t.type==="pick"&&t.isInProgress===!0&&e.length===1&&e[0]===this.getPickIntentChampionId(t)}getPickIntentChampionId(t){return t.type!=="pick"?null:p(t.championId)??this.localPlayerIntentChampionId}async delayAndRefreshAutoSelectPlan(t){const e=Se();console.debug(`auto-champion-select: Quick action is off, waiting ${e}ms before ${t.type}...`);const n=this.watchVersion;if(await O(e),!this.mounted||n!==this.watchVersion)return null;let i=null;try{await this.refreshSessionState(),i=this.findPendingAction(t)}catch(r){return console.debug("auto-champion-select: Failed to refresh champion select after action delay",r),null}if(!i||!this.isActionAvailable(i))return null;const s=this.getConfigForActionType(t.type,mt());return s!=null&&s.enabled?this.createAutoSelectPlan(i,s):null}async resolveChampionIdsForPriorityOption(t,e,n){return u(e)?this.resolveRandomChampionIdsForAction(t,n):[e]}async resolveRandomChampionIdsForAction(t,e){if(t.type==="pick"&&t.isInProgress===!0){const r=this.getPickIntentChampionId(t);if(r!==null&&!this.isChampionUnavailableForAction(t,r,e))return[r]}const n=await this.fetchRandomCandidateChampionIds(t);if(n.length===0)return[];const i=n.filter(r=>!this.isChampionUnavailableForAction(t,r,e)),s=t.type==="pick"&&!this.hasConfiguredRandomPoolPositions(e)?await this.preferAssignedPositionRandomPickCandidates(i):await this.filterRandomChampionIdsByConfiguredPoolPositions(i,e);return we(s)}async fetchRandomCandidateChampionIds(t){const e=t.type==="pick"?m.pickableChampionIds:m.bannableChampionIds;try{const n=await b("GET",e);if(!n.ok)return console.debug(`auto-champion-select: Failed to load random ${t.type} candidates`,n),[];const i=await n.json();return t.type==="ban"&&Oe(i)?(console.debug("auto-champion-select: Random ban endpoint returned unrestricted sentinel, falling back to all champions..."),await this.fetchAllChampionIdsForRandomBan()):te(i)}catch(n){return console.debug(`auto-champion-select: Failed to load random ${t.type} candidates`,n),[]}}async fetchAllChampionIdsForRandomBan(){return(await $t()).map(e=>e.id)}hasConfiguredRandomPoolPositions(t){return C(t.randomPoolPositions).length>0}async filterRandomChampionIdsByConfiguredPoolPositions(t,e){const n=C(e.randomPoolPositions);if(n.length===0)return t;const i=new Set(n),s=await G(),r=t.filter(a=>{var l;return(l=s[String(a)])==null?void 0:l.some(d=>i.has(d))});return r.length===0&&console.debug(`auto-champion-select: No random candidates matched ${n.join(", ")} restriction.`),r}async preferAssignedPositionRandomPickCandidates(t){if(!this.localPlayerAssignedPosition)return t;const e=await G(),n=t.filter(i=>{var s;return(s=e[String(i)])==null?void 0:s.includes(this.localPlayerAssignedPosition)});return n.length>0?n:t}async attemptChampionForAction(t,e,n,i={}){const s=p(e);if(s===null||this.isChampionUnavailableForAction(t,s,n))return g.TRY_NEXT_CHAMPION;if(this.isPickIntentSetToChampion(t,s)||(console.debug(`auto-champion-select: Trying to ${t.type} ${s}...`),(await this.selectChampion(t.id,s)).ok))return g.SATISFIED;console.debug(`auto-champion-select: Failed to ${t.type} ${s}, refreshing champ select state...`);const a=await this.refreshPendingAction(t);return!a||!this.isActionAvailable(a)?g.STOP_CYCLE:i.tryNextRandomCandidateOnFailure===!0?this.hasAnyPickIntentSet(a)?g.SATISFIED:(console.debug(`auto-champion-select: Failed random ${t.type} candidate ${s}, trying next ${t.type}...`),g.TRY_NEXT_CHAMPION):this.isChampionUnavailableForAction(a,s,n)?(console.debug(`auto-champion-select: ${s} is unavailable after refresh, trying next ${t.type}...`),g.TRY_NEXT_CHAMPION):g.STOP_CYCLE}isPickIntentSetToChampion(t,e){return t.type==="pick"&&t.isInProgress!==!0&&(this.localPlayerIntentChampionId===e||p(t.championId)===e)}async refreshPendingAction(t){try{await this.refreshSessionState()}catch(e){return console.debug("auto-champion-select: Failed to refresh champion select action",e),null}return this.findPendingAction(t)}findPendingAction(t){return X(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"&&!ie(n,e,this.localPlayerAssignedPosition)){const i=vt(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=m.champSelectAction(t);return b("PATCH",n,{body:{championId:e,completed:!0}})}}const A=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"}),c=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",dropdownRoot:".ui-dropdown",dropdownCurrent:".ui-dropdown-current",dropdownCurrentContent:".ui-dropdown-current-content",dropdownOption:A.dropdownOption,dropdownOptionSelected:`${A.dropdownOption}[selected]`,dropdownOptionsContainer:".ui-dropdown-options-container",dropdownOptions:".ui-dropdown-options",dropdownScrollable:A.scrollable,socialRosterGroupArrow:".arrow",socialRosterGroupHeader:".group-header",socialRosterGroupLabel:"span"});function ft(){return document.querySelector(c.socialRoster)}function J(){return document.querySelector(c.champSelectButtons)}const Ie=50,Te=100,H=210,Q=40,q="controlado-position-filter",Z="controlado-position-filter-visible",w="controlado-position-filter__badge",tt="controlado-position-filter__badge--active",gt="controlado-placeholder",Pt="controlado-search",qt="controlado-filter-input",zt="controlado-tag--search",j="controlado-quick-action",D="controlado-quick-action-toggle",Ut="controlado-quick-action-toggle--active",_e=`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M13.1 2 4 13.2h6.7L9.9 22 20 9.8h-6.9L13.1 2z'/%3E%3C/svg%3E")`,Gt="controlado-tag",Yt="controlado-filter-icon",L="controlado-filter-icon--trash",yt="controlado-champion-option__content",Ct="controlado-champion-option__icon",ke="controlado-champion-option__text",bt="controlado-champion-option__name",Re="controlado-champion-option__description",Le="controlado-champion-option__static-icon",At=`
|
|
11
|
+
${c.dropdownRoot} {
|
|
12
12
|
position: relative;
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -16,7 +16,7 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
16
16
|
--framed-dropdown-scrollable-max-height: ${H}px;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
:host ${
|
|
19
|
+
:host ${c.dropdownRoot} dt${c.dropdownCurrent} {
|
|
20
20
|
display: grid;
|
|
21
21
|
grid-template-columns: minmax(0, 1fr) max-content max-content;
|
|
22
22
|
align-items: center;
|
|
@@ -24,17 +24,17 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
24
24
|
padding: 7px 8px 7px 10px;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
:host ${
|
|
27
|
+
:host ${c.dropdownRoot} dt${c.dropdownCurrent}::after {
|
|
28
28
|
display: none;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
:host ${
|
|
31
|
+
:host ${c.dropdownRoot} dt${c.dropdownCurrent} ${c.dropdownCurrentContent} {
|
|
32
32
|
min-width: 0;
|
|
33
33
|
padding: 0;
|
|
34
34
|
text-align: left;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
${
|
|
37
|
+
${c.dropdownOptionsContainer} {
|
|
38
38
|
position: absolute;
|
|
39
39
|
top: auto;
|
|
40
40
|
bottom: 100%;
|
|
@@ -44,25 +44,25 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
44
44
|
transform: translateY(0);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
${
|
|
48
|
-
${
|
|
47
|
+
${c.dropdownOptions},
|
|
48
|
+
${c.dropdownScrollable} {
|
|
49
49
|
height: ${H}px;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
${
|
|
52
|
+
${c.dropdownOptions} {
|
|
53
53
|
width: 100%;
|
|
54
54
|
box-sizing: border-box;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
${
|
|
57
|
+
${c.dropdownOptions} ${c.dropdownScrollable} {
|
|
58
58
|
box-sizing: border-box;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
${
|
|
61
|
+
${c.dropdownOptionsContainer}.${Z} ${c.dropdownOptions} ${c.dropdownScrollable} {
|
|
62
62
|
padding-top: ${Q}px;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
.${
|
|
65
|
+
.${q} {
|
|
66
66
|
position: absolute;
|
|
67
67
|
left: 0;
|
|
68
68
|
right: 0;
|
|
@@ -80,7 +80,7 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
80
80
|
box-sizing: border-box;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
.${
|
|
83
|
+
.${w} {
|
|
84
84
|
appearance: none;
|
|
85
85
|
display: grid;
|
|
86
86
|
place-items: center;
|
|
@@ -97,8 +97,8 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
97
97
|
outline: none;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
.${
|
|
101
|
-
.${
|
|
100
|
+
.${w}:hover,
|
|
101
|
+
.${w}:focus {
|
|
102
102
|
border-color: #c8aa6e;
|
|
103
103
|
background: #0f1b2d;
|
|
104
104
|
}
|
|
@@ -109,7 +109,7 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
109
109
|
box-shadow: 0 0 0 1px #c89b3c, 0 0 10px rgba(200, 155, 60, 0.45);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
.${
|
|
112
|
+
.${w} img {
|
|
113
113
|
display: block;
|
|
114
114
|
width: 18px;
|
|
115
115
|
height: 18px;
|
|
@@ -118,13 +118,13 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
118
118
|
pointer-events: none;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
.${
|
|
122
|
-
.${
|
|
121
|
+
.${w}:hover img,
|
|
122
|
+
.${w}:focus img,
|
|
123
123
|
.${tt} img {
|
|
124
124
|
opacity: 1;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
.${
|
|
127
|
+
.${Yt} {
|
|
128
128
|
cursor: default;
|
|
129
129
|
display: inline-block;
|
|
130
130
|
flex: 0 0 auto;
|
|
@@ -137,14 +137,14 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
137
137
|
-webkit-mask-size: 18px 18px;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
.${
|
|
140
|
+
.${L} {
|
|
141
141
|
cursor: pointer;
|
|
142
142
|
background-color: #c86e6e;
|
|
143
143
|
-webkit-mask-image: url('/fe/lol-uikit/images/icon_delete.png');
|
|
144
144
|
-webkit-mask-size: 12px 12px;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
.${
|
|
147
|
+
.${qt} {
|
|
148
148
|
flex: 0 0 auto;
|
|
149
149
|
min-width: 0;
|
|
150
150
|
width: auto;
|
|
@@ -158,7 +158,7 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
158
158
|
font-weight: inherit;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
.${
|
|
161
|
+
.${Gt} {
|
|
162
162
|
cursor: default;
|
|
163
163
|
display: inline-flex;
|
|
164
164
|
align-items: center;
|
|
@@ -176,7 +176,7 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
176
176
|
box-shadow: inset 0 0 8px rgba(15, 30, 45, 0.6);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
.${
|
|
179
|
+
.${zt} {
|
|
180
180
|
border-color: #d7b46a;
|
|
181
181
|
color: #f6e1b2;
|
|
182
182
|
background: #1a232f;
|
|
@@ -190,7 +190,7 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
190
190
|
font-weight: 500;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
.${
|
|
193
|
+
.${D} {
|
|
194
194
|
appearance: none;
|
|
195
195
|
display: inline-grid;
|
|
196
196
|
place-items: center;
|
|
@@ -206,26 +206,26 @@ import{request as P,sleep as S,linkEndpoint as at}from"https://cdn.jsdelivr.net/
|
|
|
206
206
|
outline: none;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
.${
|
|
209
|
+
.${D}::before {
|
|
210
210
|
content: "";
|
|
211
211
|
display: block;
|
|
212
212
|
width: 16px;
|
|
213
213
|
height: 16px;
|
|
214
214
|
background-color: #785a28;
|
|
215
|
-
-webkit-mask-image: ${
|
|
215
|
+
-webkit-mask-image: ${_e};
|
|
216
216
|
-webkit-mask-repeat: no-repeat;
|
|
217
217
|
-webkit-mask-position: center;
|
|
218
218
|
-webkit-mask-size: 16px 16px;
|
|
219
219
|
filter: drop-shadow(0 0 1px #010a13);
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
.${
|
|
223
|
-
.${
|
|
222
|
+
.${D}:hover::before,
|
|
223
|
+
.${D}:focus::before {
|
|
224
224
|
background-color: #c8aa6e;
|
|
225
225
|
}
|
|
226
226
|
|
|
227
|
-
.${
|
|
227
|
+
.${Ut}::before {
|
|
228
228
|
background-color: #f0e6d2;
|
|
229
229
|
filter: drop-shadow(0 0 3px rgba(200, 170, 110, 0.75));
|
|
230
230
|
}
|
|
231
|
-
`;function W(o){const t=document.createElement(y.dropdownOption);return t.setAttribute("slot",y.dropdownOption),t.innerText=o,t}class Le{constructor(t,e,n,i={}){this.dropdownElement=t,this.placeholderText=e,this.searchPlaceholderText=i.searchPlaceholderText||"Search",this.quickActionLabel=i.quickActionLabel||"Pick/ban instantly",this.staticOptions=Array.isArray(i.staticOptions)?i.staticOptions:[],this.isQuickActionEnabled=typeof i.isQuickActionEnabled=="function"?i.isQuickActionEnabled:null,this.onQuickActionToggle=typeof i.onQuickActionToggle=="function"?i.onQuickActionToggle:null,this.onPriorityOptionSelected=n,this.placeholderOption=null,this.searchQuery="",this.activePositionFilter=null,this.hasRecommendedPositionData=!1,this.recommendedPositionsByOption=new WeakMap,this.staticOptionElements=new WeakSet}renderOptions(t){this.dropdownElement.replaceChildren(),this.hasRecommendedPositionData=!1,this.staticOptionElements=new WeakSet,this.placeholderOption=W(this.placeholderText),this.placeholderOption.setAttribute("selected","true"),this.hidePlaceholderOption(),this.dropdownElement.appendChild(this.placeholderOption);for(const e of this.staticOptions)this.dropdownElement.appendChild(this.createStaticOption(e));for(const e of t){const n=this.getChampionRecommendedPositions(e),i=this.createChampionOption(e,n);n.length>0&&(this.hasRecommendedPositionData=!0),this.dropdownElement.appendChild(i)}this.hasRecommendedPositionData||(this.activePositionFilter=null),this.applyOptionFilters()}createChampionOption(t,e){const n=W("");return this.recommendedPositionsByOption.set(n,new Set(e)),n.title=t.name,n.appendChild(this.createChampionOptionContent(t)),n.addEventListener("click",()=>{this.onPriorityOptionSelected(t.id),requestAnimationFrame(()=>this.reset())}),n}createStaticOption(t){const e=W(""),n=typeof t.description=="string"?t.description:"";return this.staticOptionElements.add(e),e.title=n?`${t.label}. ${n}`:t.label,e.appendChild(this.createStaticOptionContent(t,n)),e.addEventListener("click",()=>{this.onPriorityOptionSelected(t.value),requestAnimationFrame(()=>this.reset())}),e}createChampionOptionContent(t){const e=document.createElement("span");e.classList.add(Pt);const n=document.createElement("img");n.classList.add(yt),n.src=t.squarePortraitPath,n.alt="",n.draggable=!1,n.loading="lazy";const i=document.createElement("span");return i.classList.add(Ct),i.innerText=t.name,e.append(n,i),e}createStaticOptionContent(t,e=""){const n=document.createElement("span");n.classList.add(Pt);const i=document.createElement("span");i.classList.add(yt,ke),i.innerText=t.iconText||"?";const s=document.createElement("span");s.classList.add(Ct),s.innerText=t.label;const r=document.createElement("span");if(r.classList.add(Te),r.appendChild(s),e){const a=document.createElement("span");a.classList.add(_e),a.innerText=e,r.appendChild(a)}return n.append(i,r),n}getChampionRecommendedPositions(t){return Array.isArray(t.recommendedPositions)?t.recommendedPositions:[]}async waitForRender(){for(let t=0;t<Oe;t++){const e=this.dropdownElement.shadowRoot;if(this.dropdownElement.isConnected&&(e!=null&&e.querySelector(l.dropdownCurrent)))return e;await S(Ee)}return null}ensureSearchPlaceholder(t){if(t.querySelector(`#${ft}`))return;const e=t.querySelector(l.dropdownCurrent);e&&e.appendChild(this.createSearchPlaceholder())}ensureQuickActionToggle(t){if(!this.isQuickActionAvailable()||t.querySelector(`#${j}`)){this.syncQuickActionToggle(t);return}const e=t.querySelector(l.dropdownCurrent);e&&(e.appendChild(this.createQuickActionToggle()),this.syncQuickActionToggle(t))}ensurePositionFilter(t){var n;const e=t.querySelector(l.dropdownOptionsContainer);if(e){if(!this.hasRecommendedPositionData){(n=t.querySelector(`.${$}`))==null||n.remove(),e.classList.remove(Z),this.activePositionFilter=null;return}e.classList.add(Z),t.querySelector(`.${$}`)||e.insertBefore(this.createPositionFilter(),e.firstChild),this.syncPositionFilter(t)}}createPositionFilter(){const t=document.createElement("div");t.classList.add($),t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Filter champions by position");for(const e of L)t.appendChild(this.createPositionFilterBadge(e));return t}createPositionFilterBadge(t){const e=document.createElement("button");e.classList.add(b),e.type="button",e.dataset.position=t.value,e.title=t.label,e.setAttribute("aria-label",t.label),e.setAttribute("aria-pressed","false");const n=document.createElement("img");return n.src=t.iconPath,n.alt="",n.draggable=!1,e.appendChild(n),e.addEventListener("pointerdown",i=>{i.preventDefault(),i.stopPropagation()}),e.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation(),this.togglePositionFilter(t.value)}),e}createSearchPlaceholder(){const t=document.createElement("div");t.classList.add(zt,$t),t.id=ft;const e=document.createElement("input");e.classList.add(Dt),e.id=gt,e.type="text",e.placeholder=this.searchPlaceholderText,e.setAttribute("aria-label",this.searchPlaceholderText),e.size=Math.max(this.searchPlaceholderText.length,1);const n=document.createElement("span");return n.classList.add(Ut),n.addEventListener("click",()=>{n.classList.contains(_)&&this.clearSearch(e,n)}),e.addEventListener("input",i=>{this.ensureOpen(),this.setSearchQuery(i.target.value),n.classList.toggle(_,!!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}createQuickActionToggle(){const t=document.createElement("button");return t.classList.add(F),t.id=j,t.type="button",t.title=this.quickActionLabel,t.setAttribute("aria-label",this.quickActionLabel),t.setAttribute("aria-pressed","false"),["pointerdown","click"].forEach(e=>{t.addEventListener(e,n=>{n.preventDefault(),n.stopPropagation()})}),t.addEventListener("click",()=>{var e;(e=this.onQuickActionToggle)==null||e.call(this),this.syncQuickActionToggle()}),t}isQuickActionAvailable(){return!!(this.isQuickActionEnabled&&this.onQuickActionToggle)}syncQuickActionToggle(t=this.dropdownElement.shadowRoot){if(!this.isQuickActionAvailable()||!t)return;const e=t.querySelector(`#${j}`);if(!e)return;const n=this.isQuickActionEnabled()===!0;e.classList.toggle(qt,n),e.setAttribute("aria-pressed",String(n)),e.title=this.quickActionLabel,e.setAttribute("aria-label",this.quickActionLabel)}togglePositionFilter(t){const e=v(t);e&&(this.activePositionFilter=this.activePositionFilter===e?null:e,this.withShadowRoot(n=>this.syncPositionFilter(n)),this.applyOptionFilters())}syncPositionFilter(t){t.querySelectorAll(`.${b}`).forEach(e=>{const n=e.dataset.position===this.activePositionFilter;e.classList.toggle(tt,n),e.setAttribute("aria-pressed",String(n))})}clearSearch(t,e){t.value="",this.setSearchQuery(""),e.classList.toggle(_,!1)}setSearchQuery(t){this.searchQuery=t,this.applyOptionFilters()}applyOptionFilters(){const t=this.searchQuery.toLowerCase();this.dropdownElement.querySelectorAll(l.dropdownOption).forEach(n=>{if(n===this.placeholderOption){this.hidePlaceholderOption();return}this.matchesSearchQuery(n,t)&&this.matchesPositionFilter(n)?n.style.display="":n.style.display="none"})}matchesSearchQuery(t,e){return(t.textContent??"").toLowerCase().includes(e)}matchesPositionFilter(t){var e;return this.staticOptionElements.has(t)||!this.activePositionFilter?!0:((e=this.recommendedPositionsByOption.get(t))==null?void 0:e.has(this.activePositionFilter))===!0}hidePlaceholderOption(){this.placeholderOption&&(this.placeholderOption.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(`#${gt}`),i=e.querySelector(`.${_}`);n&&i?this.clearSearch(n,i):(n&&(n.value="",this.setSearchQuery("")),i&&i.classList.remove(_)),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.ensureDropdownOpensUpward(t),this.injectDropdownSearchStyles(t),this.ensurePositionFilter(t)})}ensureDropdownOpensUpward(t){var e;(e=t.querySelector(l.dropdownRoot))==null||e.classList.add("opens-upward")}injectDropdownSearchStyles(t){const e=t.querySelector("style[data-controlado='dropdown-tags']");if(e){e.textContent=bt;return}const n=document.createElement("style");n.dataset.controlado="dropdown-tags",n.textContent=bt,t.appendChild(n)}withShadowRoot(t){const e=this.dropdownElement.shadowRoot;e&&t(e)}}const Re=".champion-priority-selector__position-badge",ve=".champion-priority-selector__position-option",St=".champion-priority-selector__remove",wt="✕",At="?",x="Random",Me=0,Ot=1,D=8,xe=5,Fe=150,Be="cubic-bezier(0.2, 0, 0, 1)";class Et{constructor(t,e,n,i={}){this.element=this.createRootElement(),this.dropdownElement=this.createDropdownElement(),this.championDropdown=new Le(this.dropdownElement,t,a=>this.addPriorityOption(a),{quickActionLabel:i.quickActionLabel,searchPlaceholderText:i.searchPlaceholderText,staticOptions:[{value:m,label:x,description:i.randomOptionDescription,iconText:At}],isQuickActionEnabled:()=>this.isQuickActionEnabled(),onQuickActionToggle:()=>this.toggleQuickAction()});const{scrollElement:s,trackElement:r}=this.createSelectedChampionsScroll();this.scrollElement=s,this.trackElement=r,this.enablePositionRestrictions=i.enablePositionRestrictions===!0,this.enableRandomPositionFilters=i.enableRandomPositionFilters===!0,this.enablePositionMenu=this.enablePositionRestrictions||this.enableRandomPositionFilters,this.positionMenuElement=this.enablePositionMenu?this.createPositionMenu():null,this.positionMenuTargetOption=null,this.positionsByChampionId={},this.randomPositions=[],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.quickAction=!1,this.loadChampions=n,this.champions=[],this.championById=new Map,this.selectedPriorityOptions=[],this.optionButtons=new Map,this.dragState=null,this.handleWindowPointerMove=a=>this.moveDrag(a),this.handleWindowPointerUp=a=>this.finishDrag(a),this.handleWindowPointerCancel=a=>this.cancelDrag(a),this.handlePositionMenuOutsidePointerDown=a=>this.closePositionMenuOnOutsidePointerDown(a),this.handlePositionMenuKeyDown=a=>this.closePositionMenuOnKeyDown(a),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(y.dropdown);return t.classList.add("dropdown-champions-default","dropdown-drop-up"),t}createSelectedChampionsScroll(){const t=document.createElement(y.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 L)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.togglePositionMenuPosition(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=Ft(this.configKey,{allowedChampionIds:t}),this.quickAction=this.config.quickAction===!0,this.selectedPriorityOptions=nt(this.config.priorityOptions||this.config.champions,t),this.enablePositionRestrictions&&(this.positionsByChampionId=q(this.config.positionsByChampionId,T(this.selectedPriorityOptions))),this.enableRandomPositionFilters&&(this.randomPositions=B(this.config.randomPositions)),this.championDropdown.renderOptions(this.champions),this.renderSelectedPriorityOptions();const e=await this.championDropdown.waitForRender();e&&(this.championDropdown.ensureSearchPlaceholder(e),this.championDropdown.ensureQuickActionToggle(e),this.championDropdown.patchDropdownShadowDom())}getAllowedChampionIds(){return new Set(this.championById.keys())}isQuickActionEnabled(){return this.quickAction===!0}toggleQuickAction(){const t=this.getAllowedChampionIds();return this.config=z(this.configKey,e=>(e.quickAction=e.quickAction!==!0,e),{allowedChampionIds:t,selectedChampionIds:T(this.selectedPriorityOptions)}),this.quickAction=this.config.quickAction===!0,this.championDropdown.syncQuickActionToggle(),this.quickAction}addPriorityOption(t){const e=w(t);e===null||this.selectedPriorityOptions.includes(e)||!u(e)&&!this.championById.has(e)||(this.selectedPriorityOptions.push(e),this.renderSelectedPriorityOptions(),this.saveConfig())}removePriorityOption(t){const e=w(t),n=this.selectedPriorityOptions.indexOf(e);if(e===null||n===-1)return;this.selectedPriorityOptions.splice(n,1);const i=u(e)?null:e;this.positionMenuTargetOption===e&&this.closePositionMenu(),this.enablePositionRestrictions&&i!==null&&delete this.positionsByChampionId[String(i)],this.enableRandomPositionFilters&&u(e)&&(this.randomPositions=[]),this.renderSelectedPriorityOptions(),this.saveConfig()}movePriorityOptionToIndex(t,e){const n=w(t),i=this.selectedPriorityOptions.indexOf(n);if(n===null||i===-1)return!1;const[s]=this.selectedPriorityOptions.splice(i,1),r=Math.max(0,Math.min(e,this.selectedPriorityOptions.length));return this.selectedPriorityOptions.splice(r,0,s),i!==r}syncPositionsByChampionId(){this.enablePositionRestrictions&&(this.positionsByChampionId=q(this.positionsByChampionId,T(this.selectedPriorityOptions)))}syncRandomPositions(){this.enableRandomPositionFilters&&(this.randomPositions=B(this.randomPositions))}saveConfig(){this.syncPositionsByChampionId(),this.syncRandomPositions();const t=this.getAllowedChampionIds();this.config=z(this.configKey,e=>(e.priorityOptions=[...this.selectedPriorityOptions],e.champions=T(this.selectedPriorityOptions),this.enableRandomPositionFilters&&(e.randomPositions=[...this.randomPositions]),this.enablePositionRestrictions&&(e.positionsByChampionId={...this.positionsByChampionId}),e),{allowedChampionIds:t,selectedChampionIds:T(this.selectedPriorityOptions)}),this.enablePositionRestrictions&&(this.positionsByChampionId=this.config.positionsByChampionId||{}),this.enableRandomPositionFilters&&(this.randomPositions=this.config.randomPositions||[]),console.debug(this.configKey,this.config)}renderSelectedPriorityOptions(t=null,e=null){this.positionMenuTargetOption!==null&&this.closePositionMenu();const n=new Set(this.selectedPriorityOptions.map(s=>C(s)));for(const[s,r]of this.optionButtons)n.has(s)||(r.remove(),this.optionButtons.delete(s));if(this.selectedPriorityOptions.length===0){this.trackElement.replaceChildren(this.emptyElement);return}this.emptyElement.remove();const i=this.selectedPriorityOptions.map((s,r)=>this.getPriorityOptionButton(s,r)).filter(Boolean);this.trackElement.append(...i),t&&this.animateReorder(t,e)}getPriorityOptionButton(t,e){return u(t)?this.getRandomOptionButton(e):this.getChampionOptionButton(t,e)}getChampionOptionButton(t,e){const n=this.championById.get(t);if(!n)return null;const i=String(t);let s=this.optionButtons.get(i);s||(s=this.createIconButton(n),this.optionButtons.set(i,s)),s.dataset.rank=String(e+1),s.classList.toggle("champion-priority-selector__icon--random",!1);const r=this.getChampionPositionTitleSuffix(t);s.title=`${e+1}. ${n.name}${r}`,s.setAttribute("aria-label",`${e+1}. ${n.name}${r}`);const a=s.querySelector("img");a.src=n.squarePortraitPath,a.alt=n.name;const c=s.querySelector(St);return c.setAttribute("aria-label",`Remove ${n.name}`),c.title=`Remove ${n.name}`,this.renderPositionBadge(s,t),s}getRandomOptionButton(t){let e=this.optionButtons.get(m);e||(e=this.createRandomOptionButton(),this.optionButtons.set(m,e)),e.dataset.rank=String(t+1);const n=this.getRandomPositionTitleSuffix();e.title=`${t+1}. ${x}${n}`,e.setAttribute("aria-label",`${t+1}. ${x}${n}`);const i=e.querySelector(St);return i.setAttribute("aria-label",`Remove ${x}`),i.title=`Remove ${x}`,this.renderPositionBadge(e,m),e}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.dataset.icon=wt,i.addEventListener("pointerdown",s=>s.stopPropagation()),i.addEventListener("click",s=>{s.stopPropagation(),this.removePriorityOption(t.id)}),e.addEventListener("pointerdown",s=>this.startDrag(s,t.id)),e.addEventListener("auxclick",s=>this.removePriorityOptionOnMiddleClick(s,t.id)),this.enablePositionRestrictions&&e.addEventListener("contextmenu",s=>this.openPositionMenu(s,t.id)),e.append(n,i),e}createRandomOptionButton(){const t=document.createElement("div");t.classList.add("champion-priority-selector__icon","champion-priority-selector__icon--random"),t.setAttribute("role","button"),t.tabIndex=0;const e=document.createElement("span");e.classList.add("champion-priority-selector__random-icon"),e.innerText=At;const n=document.createElement("button");return n.classList.add("champion-priority-selector__remove"),n.type="button",n.dataset.icon=wt,n.addEventListener("pointerdown",i=>i.stopPropagation()),n.addEventListener("click",i=>{i.stopPropagation(),this.removePriorityOption(m)}),t.addEventListener("pointerdown",i=>this.startDrag(i,m)),t.addEventListener("auxclick",i=>this.removePriorityOptionOnMiddleClick(i,m)),this.enableRandomPositionFilters&&t.addEventListener("contextmenu",i=>this.openPositionMenu(i,m)),t.append(e,n),t}getChampionAllowedPositions(t){const e=h(t);return e===null?[]:this.positionsByChampionId[String(e)]||[]}getRandomAllowedPositions(){return this.randomPositions}getAllowedPositionsForPriorityOption(t){return u(t)?this.getRandomAllowedPositions():this.getChampionAllowedPositions(t)}getAllowedPositionLabelsForPriorityOption(t){return this.getAllowedPositionsForPriorityOption(t).map(e=>{var n;return(n=Y(e))==null?void 0:n.label}).filter(Boolean)}getChampionAllowedPositionLabels(t){return this.getChampionAllowedPositions(t).map(e=>{var n;return(n=Y(e))==null?void 0:n.label}).filter(Boolean)}getChampionPositionTitleSuffix(t){const e=this.getChampionAllowedPositionLabels(t);return e.length>0?` (${e.join(", ")})`:""}getRandomPositionTitleSuffix(){const t=this.getAllowedPositionLabelsForPriorityOption(m);return t.length>0?` (${t.join(", ")})`:""}renderPositionBadge(t,e){var s;(s=t.querySelector(Re))==null||s.remove();const n=w(e);if(n===null||!this.canOpenPositionMenuForOption(n))return;const i=this.createPositionBadge(n);i&&t.appendChild(i)}createPositionBadge(t){const e=this.getAllowedPositionsForPriorityOption(t),n=this.getAllowedPositionLabelsForPriorityOption(t),i=u(t),s=document.createElement("button");if(s.classList.add("champion-priority-selector__position-badge"),s.classList.toggle("champion-priority-selector__position-badge--random",i),s.type="button",s.title=this.getPositionBadgeTitle(n,i),s.setAttribute("aria-label",s.title),s.addEventListener("pointerdown",c=>c.stopPropagation()),s.addEventListener("click",c=>this.openPositionMenu(c,t,s)),i)return e.length>0?(s.classList.add("champion-priority-selector__position-badge--active"),s.dataset.count=String(e.length)):s.classList.add("champion-priority-selector__position-badge--empty"),s;if(e.length===0)return s.classList.add("champion-priority-selector__position-badge--empty"),s.innerText="+",s;const r=Y(e[0]);if(!r)return null;e.length>1&&(s.dataset.count=String(e.length));const a=document.createElement("img");return a.src=r.iconPath,a.alt=r.label,a.draggable=!1,s.appendChild(a),s}getPositionBadgeTitle(t,e){if(t.length>0){const n=e?"random lanes":"positions";return`${t.join(", ")}. Click to edit ${n}.`}return e?"Any lane. Click to restrict random lanes.":"Any position. Click to restrict positions."}canOpenPositionMenuForOption(t){const e=u(t);return this.selectedPriorityOptions.includes(t)&&(e?this.enableRandomPositionFilters:this.enablePositionRestrictions)}openPositionMenu(t,e,n=null){if(!this.positionMenuElement)return;const i=w(e);if(i===null||!this.canOpenPositionMenuForOption(i))return;t.preventDefault(),t.stopPropagation(),this.positionMenuTargetOption=i,this.renderPositionMenu(),this.positionMenuElement.hidden=!1,this.positionMenuElement.style.left="0px",this.positionMenuElement.style.top="0px";const{left:s,top:r}=this.getPositionMenuCoordinates(t,n);this.positionMenuElement.style.left=`${s}px`,this.positionMenuElement.style.top=`${r}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 r=Math.min(Math.max(i,D),window.innerWidth-n.width-D),a=Math.min(Math.max(s,D),window.innerHeight-n.height-D);return{left:r,top:a}}renderPositionMenu(){if(!this.positionMenuElement||this.positionMenuTargetOption===null)return;const t=new Set(this.getAllowedPositionsForPriorityOption(this.positionMenuTargetOption));this.positionMenuElement.querySelectorAll(ve).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))})}togglePositionMenuPosition(t){if(!this.positionMenuElement||this.positionMenuTargetOption===null)return;const e=v(t);if(!e)return;const n=this.positionMenuTargetOption,i=new Set(this.getAllowedPositionsForPriorityOption(n));i.has(e)?i.delete(e):i.add(e);const s=L.map(d=>d.value).filter(d=>i.has(d));if(u(n))this.randomPositions=s;else{const d=String(n);s.length>0?this.positionsByChampionId[d]=s:delete this.positionsByChampionId[d]}this.renderPositionMenu();const r=C(n),a=r?this.optionButtons.get(r):null,c=this.selectedPriorityOptions.indexOf(n);a&&c!==-1&&(u(n)?this.getRandomOptionButton(c):this.getChampionOptionButton(n,c)),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.positionMenuTargetOption=null,document.removeEventListener("pointerdown",this.handlePositionMenuOutsidePointerDown,!0),document.removeEventListener("keydown",this.handlePositionMenuKeyDown,!0))}startDrag(t,e){var s;if(t.button===Ot){t.preventDefault();return}if(t.button!==Me)return;this.dragState&&this.clearDragState();const n=C(e),i=n?this.optionButtons.get(n):null;if(i){this.dragState={option:e,pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,active:!1,moved:!1};try{(s=i.setPointerCapture)==null||s.call(i,t.pointerId)}catch{}window.addEventListener("pointermove",this.handleWindowPointerMove),window.addEventListener("pointerup",this.handleWindowPointerUp),window.addEventListener("pointercancel",this.handleWindowPointerCancel)}}removePriorityOptionOnMiddleClick(t,e){t.button===Ot&&(t.preventDefault(),t.stopPropagation(),this.removePriorityOption(e))}moveDrag(t){var O;if(!this.dragState||this.dragState.pointerId!==t.pointerId)return;const e=this.dragState.option,n=C(e),i=t.clientX-this.dragState.startX,s=t.clientY-this.dragState.startY,r=Math.hypot(i,s);if(!this.dragState.active){if(r<xe)return;this.dragState.active=!0,n&&((O=this.optionButtons.get(n))==null||O.classList.add("champion-priority-selector__icon--dragging"))}t.preventDefault();const a=this.getDropIndex(t.clientX,e),c=this.selectedPriorityOptions.indexOf(e);if(a===c||a===-1)return;const d=this.getIconPositions();this.movePriorityOptionToIndex(e,a)&&(this.dragState.moved=!0,this.renderSelectedPriorityOptions(d,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 s;if(!this.dragState)return;const{option:t,pointerId:e}=this.dragState,n=C(t),i=n?this.optionButtons.get(n):null;i==null||i.classList.remove("champion-priority-selector__icon--dragging");try{(s=i==null?void 0:i.releasePointerCapture)==null||s.call(i,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.selectedPriorityOptions.filter(i=>i!==e);for(let i=0;i<n.length;i++){const s=C(n[i]),r=s?this.optionButtons.get(s):null;if(!r)continue;const a=r.getBoundingClientRect();if(t<a.left+a.width/2)return i}return n.length}getIconPositions(){const t=new Map;for(const e of this.selectedPriorityOptions){const n=C(e),i=n?this.optionButtons.get(n):null;i&&t.set(n,i.getBoundingClientRect())}return t}animateReorder(t,e){for(const n of this.selectedPriorityOptions){if(n===e)continue;const i=C(n),s=i?this.optionButtons.get(i):null,r=i?t.get(i):null;if(!s||!r||typeof s.animate!="function")continue;const a=s.getBoundingClientRect(),c=r.left-a.left,d=r.top-a.top;c===0&&d===0||s.animate([{transform:`translate(${c}px, ${d}px)`},{transform:"translate(0, 0)"}],{duration:Fe,easing:Be})}}}const Ne=200,K="auto-select-champ-select-menu--collapsed",De="auto-select-champ-select-menu-button-wrapper--open";class V{constructor(t,e){this.element=document.createElement(y.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=Ft(this.configKey),this.element.toggleAttribute("selected",this.config.enabled===!0)}toggle(){return console.debug("auto-champion-select: Toggling",this.configKey),this.config=z(this.configKey,t=>(t.enabled=!t.enabled,t)),this.element.toggleAttribute("selected",this.config.enabled===!0),this.config.enabled}}class $e{constructor(t,e,n){this.element=document.createElement("div"),this.element.classList.add("auto-select-champ-select-menu",K),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(K)}setOpen(t){this.element.classList.toggle(K,!t),this.buttonWrapper.classList.toggle(De,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=J();for(;this.mounted&&!t;)await S(Ne),t=J();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 qe{constructor(t,...e){this.element=document.createElement(y.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")}}function Yt(o){var t,e;o&&((e=(t=globalThis.Toast)==null?void 0:t.success)==null||e.call(t,o))}function et(o){var t,e;o&&((e=(t=globalThis.Toast)==null?void 0:t.error)==null||e.call(t,o))}function ze(o,t){const e=globalThis.Toast;return typeof(e==null?void 0:e.promise)=="function"?e.promise(o,t):o}const R="Balaclava: Auto Champion Select";function Ue(o){return typeof(o==null?void 0:o.then)=="function"}class rt{constructor({id:t,name:e,legend:n,tags:i,group:s,callback:r,toasts:a}){this.id=t,this.name=e,this.legend=n,this.tags=i,this.group=s,this.perform=this.perform.bind(this),this.callback=r,this.toasts=a}perform(){try{const t=this.callback();if(Ue(t))return ze(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);Yt(e)}catch(t){et(this.toasts.error),console.error(t)}}}class Gt extends rt{constructor(t,e,n){super({id:`${e}Switch`,name:()=>`Auto ${t} [${A(e).enabled?"ON":"OFF"}]`,legend:()=>A(e).enabled?"Turn OFF":"Turn ON",tags:[R,e,"switch"],group:R,callback:n,toasts:{on:`Auto ${t} is ON!`,off:`Auto ${t} is OFF!`,error:`Failed to toggle Auto ${t}. Check console.`}})}}function Ye(o){return z(o,e=>(e.force=!e.force,e)).force}class Ht extends rt{constructor(t,e){super({id:`${e}ForceSwitch`,name:()=>`Force ${t} [${A(e).force?"ON":"OFF"}]`,legend:()=>`Ignore team intent and force ${t} the selected champion`,tags:[R,e,"force","switch"],group:R,callback:()=>Ye(e),toasts:{on:`Force ${t} is ON!`,off:`Force ${t} is OFF!`,error:`Failed to toggle Force ${t}. Check console.`}})}}class Ge extends rt{constructor(t){super({id:"RefreshDropdowns",name:()=>"Refresh Champions",legend:()=>"Normally champion selectors refresh automatically...",tags:[R,"refresh"],group:R,callback:t,toasts:{success:"Refreshed Champions!",error:"Failed to refresh Champions. Check console."}})}}class He extends Gt{constructor(t){super("Pick","controladoPick",t)}}class Qe extends Gt{constructor(t){super("Ban","controladoBan",t)}}class je extends Ht{constructor(){super("Pick","controladoPick")}}class We extends Ht{constructor(){super("Ban","controladoBan")}}function Ke(o){for(const t of o)CommandBar.addAction(t)}const Ve=200,Xe=6e4,It=2e3,Je=".ready-check-root-element",Ze="#lol-uikit-layer-manager-wrapper > .modal",tn="Accepted ready check!",Tt="Failed to accept ready check. Check console.",en=".auto-select-champ-select-menu__header",k=Object.freeze({autoAccept:"controladoAutoAccept",pick:"controladoPick",ban:"controladoBan"});function Qt(){return A(k.autoAccept).enabled===!0}class nn{constructor(t){this.isEnabled=t,this.observer=null,this.hiddenModal=null,this.hiddenModalStyles=new WeakMap,this.sync=this.sync.bind(this)}start(){this.observer||(this.observer=new MutationObserver(()=>this.sync()),this.observer.observe(document.body,{childList:!0,subtree:!0}),this.sync())}sync(){const t=on();if(!t){this.restore();return}if(!this.isEnabled()){this.restore();return}this.hide(t)}hide(t){this.hiddenModal!==t&&(this.restore(),this.hiddenModal=t,this.hiddenModalStyles.set(t,{display:t.style.getPropertyValue("display"),displayPriority:t.style.getPropertyPriority("display"),pointerEvents:t.style.getPropertyValue("pointer-events"),pointerEventsPriority:t.style.getPropertyPriority("pointer-events")}),t.style.setProperty("display","none","important"),t.style.setProperty("pointer-events","none","important"))}restore(){if(!this.hiddenModal)return;const t=this.hiddenModal,e=this.hiddenModalStyles.get(t);_t(t,"display",e==null?void 0:e.display,e==null?void 0:e.displayPriority),_t(t,"pointer-events",e==null?void 0:e.pointerEvents,e==null?void 0:e.pointerEventsPriority),this.hiddenModalStyles.delete(t),this.hiddenModal=null}}function on(){const o=document.querySelector(Je);return(o==null?void 0:o.closest(Ze))||null}function _t(o,t,e,n){e?o.style.setProperty(t,e,n||""):o.style.removeProperty(t)}async function sn(o){function t(){return Qt()?!1:(o.restore(),!0)}if(t()||(console.debug(`auto-champion-select(auto-accept): Ready check detected, accepting in ${It}ms...`),await S(It),t()))return;let e=!1;try{e=await rn()}catch(n){throw o.restore(),et(Tt),n}e?Yt(tn):(o.restore(),et(Tt))}async function rn(){const o=await P("POST",p.readyCheckAccept);return o.ok?(console.debug("auto-champion-select(auto-accept): Accepted ready check"),!0):(console.error("auto-champion-select(auto-accept): Failed to accept ready check",o),!1)}async function an(o){const t=await P("GET",p.gameflowPhase),e=t.ok?await t.json():null;o.handleGameflowPhase(e)}function cn({championSelect:o,champSelectControlsMenu:t,readyCheckModalSuppressor:e,setupChampionSelectors:n}){let i=0;return async function(c){const d=++i;try{await s(c,d)}catch(O){console.error("auto-champion-select: Failed to handle gameflow phase",O)}};async function s(a,c){a==="ReadyCheck"?sn(e).catch(d=>{console.error("auto-champion-select(auto-accept): Failed to handle ready check",d)}):e.restore(),await r(a),c===i&&await n()}async function r(a){a==="ChampSelect"?(o.mount(),await t.mount()):(o.unmount(),await t.unmount())}}function ln(){const o=new Ae,t=new V("Accept",k.autoAccept),e=new V("Pick",k.pick),n=new Et("Add pick",k.pick,fe,{enablePositionRestrictions:!0,quickActionLabel:"Pick instantly",enableRandomPositionFilters:!0,randomOptionDescription:"Uses assigned role unless lanes selected"}),i=new V("Ban",k.ban),s=new Et("Add ban",k.ban,Nt,{quickActionLabel:"Ban instantly",enableRandomPositionFilters:!0,randomOptionDescription:"Can filter lanes"}),r=dn(n,s),a=hn(t,e,i),c=new qe("Auto champion select",r,a);return{championSelect:o,autoAcceptToggle:t,pickToggle:e,banToggle:i,pickChampionSelector:n,banChampionSelector:s,selectorsContainer:r,checkboxesContainer:a,pluginSection:c,championSelectors:[n,s]}}function dn(...o){const t=document.createElement("div");return t.append(...o.map(e=>e.element)),t}function hn(...o){const t=document.createElement("div");return t.classList.add("auto-select-checkboxes-div"),t.append(...o.map(e=>e.element)),t}function un({pluginSection:o,checkboxesContainer:t,selectorsContainer:e}){let n=null,i=0,s=()=>!1;async function r(a){let c=mt();for(;!c;){if(s()||a!==i)return;await S(Ve),c=mt()}s()||a!==i||c.append(o.element,t,e)}return{setIsChampSelectControlsMounted(a){s=a},returnControlsToSocialRoster(){if(n)return n;const a=++i;return n=r(a).catch(c=>console.error("auto-champion-select: Failed to return controls to social roster",c)).finally(()=>{n=null}),n}}}function pn({autoAcceptToggle:o,pickToggle:t,banToggle:e,readyCheckModalSuppressor:n}){o.setup(),o.element.addEventListener("click",()=>n.sync()),t.setup(),e.setup()}async function mn(o){await Promise.all(o.map(t=>t.setup()))}async function fn(o){await Promise.all(o.map(t=>t.refresh()))}function gn(){const o=ln(),t=new nn(Qt),e=un(o),n=new $e("Auto Champion Select",e.returnControlsToSocialRoster,[o.checkboxesContainer,o.selectorsContainer]);e.setIsChampSelectControlsMounted(()=>n.mounted);const i={...o,champSelectControlsMenu:n,readyCheckModalSuppressor:t,setupToggles:()=>pn({...o,readyCheckModalSuppressor:t}),setupChampionSelectors:()=>mn(o.championSelectors),refreshChampionSelectors:()=>fn(o.championSelectors),refreshPickChampionSelector:async()=>{await o.pickChampionSelector.refresh()}};return i.handleGameflowPhase=cn(i),i}function Pn(o){at(p.gameflowPhase,t=>{o.handleGameflowPhase(t.data)}),at(p.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 yn({pickToggle:o,banToggle:t,refreshChampionSelectors:e}){Ke([new He(()=>o.toggle()),new Qe(()=>t.toggle()),new je,new We,new Ge(e)])}function Cn(o){let t=null,e=null;function n(){e==null||e.disconnect(),e=null,t!==null&&(cancelAnimationFrame(t),t=null)}const i=setTimeout(()=>{n()},Xe);function s(){if(!(J()!==null))return;clearTimeout(i),n(),document.querySelector(en)!==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 bn(){const o=gn();o.setupToggles(),o.readyCheckModalSuppressor.start(),yn(o),Pn(o),await an(o),Cn(o),console.debug(`auto-champion-select(${jt}): Report bugs to Balaclava#1912`)}let kt=!1;function Lt(){kt||(kt=!0,bn().catch(o=>console.error("auto-champion-select: Failed to initialize",o)))}document.readyState==="loading"?window.addEventListener("load",Lt,{once:!0}):Lt();export{Lt as load};
|
|
231
|
+
`;function W(o){const t=document.createElement(A.dropdownOption);return t.setAttribute("slot",A.dropdownOption),t.innerText=o,t}class ve{constructor(t,e,n,i={}){this.dropdownElement=t,this.placeholderText=e,this.searchPlaceholderText=i.searchPlaceholderText||"Search",this.quickActionLabel=i.quickActionLabel||"Pick/ban instantly",this.staticOptions=Array.isArray(i.staticOptions)?i.staticOptions:[],this.isQuickActionEnabled=typeof i.isQuickActionEnabled=="function"?i.isQuickActionEnabled:null,this.onQuickActionToggle=typeof i.onQuickActionToggle=="function"?i.onQuickActionToggle:null,this.onPriorityOptionSelected=n,this.placeholderOption=null,this.searchQuery="",this.activePositionFilter=null,this.hasRecommendedPositionData=!1,this.recommendedPositionsByOption=new WeakMap,this.staticOptionElements=new WeakSet}renderOptions(t){this.dropdownElement.replaceChildren(),this.hasRecommendedPositionData=!1,this.staticOptionElements=new WeakSet,this.placeholderOption=W(this.placeholderText),this.placeholderOption.setAttribute("selected","true"),this.hidePlaceholderOption(),this.dropdownElement.appendChild(this.placeholderOption);for(const e of this.staticOptions)this.dropdownElement.appendChild(this.createStaticOption(e));for(const e of t){const n=this.getChampionRecommendedPositions(e),i=this.createChampionOption(e,n);n.length>0&&(this.hasRecommendedPositionData=!0),this.dropdownElement.appendChild(i)}this.hasRecommendedPositionData||(this.activePositionFilter=null),this.applyOptionFilters()}createChampionOption(t,e){const n=W("");return this.recommendedPositionsByOption.set(n,new Set(e)),n.title=t.name,n.appendChild(this.createChampionOptionContent(t)),n.addEventListener("click",()=>{this.onPriorityOptionSelected(t.id),requestAnimationFrame(()=>this.reset())}),n}createStaticOption(t){const e=W(""),n=typeof t.description=="string"?t.description:"";return this.staticOptionElements.add(e),e.title=n?`${t.label}. ${n}`:t.label,e.appendChild(this.createStaticOptionContent(t,n)),e.addEventListener("click",()=>{this.onPriorityOptionSelected(t.value),requestAnimationFrame(()=>this.reset())}),e}createChampionOptionContent(t){const e=document.createElement("span");e.classList.add(yt);const n=document.createElement("img");n.classList.add(Ct),n.src=t.squarePortraitPath,n.alt="",n.draggable=!1,n.loading="lazy";const i=document.createElement("span");return i.classList.add(bt),i.innerText=t.name,e.append(n,i),e}createStaticOptionContent(t,e=""){const n=document.createElement("span");n.classList.add(yt);const i=document.createElement("span");i.classList.add(Ct,Le),i.innerText=t.iconText||"?";const s=document.createElement("span");s.classList.add(bt),s.innerText=t.label;const r=document.createElement("span");if(r.classList.add(ke),r.appendChild(s),e){const a=document.createElement("span");a.classList.add(Re),a.innerText=e,r.appendChild(a)}return n.append(i,r),n}getChampionRecommendedPositions(t){return Array.isArray(t.recommendedPositions)?t.recommendedPositions:[]}async waitForRender(){for(let t=0;t<Ie;t++){const e=this.dropdownElement.shadowRoot;if(this.dropdownElement.isConnected&&(e!=null&&e.querySelector(c.dropdownCurrent)))return e;await O(Te)}return null}ensureSearchPlaceholder(t){if(t.querySelector(`#${gt}`))return;const e=t.querySelector(c.dropdownCurrent);e&&e.appendChild(this.createSearchPlaceholder())}ensureQuickActionToggle(t){if(!this.isQuickActionAvailable()||t.querySelector(`#${j}`)){this.syncQuickActionToggle(t);return}const e=t.querySelector(c.dropdownCurrent);e&&(e.appendChild(this.createQuickActionToggle()),this.syncQuickActionToggle(t))}ensurePositionFilter(t){var n;const e=t.querySelector(c.dropdownOptionsContainer);if(e){if(!this.hasRecommendedPositionData){(n=t.querySelector(`.${q}`))==null||n.remove(),e.classList.remove(Z),this.activePositionFilter=null;return}e.classList.add(Z),t.querySelector(`.${q}`)||e.insertBefore(this.createPositionFilter(),e.firstChild),this.syncPositionFilter(t)}}createPositionFilter(){const t=document.createElement("div");t.classList.add(q),t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Filter champions by position");for(const e of M)t.appendChild(this.createPositionFilterBadge(e));return t}createPositionFilterBadge(t){const e=document.createElement("button");e.classList.add(w),e.type="button",e.dataset.position=t.value,e.title=t.label,e.setAttribute("aria-label",t.label),e.setAttribute("aria-pressed","false");const n=document.createElement("img");return n.src=t.iconPath,n.alt="",n.draggable=!1,e.appendChild(n),e.addEventListener("pointerdown",i=>{i.preventDefault(),i.stopPropagation()}),e.addEventListener("click",i=>{i.preventDefault(),i.stopPropagation(),this.togglePositionFilter(t.value)}),e}createSearchPlaceholder(){const t=document.createElement("div");t.classList.add(Gt,zt),t.id=gt;const e=document.createElement("input");e.classList.add(qt),e.id=Pt,e.type="text",e.placeholder=this.searchPlaceholderText,e.setAttribute("aria-label",this.searchPlaceholderText),e.size=Math.max(this.searchPlaceholderText.length,1);const n=document.createElement("span");return n.classList.add(Yt),n.addEventListener("click",()=>{n.classList.contains(L)&&this.clearSearch(e,n)}),e.addEventListener("input",i=>{this.ensureOpen(),this.setSearchQuery(i.target.value),n.classList.toggle(L,!!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}createQuickActionToggle(){const t=document.createElement("button");return t.classList.add(D),t.id=j,t.type="button",t.title=this.quickActionLabel,t.setAttribute("aria-label",this.quickActionLabel),t.setAttribute("aria-pressed","false"),["pointerdown","click"].forEach(e=>{t.addEventListener(e,n=>{n.preventDefault(),n.stopPropagation()})}),t.addEventListener("click",()=>{var e;(e=this.onQuickActionToggle)==null||e.call(this),this.syncQuickActionToggle()}),t}isQuickActionAvailable(){return!!(this.isQuickActionEnabled&&this.onQuickActionToggle)}syncQuickActionToggle(t=this.dropdownElement.shadowRoot){if(!this.isQuickActionAvailable()||!t)return;const e=t.querySelector(`#${j}`);if(!e)return;const n=this.isQuickActionEnabled()===!0;e.classList.toggle(Ut,n),e.setAttribute("aria-pressed",String(n)),e.title=this.quickActionLabel,e.setAttribute("aria-label",this.quickActionLabel)}togglePositionFilter(t){const e=N(t);e&&(this.activePositionFilter=this.activePositionFilter===e?null:e,this.withShadowRoot(n=>this.syncPositionFilter(n)),this.applyOptionFilters())}syncPositionFilter(t){t.querySelectorAll(`.${w}`).forEach(e=>{const n=e.dataset.position===this.activePositionFilter;e.classList.toggle(tt,n),e.setAttribute("aria-pressed",String(n))})}clearSearch(t,e){t.value="",this.setSearchQuery(""),e.classList.toggle(L,!1)}setSearchQuery(t){this.searchQuery=t,this.applyOptionFilters()}applyOptionFilters(){const t=this.searchQuery.toLowerCase();this.dropdownElement.querySelectorAll(c.dropdownOption).forEach(n=>{if(n===this.placeholderOption){this.hidePlaceholderOption();return}this.matchesSearchQuery(n,t)&&this.matchesPositionFilter(n)?n.style.display="":n.style.display="none"})}matchesSearchQuery(t,e){return(t.textContent??"").toLowerCase().includes(e)}matchesPositionFilter(t){var e;return this.staticOptionElements.has(t)||!this.activePositionFilter?!0:((e=this.recommendedPositionsByOption.get(t))==null?void 0:e.has(this.activePositionFilter))===!0}hidePlaceholderOption(){this.placeholderOption&&(this.placeholderOption.style.display="none")}reset(){var t;this.dropdownElement.querySelectorAll(c.dropdownOptionSelected).forEach(e=>{e.removeAttribute("selected")}),(t=this.placeholderOption)==null||t.setAttribute("selected","true"),this.withShadowRoot(e=>{var s;const n=e.querySelector(`#${Pt}`),i=e.querySelector(`.${L}`);n&&i?this.clearSearch(n,i):(n&&(n.value="",this.setSearchQuery("")),i&&i.classList.remove(L)),this.isOpen()&&((s=e.querySelector(c.dropdownCurrent))==null||s.click())})}isOpen(){return this.dropdownElement.classList.contains("active")}ensureOpen(){this.isOpen()||this.withShadowRoot(t=>{const e=t.querySelector(c.dropdownCurrent);e&&e.click()})}patchDropdownShadowDom(){this.withShadowRoot(t=>{this.ensureDropdownOpensUpward(t),this.injectDropdownSearchStyles(t),this.ensurePositionFilter(t)})}ensureDropdownOpensUpward(t){var e;(e=t.querySelector(c.dropdownRoot))==null||e.classList.add("opens-upward")}injectDropdownSearchStyles(t){const e=t.querySelector("style[data-controlado='dropdown-tags']");if(e){e.textContent=At;return}const n=document.createElement("style");n.dataset.controlado="dropdown-tags",n.textContent=At,t.appendChild(n)}withShadowRoot(t){const e=this.dropdownElement.shadowRoot;e&&t(e)}}const Me=".champion-priority-selector__position-badge",Fe=".champion-priority-selector__position-option",St=".champion-priority-selector__remove",wt="✕",Ot="?",x="Random",Ne=0,Et=1,$=8,h=Object.freeze({CHAMPION_ASSIGNED:"champion-assigned",RANDOM_ASSIGNED:"random-assigned",RANDOM_POOL:"random-pool"}),xe=5,De=150,Be="cubic-bezier(0.2, 0, 0, 1)";class It{constructor(t,e,n,i={}){this.element=this.createRootElement(),this.dropdownElement=this.createDropdownElement(),this.championDropdown=new ve(this.dropdownElement,t,a=>this.addPriorityOption(a),{quickActionLabel:i.quickActionLabel,searchPlaceholderText:i.searchPlaceholderText,staticOptions:[{value:y,label:x,description:i.randomOptionDescription,iconText:Ot}],isQuickActionEnabled:()=>this.isQuickActionEnabled(),onQuickActionToggle:()=>this.toggleQuickAction()});const{scrollElement:s,trackElement:r}=this.createSelectedChampionsScroll();this.scrollElement=s,this.trackElement=r,this.enablePositionRestrictions=i.enablePositionRestrictions===!0,this.enableRandomPoolPositionFilters=i.enableRandomPoolPositionFilters===!0,this.enableRandomAssignedPositionRestrictions=i.enableRandomAssignedPositionRestrictions===!0,this.enablePositionMenu=this.enablePositionRestrictions||this.enableRandomAssignedPositionRestrictions||this.enableRandomPoolPositionFilters,this.positionMenuElement=this.enablePositionMenu?this.createPositionMenu():null,this.positionMenuTarget=null,this.positionsByChampionId={},this.randomAssignedPositions=[],this.randomPoolPositions=[],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.quickAction=!1,this.loadChampions=n,this.champions=[],this.championById=new Map,this.selectedPriorityOptions=[],this.optionButtons=new Map,this.dragState=null,this.handleWindowPointerMove=a=>this.moveDrag(a),this.handleWindowPointerUp=a=>this.finishDrag(a),this.handleWindowPointerCancel=a=>this.cancelDrag(a),this.handlePositionMenuOutsidePointerDown=a=>this.closePositionMenuOnOutsidePointerDown(a),this.handlePositionMenuKeyDown=a=>this.closePositionMenuOnKeyDown(a),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(A.dropdown);return t.classList.add("dropdown-champions-default","dropdown-drop-up"),t}createSelectedChampionsScroll(){const t=document.createElement(A.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 M)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.togglePositionMenuPosition(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=Dt(this.configKey,{allowedChampionIds:t}),this.quickAction=this.config.quickAction===!0,this.selectedPriorityOptions=nt(this.config.priorityOptions||this.config.champions,t),this.enablePositionRestrictions&&(this.positionsByChampionId=z(this.config.positionsByChampionId,R(this.selectedPriorityOptions))),this.enableRandomAssignedPositionRestrictions&&(this.randomAssignedPositions=C(this.config.randomAssignedPositions)),this.enableRandomPoolPositionFilters&&(this.randomPoolPositions=C(this.config.randomPoolPositions)),this.championDropdown.renderOptions(this.champions),this.renderSelectedPriorityOptions();const e=await this.championDropdown.waitForRender();e&&(this.championDropdown.ensureSearchPlaceholder(e),this.championDropdown.ensureQuickActionToggle(e),this.championDropdown.patchDropdownShadowDom())}getAllowedChampionIds(){return new Set(this.championById.keys())}isQuickActionEnabled(){return this.quickAction===!0}toggleQuickAction(){const t=this.getAllowedChampionIds();return this.config=U(this.configKey,e=>(e.quickAction=e.quickAction!==!0,e),{allowedChampionIds:t,selectedChampionIds:R(this.selectedPriorityOptions)}),this.quickAction=this.config.quickAction===!0,this.championDropdown.syncQuickActionToggle(),this.quickAction}addPriorityOption(t){const e=E(t);e===null||this.selectedPriorityOptions.includes(e)||!u(e)&&!this.championById.has(e)||(this.selectedPriorityOptions.push(e),this.renderSelectedPriorityOptions(),this.saveConfig())}removePriorityOption(t){var s;const e=E(t),n=this.selectedPriorityOptions.indexOf(e);if(e===null||n===-1)return;this.selectedPriorityOptions.splice(n,1);const i=u(e)?null:e;((s=this.positionMenuTarget)==null?void 0:s.option)===e&&this.closePositionMenu(),this.enablePositionRestrictions&&i!==null&&delete this.positionsByChampionId[String(i)],this.enableRandomAssignedPositionRestrictions&&u(e)&&(this.randomAssignedPositions=[]),this.enableRandomPoolPositionFilters&&u(e)&&(this.randomPoolPositions=[]),this.renderSelectedPriorityOptions(),this.saveConfig()}movePriorityOptionToIndex(t,e){const n=E(t),i=this.selectedPriorityOptions.indexOf(n);if(n===null||i===-1)return!1;const[s]=this.selectedPriorityOptions.splice(i,1),r=Math.max(0,Math.min(e,this.selectedPriorityOptions.length));return this.selectedPriorityOptions.splice(r,0,s),i!==r}syncPositionsByChampionId(){this.enablePositionRestrictions&&(this.positionsByChampionId=z(this.positionsByChampionId,R(this.selectedPriorityOptions)))}syncRandomPoolPositions(){this.enableRandomPoolPositionFilters&&(this.randomPoolPositions=C(this.randomPoolPositions))}syncRandomAssignedPositions(){this.enableRandomAssignedPositionRestrictions&&(this.randomAssignedPositions=C(this.randomAssignedPositions))}saveConfig(){this.syncPositionsByChampionId(),this.syncRandomAssignedPositions(),this.syncRandomPoolPositions();const t=this.getAllowedChampionIds();this.config=U(this.configKey,e=>(e.priorityOptions=[...this.selectedPriorityOptions],e.champions=R(this.selectedPriorityOptions),this.enableRandomAssignedPositionRestrictions&&(e.randomAssignedPositions=[...this.randomAssignedPositions]),this.enableRandomPoolPositionFilters&&(e.randomPoolPositions=[...this.randomPoolPositions]),this.enablePositionRestrictions&&(e.positionsByChampionId={...this.positionsByChampionId}),e),{allowedChampionIds:t,selectedChampionIds:R(this.selectedPriorityOptions)}),this.enablePositionRestrictions&&(this.positionsByChampionId=this.config.positionsByChampionId||{}),this.enableRandomAssignedPositionRestrictions&&(this.randomAssignedPositions=this.config.randomAssignedPositions||[]),this.enableRandomPoolPositionFilters&&(this.randomPoolPositions=this.config.randomPoolPositions||[]),console.debug(this.configKey,this.config)}renderSelectedPriorityOptions(t=null,e=null){this.positionMenuTarget!==null&&this.closePositionMenu();const n=new Set(this.selectedPriorityOptions.map(s=>S(s)));for(const[s,r]of this.optionButtons)n.has(s)||(r.remove(),this.optionButtons.delete(s));if(this.selectedPriorityOptions.length===0){this.trackElement.replaceChildren(this.emptyElement);return}this.emptyElement.remove();const i=this.selectedPriorityOptions.map((s,r)=>this.getPriorityOptionButton(s,r)).filter(Boolean);this.trackElement.append(...i),t&&this.animateReorder(t,e)}getPriorityOptionButton(t,e){return u(t)?this.getRandomOptionButton(e):this.getChampionOptionButton(t,e)}getChampionOptionButton(t,e){const n=this.championById.get(t);if(!n)return null;const i=String(t);let s=this.optionButtons.get(i);s||(s=this.createIconButton(n),this.optionButtons.set(i,s)),s.dataset.rank=String(e+1),s.classList.toggle("champion-priority-selector__icon--random",!1);const r=this.getChampionPositionTitleSuffix(t);s.title=`${e+1}. ${n.name}${r}`,s.setAttribute("aria-label",`${e+1}. ${n.name}${r}`);const a=s.querySelector("img");a.src=n.squarePortraitPath,a.alt=n.name;const l=s.querySelector(St);return l.setAttribute("aria-label",`Remove ${n.name}`),l.title=`Remove ${n.name}`,this.renderPositionBadge(s,t),s}getRandomOptionButton(t){let e=this.optionButtons.get(y);e||(e=this.createRandomOptionButton(),this.optionButtons.set(y,e)),e.dataset.rank=String(t+1);const n=this.getRandomPositionTitleSuffix();e.title=`${t+1}. ${x}${n}`,e.setAttribute("aria-label",`${t+1}. ${x}${n}`);const i=e.querySelector(St);return i.setAttribute("aria-label",`Remove ${x}`),i.title=`Remove ${x}`,this.renderPositionBadge(e,y),e}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");if(i.classList.add("champion-priority-selector__remove"),i.type="button",i.dataset.icon=wt,i.addEventListener("pointerdown",s=>s.stopPropagation()),i.addEventListener("click",s=>{s.stopPropagation(),this.removePriorityOption(t.id)}),e.addEventListener("pointerdown",s=>this.startDrag(s,t.id)),e.addEventListener("auxclick",s=>this.removePriorityOptionOnMiddleClick(s,t.id)),this.enablePositionRestrictions){const s={option:t.id,kind:h.CHAMPION_ASSIGNED};e.addEventListener("contextmenu",r=>this.openPositionMenu(r,s))}return e.append(n,i),e}createRandomOptionButton(){const t=document.createElement("div");t.classList.add("champion-priority-selector__icon","champion-priority-selector__icon--random"),t.setAttribute("role","button"),t.tabIndex=0;const e=document.createElement("span");e.classList.add("champion-priority-selector__random-icon"),e.innerText=Ot;const n=document.createElement("button");if(n.classList.add("champion-priority-selector__remove"),n.type="button",n.dataset.icon=wt,n.addEventListener("pointerdown",i=>i.stopPropagation()),n.addEventListener("click",i=>{i.stopPropagation(),this.removePriorityOption(y)}),t.addEventListener("pointerdown",i=>this.startDrag(i,y)),t.addEventListener("auxclick",i=>this.removePriorityOptionOnMiddleClick(i,y)),this.enableRandomPoolPositionFilters){const i={option:y,kind:h.RANDOM_POOL};t.addEventListener("contextmenu",s=>this.openPositionMenu(s,i))}return t.append(e,n),t}getChampionAllowedPositions(t){const e=p(t);return e===null?[]:this.positionsByChampionId[String(e)]||[]}getRandomPoolPositions(){return this.randomPoolPositions}getRandomAssignedPositions(){return this.randomAssignedPositions}getPositionLabels(t){return t.map(e=>{var n;return(n=lt(e))==null?void 0:n.label}).filter(Boolean)}getChampionAllowedPositionLabels(t){return this.getPositionLabels(this.getChampionAllowedPositions(t))}getRandomPoolPositionLabels(){return this.getPositionLabels(this.getRandomPoolPositions())}getRandomAssignedPositionLabels(){return this.getPositionLabels(this.getRandomAssignedPositions())}getChampionPositionTitleSuffix(t){const e=this.getChampionAllowedPositionLabels(t);return e.length>0?` (${e.join(", ")})`:""}getRandomPositionTitleSuffix(){const t=[],e=this.getRandomAssignedPositionLabels(),n=this.getRandomPoolPositionLabels();return e.length>0&&t.push(`runs only when assigned lane matches ${this.formatPositionLabelsForSentence(e)}`),n.length>0&&t.push(`filters random pool to ${this.formatPositionLabelsForSentence(n)}`),t.length>0?` (${t.join("; ")})`:""}formatPositionLabelsForSentence(t){return t.length<=1?t[0]||"":t.length===2?`${t[0]} or ${t[1]}`:`${t.slice(0,-1).join(", ")}, or ${t[t.length-1]}`}renderPositionBadge(t,e){t.querySelectorAll(Me).forEach(i=>i.remove());const n=E(e);if(n!==null)for(const i of this.getPositionBadgeTargetsForOption(n)){const s=this.createPositionBadge(i);s&&t.appendChild(s)}}getPositionBadgeTargetsForOption(t){return this.selectedPriorityOptions.includes(t)?u(t)?[{option:t,kind:h.RANDOM_ASSIGNED},{option:t,kind:h.RANDOM_POOL}].filter(e=>this.canOpenPositionMenuForTarget(e)):[{option:t,kind:h.CHAMPION_ASSIGNED}].filter(e=>this.canOpenPositionMenuForTarget(e)):[]}createPositionBadge(t){const e=this.getAllowedPositionsForPositionMenuTarget(t),n=this.getAllowedPositionLabelsForPositionMenuTarget(t),i=t.kind===h.RANDOM_POOL,s=document.createElement("button");if(s.classList.add("champion-priority-selector__position-badge"),s.classList.toggle("champion-priority-selector__position-badge--random",i),s.type="button",s.dataset.positionTarget=t.kind,s.title=this.getPositionBadgeTitle(n,t),s.setAttribute("aria-label",s.title),s.addEventListener("pointerdown",l=>l.stopPropagation()),s.addEventListener("click",l=>this.openPositionMenu(l,t,s)),i)return e.length>0?(s.classList.add("champion-priority-selector__position-badge--active"),s.dataset.count=String(e.length)):s.classList.add("champion-priority-selector__position-badge--empty"),s;if(e.length===0)return s.classList.add("champion-priority-selector__position-badge--empty"),s.innerText="+",s;const r=lt(e[0]);if(!r)return null;e.length>1&&(s.dataset.count=String(e.length));const a=document.createElement("img");return a.src=r.iconPath,a.alt=r.label,a.draggable=!1,s.appendChild(a),s}getPositionBadgeTitle(t,e){return e.kind===h.RANDOM_ASSIGNED?t.length===0?"The plugin can use Random in any lane. Click to run it only in selected draft lanes.":`The plugin will use Random only when your assigned lane matches ${this.formatPositionLabelsForSentence(t)}. Draft modes only. Click to edit.`:e.kind===h.RANDOM_POOL?t.length===0?"The plugin can choose any available champion at random. Click to filter the pool first.":`The plugin filters Random to champions for ${this.formatPositionLabelsForSentence(t)}, then picks one. Click to edit.`:t.length>0?`The plugin will pick this champion only when your assigned lane matches ${this.formatPositionLabelsForSentence(t)}. Draft modes only. Click to edit.`:"The plugin can pick this champion in any lane. Click to limit it to selected draft lanes."}canOpenPositionMenuForTarget(t){if(!this.selectedPriorityOptions.includes(t.option))return!1;switch(t.kind){case h.CHAMPION_ASSIGNED:return!u(t.option)&&this.enablePositionRestrictions;case h.RANDOM_ASSIGNED:return u(t.option)&&this.enableRandomAssignedPositionRestrictions;case h.RANDOM_POOL:return u(t.option)&&this.enableRandomPoolPositionFilters;default:return!1}}normalizePositionMenuTarget(t){if(!t||typeof t!="object"||Array.isArray(t)||!("option"in t)||!("kind"in t))return null;const e=E(t.option),n=e===null?null:{option:e,kind:String(t.kind)};return n&&this.canOpenPositionMenuForTarget(n)?n:null}getAllowedPositionsForPositionMenuTarget(t){switch(t.kind){case h.CHAMPION_ASSIGNED:return this.getChampionAllowedPositions(t.option);case h.RANDOM_ASSIGNED:return this.getRandomAssignedPositions();case h.RANDOM_POOL:return this.getRandomPoolPositions();default:return[]}}getAllowedPositionLabelsForPositionMenuTarget(t){return this.getPositionLabels(this.getAllowedPositionsForPositionMenuTarget(t))}setAllowedPositionsForPositionMenuTarget(t,e){switch(t.kind){case h.CHAMPION_ASSIGNED:{const n=String(t.option);e.length>0?this.positionsByChampionId[n]=e:delete this.positionsByChampionId[n];break}case h.RANDOM_ASSIGNED:this.randomAssignedPositions=e;break;case h.RANDOM_POOL:this.randomPoolPositions=e;break}}openPositionMenu(t,e,n=null){if(!this.positionMenuElement)return;const i=this.normalizePositionMenuTarget(e);if(i===null)return;t.preventDefault(),t.stopPropagation(),this.positionMenuTarget=i,this.renderPositionMenu(),this.positionMenuElement.hidden=!1,this.positionMenuElement.style.left="0px",this.positionMenuElement.style.top="0px";const{left:s,top:r}=this.getPositionMenuCoordinates(t,n);this.positionMenuElement.style.left=`${s}px`,this.positionMenuElement.style.top=`${r}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 l=e.getBoundingClientRect();i=l.left+l.width/2,s=l.bottom}const r=Math.min(Math.max(i,$),window.innerWidth-n.width-$),a=Math.min(Math.max(s,$),window.innerHeight-n.height-$);return{left:r,top:a}}renderPositionMenu(){if(!this.positionMenuElement||this.positionMenuTarget===null)return;const t=new Set(this.getAllowedPositionsForPositionMenuTarget(this.positionMenuTarget));this.positionMenuElement.querySelectorAll(Fe).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))})}togglePositionMenuPosition(t){if(!this.positionMenuElement||this.positionMenuTarget===null)return;const e=N(t);if(!e)return;const n=this.positionMenuTarget,i=n.option,s=new Set(this.getAllowedPositionsForPositionMenuTarget(n));s.has(e)?s.delete(e):s.add(e);const r=M.map(f=>f.value).filter(f=>s.has(f));this.setAllowedPositionsForPositionMenuTarget(n,r),this.renderPositionMenu();const a=S(i),l=a?this.optionButtons.get(a):null,d=this.selectedPriorityOptions.indexOf(i);l&&d!==-1&&(u(i)?this.getRandomOptionButton(d):this.getChampionOptionButton(i,d)),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.positionMenuTarget=null,document.removeEventListener("pointerdown",this.handlePositionMenuOutsidePointerDown,!0),document.removeEventListener("keydown",this.handlePositionMenuKeyDown,!0))}startDrag(t,e){var s;if(t.button===Et){t.preventDefault();return}if(t.button!==Ne)return;this.dragState&&this.clearDragState();const n=S(e),i=n?this.optionButtons.get(n):null;if(i){this.dragState={option:e,pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,active:!1,moved:!1};try{(s=i.setPointerCapture)==null||s.call(i,t.pointerId)}catch{}window.addEventListener("pointermove",this.handleWindowPointerMove),window.addEventListener("pointerup",this.handleWindowPointerUp),window.addEventListener("pointercancel",this.handleWindowPointerCancel)}}removePriorityOptionOnMiddleClick(t,e){t.button===Et&&(t.preventDefault(),t.stopPropagation(),this.removePriorityOption(e))}moveDrag(t){var f;if(!this.dragState||this.dragState.pointerId!==t.pointerId)return;const e=this.dragState.option,n=S(e),i=t.clientX-this.dragState.startX,s=t.clientY-this.dragState.startY,r=Math.hypot(i,s);if(!this.dragState.active){if(r<xe)return;this.dragState.active=!0,n&&((f=this.optionButtons.get(n))==null||f.classList.add("champion-priority-selector__icon--dragging"))}t.preventDefault();const a=this.getDropIndex(t.clientX,e),l=this.selectedPriorityOptions.indexOf(e);if(a===l||a===-1)return;const d=this.getIconPositions();this.movePriorityOptionToIndex(e,a)&&(this.dragState.moved=!0,this.renderSelectedPriorityOptions(d,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 s;if(!this.dragState)return;const{option:t,pointerId:e}=this.dragState,n=S(t),i=n?this.optionButtons.get(n):null;i==null||i.classList.remove("champion-priority-selector__icon--dragging");try{(s=i==null?void 0:i.releasePointerCapture)==null||s.call(i,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.selectedPriorityOptions.filter(i=>i!==e);for(let i=0;i<n.length;i++){const s=S(n[i]),r=s?this.optionButtons.get(s):null;if(!r)continue;const a=r.getBoundingClientRect();if(t<a.left+a.width/2)return i}return n.length}getIconPositions(){const t=new Map;for(const e of this.selectedPriorityOptions){const n=S(e),i=n?this.optionButtons.get(n):null;i&&t.set(n,i.getBoundingClientRect())}return t}animateReorder(t,e){for(const n of this.selectedPriorityOptions){if(n===e)continue;const i=S(n),s=i?this.optionButtons.get(i):null,r=i?t.get(i):null;if(!s||!r||typeof s.animate!="function")continue;const a=s.getBoundingClientRect(),l=r.left-a.left,d=r.top-a.top;l===0&&d===0||s.animate([{transform:`translate(${l}px, ${d}px)`},{transform:"translate(0, 0)"}],{duration:De,easing:Be})}}}const $e=200,K="auto-select-champ-select-menu--collapsed",qe="auto-select-champ-select-menu-button-wrapper--open";class V{constructor(t,e){this.element=document.createElement(A.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=Dt(this.configKey),this.element.toggleAttribute("selected",this.config.enabled===!0)}toggle(){return console.debug("auto-champion-select: Toggling",this.configKey),this.config=U(this.configKey,t=>(t.enabled=!t.enabled,t)),this.element.toggleAttribute("selected",this.config.enabled===!0),this.config.enabled}}class ze{constructor(t,e,n){this.element=document.createElement("div"),this.element.classList.add("auto-select-champ-select-menu",K),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(K)}setOpen(t){this.element.classList.toggle(K,!t),this.buttonWrapper.classList.toggle(qe,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=J();for(;this.mounted&&!t;)await O($e),t=J();if(!this.mounted||!t)return;const e=t.querySelector(c.firstChampSelectSquareButton);this.buttonWrapper.parentNode===t&&this.buttonWrapper.nextSibling===e||t.insertBefore(this.buttonWrapper,e)}}class Ue{constructor(t,...e){this.element=document.createElement(A.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(c.socialRosterGroupLabel)){const n=new Event("post-render");this.element.dispatchEvent(n),e.disconnect()}}).observe(this.element,{childList:!0})}onPostRender(){var t;this.element.querySelector(c.socialRosterGroupLabel).innerText=this.label,(t=this.element.querySelector(c.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(c.socialRosterGroupArrow))==null||t.toggleAttribute("open")}}function Ht(o){var t,e;o&&((e=(t=globalThis.Toast)==null?void 0:t.success)==null||e.call(t,o))}function et(o){var t,e;o&&((e=(t=globalThis.Toast)==null?void 0:t.error)==null||e.call(t,o))}function Ge(o,t){const e=globalThis.Toast;return typeof(e==null?void 0:e.promise)=="function"?e.promise(o,t):o}const F="Balaclava: Auto Champion Select";function Ye(o){return typeof(o==null?void 0:o.then)=="function"}class rt{constructor({id:t,name:e,legend:n,tags:i,group:s,callback:r,toasts:a}){this.id=t,this.name=e,this.legend=n,this.tags=i,this.group=s,this.perform=this.perform.bind(this),this.callback=r,this.toasts=a}perform(){try{const t=this.callback();if(Ye(t))return Ge(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);Ht(e)}catch(t){et(this.toasts.error),console.error(t)}}}class Qt extends rt{constructor(t,e,n){super({id:`${e}Switch`,name:()=>`Auto ${t} [${I(e).enabled?"ON":"OFF"}]`,legend:()=>I(e).enabled?"Turn OFF":"Turn ON",tags:[F,e,"switch"],group:F,callback:n,toasts:{on:`Auto ${t} is ON!`,off:`Auto ${t} is OFF!`,error:`Failed to toggle Auto ${t}. Check console.`}})}}function He(o){return U(o,e=>(e.force=!e.force,e)).force}class jt extends rt{constructor(t,e){super({id:`${e}ForceSwitch`,name:()=>`Force ${t} [${I(e).force?"ON":"OFF"}]`,legend:()=>`Ignore team intent and force ${t} the selected champion`,tags:[F,e,"force","switch"],group:F,callback:()=>He(e),toasts:{on:`Force ${t} is ON!`,off:`Force ${t} is OFF!`,error:`Failed to toggle Force ${t}. Check console.`}})}}class Qe extends rt{constructor(t){super({id:"RefreshDropdowns",name:()=>"Refresh Champions",legend:()=>"Normally champion selectors refresh automatically...",tags:[F,"refresh"],group:F,callback:t,toasts:{success:"Refreshed Champions!",error:"Failed to refresh Champions. Check console."}})}}class je extends Qt{constructor(t){super("Pick","controladoPick",t)}}class We extends Qt{constructor(t){super("Ban","controladoBan",t)}}class Ke extends jt{constructor(){super("Pick","controladoPick")}}class Ve extends jt{constructor(){super("Ban","controladoBan")}}function Xe(o){for(const t of o)CommandBar.addAction(t)}const Je=200,Ze=6e4,Tt=2e3,tn=".ready-check-root-element",en="#lol-uikit-layer-manager-wrapper > .modal",nn="Accepted ready check!",_t="Failed to accept ready check. Check console.",on=".auto-select-champ-select-menu__header",v=Object.freeze({autoAccept:"controladoAutoAccept",pick:"controladoPick",ban:"controladoBan"});function Wt(){return I(v.autoAccept).enabled===!0}class sn{constructor(t){this.isEnabled=t,this.observer=null,this.hiddenModal=null,this.hiddenModalStyles=new WeakMap,this.sync=this.sync.bind(this)}start(){this.observer||(this.observer=new MutationObserver(()=>this.sync()),this.observer.observe(document.body,{childList:!0,subtree:!0}),this.sync())}sync(){const t=rn();if(!t){this.restore();return}if(!this.isEnabled()){this.restore();return}this.hide(t)}hide(t){this.hiddenModal!==t&&(this.restore(),this.hiddenModal=t,this.hiddenModalStyles.set(t,{display:t.style.getPropertyValue("display"),displayPriority:t.style.getPropertyPriority("display"),pointerEvents:t.style.getPropertyValue("pointer-events"),pointerEventsPriority:t.style.getPropertyPriority("pointer-events")}),t.style.setProperty("display","none","important"),t.style.setProperty("pointer-events","none","important"))}restore(){if(!this.hiddenModal)return;const t=this.hiddenModal,e=this.hiddenModalStyles.get(t);kt(t,"display",e==null?void 0:e.display,e==null?void 0:e.displayPriority),kt(t,"pointer-events",e==null?void 0:e.pointerEvents,e==null?void 0:e.pointerEventsPriority),this.hiddenModalStyles.delete(t),this.hiddenModal=null}}function rn(){const o=document.querySelector(tn);return(o==null?void 0:o.closest(en))||null}function kt(o,t,e,n){e?o.style.setProperty(t,e,n||""):o.style.removeProperty(t)}async function an(o){function t(){return Wt()?!1:(o.restore(),!0)}if(t()||(console.debug(`auto-champion-select(auto-accept): Ready check detected, accepting in ${Tt}ms...`),await O(Tt),t()))return;let e=!1;try{e=await ln()}catch(n){throw o.restore(),et(_t),n}e?Ht(nn):(o.restore(),et(_t))}async function ln(){const o=await b("POST",m.readyCheckAccept);return o.ok?(console.debug("auto-champion-select(auto-accept): Accepted ready check"),!0):(console.error("auto-champion-select(auto-accept): Failed to accept ready check",o),!1)}async function cn(o){const t=await b("GET",m.gameflowPhase),e=t.ok?await t.json():null;o.handleGameflowPhase(e)}function dn({championSelect:o,champSelectControlsMenu:t,readyCheckModalSuppressor:e,setupChampionSelectors:n}){let i=0;return async function(l){const d=++i;try{await s(l,d)}catch(f){console.error("auto-champion-select: Failed to handle gameflow phase",f)}};async function s(a,l){a==="ReadyCheck"?an(e).catch(d=>{console.error("auto-champion-select(auto-accept): Failed to handle ready check",d)}):e.restore(),await r(a),l===i&&await n()}async function r(a){a==="ChampSelect"?(o.mount(),await t.mount()):(o.unmount(),await t.unmount())}}function hn(){const o=new Ee,t=new V("Accept",v.autoAccept),e=new V("Pick",v.pick),n=new It("Add pick",v.pick,Pe,{enablePositionRestrictions:!0,enableRandomAssignedPositionRestrictions:!0,quickActionLabel:"Pick instantly",enableRandomPoolPositionFilters:!0,randomOptionDescription:"Picks a random available champion. Badges limit draft lanes or filter the pool."}),i=new V("Ban",v.ban),s=new It("Add ban",v.ban,$t,{quickActionLabel:"Ban instantly",enableRandomPoolPositionFilters:!0,randomOptionDescription:"Bans a random available champion. Lane badges filter the pool first."}),r=un(n,s),a=pn(t,e,i),l=new Ue("Auto champion select",r,a);return{championSelect:o,autoAcceptToggle:t,pickToggle:e,banToggle:i,pickChampionSelector:n,banChampionSelector:s,selectorsContainer:r,checkboxesContainer:a,pluginSection:l,championSelectors:[n,s]}}function un(...o){const t=document.createElement("div");return t.append(...o.map(e=>e.element)),t}function pn(...o){const t=document.createElement("div");return t.classList.add("auto-select-checkboxes-div"),t.append(...o.map(e=>e.element)),t}function mn({pluginSection:o,checkboxesContainer:t,selectorsContainer:e}){let n=null,i=0,s=()=>!1;async function r(a){let l=ft();for(;!l;){if(s()||a!==i)return;await O(Je),l=ft()}s()||a!==i||l.append(o.element,t,e)}return{setIsChampSelectControlsMounted(a){s=a},returnControlsToSocialRoster(){if(n)return n;const a=++i;return n=r(a).catch(l=>console.error("auto-champion-select: Failed to return controls to social roster",l)).finally(()=>{n=null}),n}}}function fn({autoAcceptToggle:o,pickToggle:t,banToggle:e,readyCheckModalSuppressor:n}){o.setup(),o.element.addEventListener("click",()=>n.sync()),t.setup(),e.setup()}async function gn(o){await Promise.all(o.map(t=>t.setup()))}async function Pn(o){await Promise.all(o.map(t=>t.refresh()))}function yn(){const o=hn(),t=new sn(Wt),e=mn(o),n=new ze("Auto Champion Select",e.returnControlsToSocialRoster,[o.checkboxesContainer,o.selectorsContainer]);e.setIsChampSelectControlsMounted(()=>n.mounted);const i={...o,champSelectControlsMenu:n,readyCheckModalSuppressor:t,setupToggles:()=>fn({...o,readyCheckModalSuppressor:t}),setupChampionSelectors:()=>gn(o.championSelectors),refreshChampionSelectors:()=>Pn(o.championSelectors),refreshPickChampionSelector:async()=>{await o.pickChampionSelector.refresh()}};return i.handleGameflowPhase=dn(i),i}function Cn(o){at(m.gameflowPhase,t=>{o.handleGameflowPhase(t.data)}),at(m.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 bn({pickToggle:o,banToggle:t,refreshChampionSelectors:e}){Xe([new je(()=>o.toggle()),new We(()=>t.toggle()),new Ke,new Ve,new Qe(e)])}function An(o){let t=null,e=null;function n(){e==null||e.disconnect(),e=null,t!==null&&(cancelAnimationFrame(t),t=null)}const i=setTimeout(()=>{n()},Ze);function s(){if(!(J()!==null))return;clearTimeout(i),n(),document.querySelector(on)!==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 Sn(){const o=yn();o.setupToggles(),o.readyCheckModalSuppressor.start(),bn(o),Cn(o),await cn(o),An(o),console.debug(`auto-champion-select(${Kt}): Report bugs to Balaclava#1912`)}let Rt=!1;function Lt(){Rt||(Rt=!0,Sn().catch(o=>console.error("auto-champion-select: Failed to initialize",o)))}document.readyState==="loading"?window.addEventListener("load",Lt,{once:!0}):Lt();export{Lt as load};
|