auto-champion-select 1.8.10 → 1.9.0
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 +89 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode('.dropdown-champions-default{position:inherit;inline-size:100%}.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-menu),.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-content),.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-options){top:auto;bottom:100%;transform-origin:bottom}.dropdown-champions-default .controlado-champion-option__content{display:inline-flex;align-items:center;gap:8px;width:100%;min-width:0;line-height:20px;vertical-align:middle}.dropdown-champions-default .controlado-champion-option__icon{flex:0 0 20px;width:20px;height:20px;border:1px solid rgba(200,170,110,.65);border-radius:50%;background:#010a13;object-fit:cover;box-sizing:border-box;pointer-events:none}.dropdown-champions-default .controlado-champion-option__name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.champion-priority-selector{display:grid;gap:0;padding:2px 0 3px}.champion-priority-selector__scroll{position:relative;inline-size:100%;height:58px;border:1px solid rgba(120,90,40,.7);border-top:0;background:rgba(30,35,40,.5);box-sizing:border-box}.champion-priority-selector__track{display:inline-flex;align-items:center;gap:12px;min-width:max-content;min-height:45px;padding:10px 8px 8px;box-sizing:border-box}.champion-priority-selector__empty{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;color:#5f5b4f;font-family:var(--font-body);font-size:11px;line-height:13px;text-align:center;white-space:nowrap;pointer-events:none}.champion-priority-selector__icon{position:relative;flex:0 0 auto;width:34px;height:34px;border:1px solid #c8aa6e;border-radius:50%;background:#1e2328;box-shadow:0 0 0 1px #010a13e6;box-sizing:border-box;cursor:grab;outline:none}.champion-priority-selector__icon:focus{border-color:#f0e6d2}.champion-priority-selector__icon--dragging{cursor:grabbing;filter:brightness(1.15);z-index:1}.champion-priority-selector__icon:before,.champion-priority-selector__remove,.champion-priority-selector__position-badge{display:grid;place-items:center;width:17px;height:17px;padding:0;border-radius:50%;box-sizing:border-box;font-family:var(--font-body);font-size:10px;font-weight:700;line-height:1}.champion-priority-selector__icon:before{content:attr(data-rank);position:absolute;left:-6px;top:-6px;border:1px solid #c8aa6e;background:#010a13;color:#f0e6d2;text-align:center;pointer-events:none}.champion-priority-selector__icon img{display:block;width:100%;height:100%;border-radius:50%;object-fit:cover;pointer-events:none}.champion-priority-selector__remove{position:absolute;right:-6px;bottom:-6px;-webkit-appearance:none;-moz-appearance:none;appearance:none;border:1px solid #785a28;background:#1e2328;color:#c8aa6e;cursor:pointer;font-family:var(--font-display);font-size:0;text-align:center}.champion-priority-selector__remove:before{content:attr(data-icon);font-family:var(--font-display);font-size:7px;line-height:1;transform:translate(.4px,-.1px)}.champion-priority-selector__remove:hover{border-color:#c8aa6e;color:#f0e6d2}.champion-priority-selector__position-badge{position:absolute;left:-6px;bottom:-6px;-webkit-appearance:none;-moz-appearance:none;appearance:none;border:1px solid #785a28;background:#010a13;color:#c8aa6e;cursor:pointer}.champion-priority-selector__position-badge:hover,.champion-priority-selector__position-badge:focus{border-color:#c8aa6e;color:#f0e6d2;outline:none}.champion-priority-selector__position-badge--empty{background:#1e2328;font-size:0}.champion-priority-selector__position-badge--empty:before{content:"+";font-family:var(--font-body);font-size:12px;line-height:1;transform:translate(.25px,.4px)}.champion-priority-selector__position-badge img{display:block;width:11px;height:11px;object-fit:contain;transform:translate(.1px)}.champion-priority-selector__position-badge:after{content:attr(data-count);position:absolute;right:-5px;top:-5px;display:none;place-items:center;width:11px;min-width:11px;height:11px;border:1px solid #785a28;border-radius:50%;background:#010a13;box-sizing:border-box;color:#f0e6d2;font-family:var(--font-body);font-size:7px;font-weight:700;line-height:1;text-align:center}.champion-priority-selector__position-badge[data-count]:after{display:grid}.champion-priority-selector__position-menu{position:fixed;z-index:10002;display:flex;gap:4px;padding:5px;border:1px solid #785a28;background:#010a13;box-shadow:0 0 0 1px #010a13d9,0 4px 16px #0000008c;box-sizing:border-box}.champion-priority-selector__position-menu[hidden]{display:none}.champion-priority-selector__position-option{display:grid;place-items:center;width:28px;height:28px;padding:0;border:1px solid #463714;background:#1e2328;box-sizing:border-box;cursor:pointer}.champion-priority-selector__position-option:hover,.champion-priority-selector__position-option--selected{border-color:#c8aa6e;background:#0f1b2d}.champion-priority-selector__position-option img{display:block;width:18px;height:18px;pointer-events:none}.auto-select-checkboxes-div{display:flex;border-top:thin solid #1e282d}.auto-select-checkbox{margin:auto}.auto-select-checkbox:last-child{margin-right:17px}.auto-select-champ-select-menu{position:absolute;right:0;bottom:36px;z-index:10000;width:min(340px,calc(100vw - 32px));color:#a09b8c;font-family:var(--font-body);font-size:12px;font-weight:400;line-height:normal;pointer-events:none;text-transform:none}.auto-select-champ-select-menu-button-wrapper{position:relative;display:block;width:38px;height:32px;flex:0 0 38px;box-sizing:border-box}.auto-select-champ-select-menu__header{position:relative;display:block;width:38px;height:32px;border:
|
|
1
|
+
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode('.dropdown-champions-default{position:inherit;inline-size:100%}.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-menu),.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-content),.dropdown-champions-default.dropdown-drop-up::part(ui-dropdown-options){top:auto;bottom:100%;transform-origin:bottom}.dropdown-champions-default .controlado-champion-option__content{display:inline-flex;align-items:center;gap:8px;width:100%;min-width:0;line-height:20px;vertical-align:middle}.dropdown-champions-default .controlado-champion-option__icon{flex:0 0 20px;width:20px;height:20px;border:1px solid rgba(200,170,110,.65);border-radius:50%;background:#010a13;object-fit:cover;box-sizing:border-box;pointer-events:none}.dropdown-champions-default .controlado-champion-option__name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.champion-priority-selector{display:grid;gap:0;padding:2px 0 3px}.champion-priority-selector__scroll{position:relative;inline-size:100%;height:58px;border:1px solid rgba(120,90,40,.7);border-top:0;background:rgba(30,35,40,.5);box-sizing:border-box}.champion-priority-selector__track{display:inline-flex;align-items:center;gap:12px;min-width:max-content;min-height:45px;padding:10px 8px 8px;box-sizing:border-box}.champion-priority-selector__empty{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;color:#5f5b4f;font-family:var(--font-body);font-size:11px;line-height:13px;text-align:center;white-space:nowrap;pointer-events:none}.champion-priority-selector__icon{position:relative;flex:0 0 auto;width:34px;height:34px;border:1px solid #c8aa6e;border-radius:50%;background:#1e2328;box-shadow:0 0 0 1px #010a13e6;box-sizing:border-box;cursor:grab;outline:none}.champion-priority-selector__icon:focus{border-color:#f0e6d2}.champion-priority-selector__icon--dragging{cursor:grabbing;filter:brightness(1.15);z-index:1}.champion-priority-selector__icon:before,.champion-priority-selector__remove,.champion-priority-selector__position-badge{display:grid;place-items:center;width:17px;height:17px;padding:0;border-radius:50%;box-sizing:border-box;font-family:var(--font-body);font-size:10px;font-weight:700;line-height:1}.champion-priority-selector__icon:before{content:attr(data-rank);position:absolute;left:-6px;top:-6px;border:1px solid #c8aa6e;background:#010a13;color:#f0e6d2;text-align:center;pointer-events:none}.champion-priority-selector__icon img{display:block;width:100%;height:100%;border-radius:50%;object-fit:cover;pointer-events:none}.champion-priority-selector__remove{position:absolute;right:-6px;bottom:-6px;-webkit-appearance:none;-moz-appearance:none;appearance:none;border:1px solid #785a28;background:#1e2328;color:#c8aa6e;cursor:pointer;font-family:var(--font-display);font-size:0;text-align:center}.champion-priority-selector__remove:before{content:attr(data-icon);font-family:var(--font-display);font-size:7px;line-height:1;transform:translate(.4px,-.1px)}.champion-priority-selector__remove:hover{border-color:#c8aa6e;color:#f0e6d2}.champion-priority-selector__position-badge{position:absolute;left:-6px;bottom:-6px;-webkit-appearance:none;-moz-appearance:none;appearance:none;border:1px solid #785a28;background:#010a13;color:#c8aa6e;cursor:pointer}.champion-priority-selector__position-badge:hover,.champion-priority-selector__position-badge:focus{border-color:#c8aa6e;color:#f0e6d2;outline:none}.champion-priority-selector__position-badge--empty{background:#1e2328;font-size:0}.champion-priority-selector__position-badge--empty:before{content:"+";font-family:var(--font-body);font-size:12px;line-height:1;transform:translate(.25px,.4px)}.champion-priority-selector__position-badge img{display:block;width:11px;height:11px;object-fit:contain;transform:translate(.1px)}.champion-priority-selector__position-badge:after{content:attr(data-count);position:absolute;right:-5px;top:-5px;display:none;place-items:center;width:11px;min-width:11px;height:11px;border:1px solid #785a28;border-radius:50%;background:#010a13;box-sizing:border-box;color:#f0e6d2;font-family:var(--font-body);font-size:7px;font-weight:700;line-height:1;text-align:center}.champion-priority-selector__position-badge[data-count]:after{display:grid}.champion-priority-selector__position-menu{position:fixed;z-index:10002;display:flex;gap:4px;padding:5px;border:1px solid #785a28;background:#010a13;box-shadow:0 0 0 1px #010a13d9,0 4px 16px #0000008c;box-sizing:border-box}.champion-priority-selector__position-menu[hidden]{display:none}.champion-priority-selector__position-option{display:grid;place-items:center;width:28px;height:28px;padding:0;border:1px solid #463714;background:#1e2328;box-sizing:border-box;cursor:pointer}.champion-priority-selector__position-option:hover,.champion-priority-selector__position-option--selected{border-color:#c8aa6e;background:#0f1b2d}.champion-priority-selector__position-option img{display:block;width:18px;height:18px;pointer-events:none}.auto-select-checkboxes-div{display:flex;border-top:thin solid #1e282d}.auto-select-checkbox{margin:auto}.auto-select-checkbox:last-child{margin-right:17px}.auto-select-champ-select-menu{position:absolute;right:0;bottom:36px;z-index:10000;width:min(340px,calc(100vw - 32px));color:#a09b8c;font-family:var(--font-body);font-size:12px;font-weight:400;line-height:normal;pointer-events:none;text-transform:none}.auto-select-champ-select-menu-button-wrapper{position:relative;display:block;width:38px;height:32px;flex:0 0 38px;box-sizing:border-box}.auto-select-champ-select-menu__header{position:relative;display:block;width:38px;height:32px;border:1px solid #785a28;background:#1e2328;box-shadow:inset 0 0 0 1px #010a13;box-sizing:border-box;cursor:pointer;outline:none;padding:0}.auto-select-champ-select-menu__header:before{content:"";position:absolute;left:50%;top:50%;width:20px;height:20px;background-color:#c8aa6e;-webkit-mask:url(/fe/lol-static-assets/images/nav-icon-collections.svg) center / 20px 20px no-repeat;mask:url(/fe/lol-static-assets/images/nav-icon-collections.svg) center / 20px 20px no-repeat;pointer-events:none;transform:translate(-50%,-50%)}.auto-select-champ-select-menu__header:hover{border-color:#c8aa6e;background:#2a3038}.auto-select-champ-select-menu__header:hover:before{background-color:#f0e6d2}.auto-select-champ-select-menu__header:active,.auto-select-champ-select-menu-button-wrapper--open .auto-select-champ-select-menu__header{border-color:#c89b3c;background:#111820}.auto-select-champ-select-menu-button-wrapper--open{z-index:10000}.auto-select-champ-select-menu-button-wrapper--open .auto-select-champ-select-menu__header:hover{border-color:#c8aa6e;background:#1e2328}.auto-select-champ-select-menu-button-wrapper--open .auto-select-champ-select-menu__header:before{background-color:#f0e6d2}.auto-select-champ-select-menu__content{display:grid;gap:4px;width:100%;margin-bottom:4px;border:1px solid #785a28;background:rgba(1,10,19,.96);box-shadow:0 0 18px #000000a6;box-sizing:border-box;pointer-events:auto;padding:8px}.auto-select-champ-select-menu__title{display:flex;align-items:center;justify-content:center;min-height:24px;padding-bottom:4px;border-bottom:thin solid #1e282d;color:#f0e6d2;font-family:var(--font-display);font-size:14px;font-weight:700;text-align:center}.auto-select-champ-select-menu .auto-select-checkboxes-div{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));align-items:center;border-top:0;border-bottom:thin solid #1e282d;padding-bottom:6px}.auto-select-champ-select-menu .auto-select-checkbox{justify-self:center;margin:0}.auto-select-champ-select-menu .dropdown-champions-default{min-height:32px}.auto-select-champ-select-menu .champion-priority-selector__scroll{height:56px}.auto-select-champ-select-menu--collapsed .auto-select-champ-select-menu__content{display:none}')),document.head.appendChild(e)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
|
|
2
2
|
/**
|
|
3
3
|
* @author balaclava
|
|
4
4
|
* @name auto-champion-select
|
|
5
5
|
* @link https://github.com/controlado/auto-champion-select#readme
|
|
6
6
|
* @description Pick or ban automatically! 🐧
|
|
7
|
-
* @version 1.
|
|
7
|
+
* @version 1.9.0
|
|
8
8
|
* @license GPL-3.0-or-later
|
|
9
9
|
*/
|
|
10
|
-
import{request as w,sleep as g,linkEndpoint as z}from"https://cdn.jsdelivr.net/npm/balaclava-utils@latest";const Pt="1.8.10",It={enabled:!1},kt={enabled:!1,force:!1,quickAction:!1,champions:[432,235],positionsByChampionId:{235:["BOTTOM","UTILITY"],432:["UTILITY"]}},Ot={enabled:!1,force:!1,quickAction:!1,champions:[157,777,238,38]},Tt={controladoAutoAccept:It,controladoPick:kt,controladoBan:Ot};function d(o){const t=Number(o);return Number.isSafeInteger(t)&&t>0?t:null}function at(o,t=null){const e=[],n=new Set,i=_t(t);if(!Array.isArray(o))return e;for(const s of o){const r=d(s);r===null||n.has(r)||i&&!i.has(r)||(e.push(r),n.add(r))}return e}function _t(o){return o?new Set(Array.from(o,d).filter(t=>t!==null)):null}const k=[{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"}],Lt=new Set(k.map(o=>o.value));function T(o){const t=String(o??"").toUpperCase();return Lt.has(t)?t:null}function x(o,t=null){const e={};if(!o||typeof o!="object"||Array.isArray(o))return e;const n=vt(t);for(const[i,s]of Object.entries(o)){const r=d(i),a=String(r);if(r===null||n&&!n.has(a)||!Array.isArray(s))continue;const c=[],h=new Set;for(const u of s){const C=T(u);!C||h.has(C)||(c.push(C),h.add(C))}c.length>0&&(e[a]=c)}return e}function vt(o){if(!o)return null;const t=new Set;for(const e of o){const n=d(e);n!==null&&t.add(String(n))}return t}function U(o){return k.find(t=>t.value===o)}function ct(o,t){var n;const e=d(t);return e===null?[]:((n=o==null?void 0:o.positionsByChampionId)==null?void 0:n[String(e)])||[]}function Mt(o,t,e){const n=ct(o,t);if(n.length===0)return!0;const i=T(e);return i!==null&&n.includes(i)}const G=new Set;function Rt(o,t){return Object.prototype.hasOwnProperty.call(o,t)}function P(o,t){return Rt(o,t)}function $(){if(!globalThis.DataStore)throw new Error("DataStore is not available");return globalThis.DataStore}function xt(o){return o!==null&&typeof o=="object"&&!Array.isArray(o)}function F(o){if(o!==void 0)return JSON.parse(JSON.stringify(o))}function lt(o){const t=Tt[o];if(!t)throw new Error(`Unknown auto-champion-select config key: ${o}`);return F(t)}function dt(o,t,e={}){const n=lt(o),i=xt(t)?F(t):{},s={...n,...i},r={enabled:s.enabled===!0};return P(n,"force")&&(r.force=s.force===!0),P(n,"quickAction")&&(r.quickAction=s.quickAction===!0),P(n,"champions")&&(r.champions=at(s.champions,e.allowedChampionIds)),P(n,"positionsByChampionId")&&(r.positionsByChampionId=x(s.positionsByChampionId,e.selectedChampionIds||r.champions)),r}function ht(o,t,e={}){const n=t===void 0?lt(o):t;return dt(o,n,e)}function b(o,t={}){const n=$().get(o);return ht(o,n,t)}function Bt(o,t,e={}){const n=$(),i=dt(o,t,e);return n.set(o,i),i}function Dt(o,t){return JSON.stringify(o)===JSON.stringify(t)}function Nt(o,t,e){G.has(o)||(G.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 ut(o,t={}){const e=$(),n=e.get(o),i=ht(o,n,t);return(n===void 0||!Dt(n,i))&&(n!==void 0&&Nt(o,n,i),e.set(o,i)),i}function O(o,t,e={}){const n=b(o,e),i=F(n),s=t(i)||i;return Bt(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",champSelectSession:"/lol-champ-select/v1/session",championIcon(o){return`/lol-game-data/assets/v1/champion-icons/${o}.png`},champSelectAction(o){return`/lol-champ-select/v1/session/actions/${o}`}}),$t=1e3;function pt(o){let t=null;return function(){return t||(t=Promise.resolve().then(o).finally(()=>{t=null})),t}}function mt(o){const t=[],e=new Set;if(!Array.isArray(o))return t;for(const n of o){if(!n||typeof n!="object")continue;const i=d(n.id),s=typeof n.name=="string"?n.name:"";i===null||!s||e.has(s)||(t.push({...n,id:i,name:s,squarePortraitPath:n.squarePortraitPath||p.championIcon(i)}),e.add(s))}return t.sort((n,i)=>n.name.localeCompare(i.name)),t}async function Ft(){let o=await w("GET",p.ownedChampions);for(;!o.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),o=await w("GET",p.ownedChampions),await g($t);return mt(await o.json())}async function qt(){const o=await w("GET",p.championSummary);return mt(await o.json())}const zt=pt(Ft),Ut=pt(qt),H=300,Y=2e3,Gt=4e3,f=Object.freeze({APPLIED:"applied",TRY_NEXT_CHAMPION:"try-next-champion",ABORT_ACTION:"abort-action"});function B(o){return Array.isArray(o)?o.flat():[]}function Ht(o){return B(o).filter(t=>t.type==="ban"&&t.completed===!0).map(t=>t.championId)}function Q(o){return Array.isArray(o)?o:[]}function _(o){const t=new Set;for(const e of o){const n=d(e);n!==null&&t.add(n)}return t}function W(o){return o.type==="pick"?0:1}function j(){return{pickConfig:b("controladoPick"),banConfig:b("controladoBan")}}function Yt(o){return o.quickAction===!0}function Qt(){const o=Gt-Y;return Y+Math.floor(Math.random()*(o+1))}class Wt{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 g(H);continue}try{await this.runAutoSelectCycle()}catch(n){console.debug("auto-champion-select: Failed to run champion select cycle",n)}this.mounted&&t===this.watchVersion&&await g(H)}}finally{this.watchTask=null}}async refreshSessionState(){var s,r;const t=await w("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=Q(this.session.myTeam),n=Q(this.session.theirTeam),i=e.find(a=>a.cellId===this.localPlayerCellId);this.localPlayerAssignedPosition=T(i==null?void 0:i.assignedPosition),this.localPlayerIntentChampionId=d(i==null?void 0:i.championPickIntent),this.pickedChampionIds=_([...e,...n].map(a=>a.championId)),this.bannedChampionIds=_([...((s=this.session.bans)==null?void 0:s.myTeamBans)||[],...((r=this.session.bans)==null?void 0:r.theirTeamBans)||[],...Ht(this.actions)]),this.teammateIntentChampionIds=_(e.map(a=>a.championPickIntent))}async runAutoSelectCycle(){const{pickConfig:t,banConfig:e}=j();if(!t.enabled&&!e.enabled)return;const n=this.getLocalPlayerActions();if(n.length===0){console.debug("auto-champion-select: No local player sub actions found, skipping..."),this.unmount();return}for(const i of n){if(!this.isActionAvailable(i))continue;const s=this.getConfigForActionType(i.type,{pickConfig:t,banConfig:e});if(!(s!=null&&s.enabled))continue;let r=i,a=s,c=this.getAvailableChampionIdsForAction(r,a);if(c.length===0)continue;const h=c.find(u=>this.isPickIntentAlreadyApplied(r,u));if(h!==void 0)c=[h];else if(!Yt(a)){const u=await this.delayAndRefreshPendingAction(r);if(!u)return;r=u.action,a=u.config,c=u.championIds}for(const u of c){const C=await this.attemptChampionForAction(r,u,a);if(C===f.APPLIED)break;if(C===f.ABORT_ACTION)return}}}getLocalPlayerActions(){return B(this.actions).filter(t=>this.isPendingLocalPlayerAction(t)).sort((t,e)=>W(t)-W(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}getAvailableChampionIdsForAction(t,e){return e.champions.map(n=>d(n)).filter(n=>n!==null&&!this.isChampionUnavailableForAction(t,n,e))}async delayAndRefreshPendingAction(t){const e=Qt();console.debug(`auto-champion-select: Quick action is off, waiting ${e}ms before ${t.type}...`);const n=this.watchVersion;if(await g(e),!this.mounted||n!==this.watchVersion)return null;let i=null;try{await this.refreshSessionState(),i=this.findPendingAction(t)}catch(a){return console.debug("auto-champion-select: Failed to refresh champion select after action delay",a),null}if(!i||!this.isActionAvailable(i))return null;const s=this.getConfigForActionType(t.type,j());if(!(s!=null&&s.enabled))return null;const r=this.getAvailableChampionIdsForAction(i,s);return r.length===0?null:{action:i,config:s,championIds:r}}async attemptChampionForAction(t,e,n){const i=d(e);if(i===null||this.isChampionUnavailableForAction(t,i,n))return f.TRY_NEXT_CHAMPION;if(this.isPickIntentAlreadyApplied(t,i)||(console.debug(`auto-champion-select: Trying to ${t.type} ${i}...`),(await this.selectChampion(t.id,i)).ok))return f.APPLIED;console.debug(`auto-champion-select: Failed to ${t.type} ${i}, refreshing champ select state...`);const r=await this.refreshPendingAction(t);return!r||!this.isActionAvailable(r)||!this.isChampionUnavailableForAction(r,i,n)?f.ABORT_ACTION:(console.debug(`auto-champion-select: ${i} is unavailable after refresh, trying next ${t.type}...`),f.TRY_NEXT_CHAMPION)}isPickIntentAlreadyApplied(t,e){return t.type==="pick"&&t.isInProgress!==!0&&(this.localPlayerIntentChampionId===e||d(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 B(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"&&!Mt(n,e,this.localPlayerAssignedPosition)){const i=ct(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 w("PATCH",n,{body:{championId:e,completed:!0}})}}const m=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:m.dropdownOption,dropdownOptionSelected:`${m.dropdownOption}[selected]`,dropdownOptionsContainer:".ui-dropdown-options-container",dropdownOptions:".ui-dropdown-options",dropdownScrollable:m.scrollable,socialRosterGroupArrow:".arrow",socialRosterGroupHeader:".group-header",socialRosterGroupLabel:"span"});function V(){return document.querySelector(l.socialRoster)}function D(){return document.querySelector(l.champSelectButtons)}const jt=50,Vt=100,L=210,X="controlado-placeholder",K="controlado-search",v="controlado-quick-action",ft="controlado-filter-icon",y="controlado-filter-icon--trash",gt="controlado-filter-input",E="controlado-quick-action-toggle",Ct="controlado-quick-action-toggle--active",wt="controlado-tag",bt="controlado-tag--search",Xt="controlado-champion-option",Kt="controlado-champion-option__content",Jt="controlado-champion-option__icon",Zt="controlado-champion-option__name",te=`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")`,J=`
|
|
10
|
+
import{request as b,sleep as C,linkEndpoint as W}from"https://cdn.jsdelivr.net/npm/balaclava-utils@latest";const Lt="1.9.0",vt={enabled:!1},Rt={enabled:!1,force:!1,quickAction:!1,champions:[432,235],positionsByChampionId:{235:["BOTTOM","UTILITY"],432:["UTILITY"]}},Mt={enabled:!1,force:!1,quickAction:!1,champions:[157,777,238,38]},xt={controladoAutoAccept:vt,controladoPick:Rt,controladoBan:Mt};function d(o){const t=Number(o);return Number.isSafeInteger(t)&&t>0?t:null}function pt(o,t=null){const e=[],n=new Set,i=Bt(t);if(!Array.isArray(o))return e;for(const s of o){const r=d(s);r===null||n.has(r)||i&&!i.has(r)||(e.push(r),n.add(r))}return e}function Bt(o){return o?new Set(Array.from(o,d).filter(t=>t!==null)):null}const I=[{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"}],Dt=new Set(I.map(o=>o.value));function k(o){const t=String(o??"").toUpperCase();return Dt.has(t)?t:null}function L(o,t=null){const e={};if(!o||typeof o!="object"||Array.isArray(o))return e;const n=Ft(t);for(const[i,s]of Object.entries(o)){const r=d(i);if(r===null||!Array.isArray(s))continue;const a=String(r);if(n&&!n.has(a))continue;const c=[],h=new Set;for(const u of s){const w=k(u);!w||h.has(w)||(c.push(w),h.add(w))}c.length>0&&(e[a]=c)}return e}function Ft(o){if(!o)return null;const t=new Set;for(const e of o){const n=d(e);n!==null&&t.add(String(n))}return t}function j(o){return I.find(t=>t.value===o)}function mt(o,t){var n;const e=d(t);return e===null?[]:((n=o==null?void 0:o.positionsByChampionId)==null?void 0:n[String(e)])||[]}function $t(o,t,e){const n=mt(o,t);if(n.length===0)return!0;const i=k(e);return i!==null&&n.includes(i)}const V=new Set;function Nt(o,t){return Object.prototype.hasOwnProperty.call(o,t)}function O(o,t){return Nt(o,t)}function U(){if(!globalThis.DataStore)throw new Error("DataStore is not available");return globalThis.DataStore}function qt(o){return o!==null&&typeof o=="object"&&!Array.isArray(o)}function Q(o){if(o!==void 0)return JSON.parse(JSON.stringify(o))}function ft(o){const t=xt[o];if(!t)throw new Error(`Unknown auto-champion-select config key: ${o}`);return Q(t)}function gt(o,t,e={}){const n=ft(o),i=qt(t)?Q(t):{},s={...n,...i},r={enabled:s.enabled===!0};return O(n,"force")&&(r.force=s.force===!0),O(n,"quickAction")&&(r.quickAction=s.quickAction===!0),O(n,"champions")&&(r.champions=pt(s.champions,e.allowedChampionIds)),O(n,"positionsByChampionId")&&(r.positionsByChampionId=L(s.positionsByChampionId,e.selectedChampionIds||r.champions)),r}function Ct(o,t,e={}){const n=t===void 0?ft(o):t;return gt(o,n,e)}function y(o,t={}){const n=U().get(o);return Ct(o,n,t)}function zt(o,t,e={}){const n=U(),i=gt(o,t,e);return n.set(o,i),i}function Gt(o,t){return JSON.stringify(o)===JSON.stringify(t)}function Ut(o,t,e){V.has(o)||(V.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 bt(o,t={}){const e=U(),n=e.get(o),i=Ct(o,n,t);return(n===void 0||!Gt(n,i))&&(n!==void 0&&Ut(o,n,i),e.set(o,i)),i}function v(o,t,e={}){const n=y(o,e),i=Q(n),s=t(i)||i;return zt(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",championIcon(o){return`/lol-game-data/assets/v1/champion-icons/${o}.png`},champSelectAction(o){return`/lol-champ-select/v1/session/actions/${o}`}}),Qt=1e3;function H(o){let t=null;return function(){return t||(t=Promise.resolve().then(o).finally(()=>{t=null})),t}}function wt(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=d(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 Ht(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 L(t)}async function Yt(){try{const o=await b("GET",p.recommendedChampionPositions);return o.ok?Ht(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 yt=H(Yt);async function Wt(){let o=await b("GET",p.ownedChampions);for(;!o.ok;)console.debug("auto-champion-select(owned-champions-minimal): Retrying..."),o=await b("GET",p.ownedChampions),await C(Qt);return wt(await o.json(),await yt())}async function jt(){const[o,t]=await Promise.all([b("GET",p.championSummary),yt()]);return wt(await o.json(),t)}const Vt=H(Wt),Xt=H(jt),X=300,K=2e3,Kt=4e3,f=Object.freeze({APPLIED:"applied",TRY_NEXT_CHAMPION:"try-next-champion",ABORT_ACTION:"abort-action"});function $(o){return Array.isArray(o)?o.flat():[]}function Jt(o){return $(o).filter(t=>t.type==="ban"&&t.completed===!0).map(t=>t.championId)}function J(o){return Array.isArray(o)?o:[]}function R(o){const t=new Set;for(const e of o){const n=d(e);n!==null&&t.add(n)}return t}function Z(o){return o.type==="pick"?0:1}function tt(){return{pickConfig:y("controladoPick"),banConfig:y("controladoBan")}}function Zt(o){return o.quickAction===!0}function te(){const o=Kt-K;return K+Math.floor(Math.random()*(o+1))}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 C(X);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 C(X)}}finally{this.watchTask=null}}async refreshSessionState(){var s,r;const t=await b("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=J(this.session.myTeam),n=J(this.session.theirTeam),i=e.find(a=>a.cellId===this.localPlayerCellId);this.localPlayerAssignedPosition=k(i==null?void 0:i.assignedPosition),this.localPlayerIntentChampionId=d(i==null?void 0:i.championPickIntent),this.pickedChampionIds=R([...e,...n].map(a=>a.championId)),this.bannedChampionIds=R([...((s=this.session.bans)==null?void 0:s.myTeamBans)||[],...((r=this.session.bans)==null?void 0:r.theirTeamBans)||[],...Jt(this.actions)]),this.teammateIntentChampionIds=R(e.map(a=>a.championPickIntent))}async runAutoSelectCycle(){const{pickConfig:t,banConfig:e}=tt();if(!t.enabled&&!e.enabled)return;const n=this.getLocalPlayerActions();if(n.length===0){console.debug("auto-champion-select: No local player sub actions found, skipping..."),this.unmount();return}for(const i of n){if(!this.isActionAvailable(i))continue;const s=this.getConfigForActionType(i.type,{pickConfig:t,banConfig:e});if(!(s!=null&&s.enabled))continue;let r=i,a=s,c=this.getAvailableChampionIdsForAction(r,a);if(c.length===0)continue;const h=c.find(u=>this.isPickIntentAlreadyApplied(r,u));if(h!==void 0)c=[h];else if(!Zt(a)){const u=await this.delayAndRefreshPendingAction(r);if(!u)return;r=u.action,a=u.config,c=u.championIds}for(const u of c){const w=await this.attemptChampionForAction(r,u,a);if(w===f.APPLIED)break;if(w===f.ABORT_ACTION)return}}}getLocalPlayerActions(){return $(this.actions).filter(t=>this.isPendingLocalPlayerAction(t)).sort((t,e)=>Z(t)-Z(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}getAvailableChampionIdsForAction(t,e){return e.champions.map(n=>d(n)).filter(n=>n!==null&&!this.isChampionUnavailableForAction(t,n,e))}async delayAndRefreshPendingAction(t){const e=te();console.debug(`auto-champion-select: Quick action is off, waiting ${e}ms before ${t.type}...`);const n=this.watchVersion;if(await C(e),!this.mounted||n!==this.watchVersion)return null;let i=null;try{await this.refreshSessionState(),i=this.findPendingAction(t)}catch(a){return console.debug("auto-champion-select: Failed to refresh champion select after action delay",a),null}if(!i||!this.isActionAvailable(i))return null;const s=this.getConfigForActionType(t.type,tt());if(!(s!=null&&s.enabled))return null;const r=this.getAvailableChampionIdsForAction(i,s);return r.length===0?null:{action:i,config:s,championIds:r}}async attemptChampionForAction(t,e,n){const i=d(e);if(i===null||this.isChampionUnavailableForAction(t,i,n))return f.TRY_NEXT_CHAMPION;if(this.isPickIntentAlreadyApplied(t,i)||(console.debug(`auto-champion-select: Trying to ${t.type} ${i}...`),(await this.selectChampion(t.id,i)).ok))return f.APPLIED;console.debug(`auto-champion-select: Failed to ${t.type} ${i}, refreshing champ select state...`);const r=await this.refreshPendingAction(t);return!r||!this.isActionAvailable(r)||!this.isChampionUnavailableForAction(r,i,n)?f.ABORT_ACTION:(console.debug(`auto-champion-select: ${i} is unavailable after refresh, trying next ${t.type}...`),f.TRY_NEXT_CHAMPION)}isPickIntentAlreadyApplied(t,e){return t.type==="pick"&&t.isInProgress!==!0&&(this.localPlayerIntentChampionId===e||d(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 $(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"&&!$t(n,e,this.localPlayerAssignedPosition)){const i=mt(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 b("PATCH",n,{body:{championId:e,completed:!0}})}}const m=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:m.dropdownOption,dropdownOptionSelected:`${m.dropdownOption}[selected]`,dropdownOptionsContainer:".ui-dropdown-options-container",dropdownOptions:".ui-dropdown-options",dropdownScrollable:m.scrollable,socialRosterGroupArrow:".arrow",socialRosterGroupHeader:".group-header",socialRosterGroupLabel:"span"});function et(){return document.querySelector(l.socialRoster)}function N(){return document.querySelector(l.champSelectButtons)}const ne=50,oe=100,M=210,x=40,_="controlado-position-filter",q="controlado-position-filter-visible",g="controlado-position-filter__badge",z="controlado-position-filter__badge--active",nt="controlado-placeholder",ot="controlado-search",Pt="controlado-filter-input",At="controlado-tag--search",B="controlado-quick-action",E="controlado-quick-action-toggle",St="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")`,Et="controlado-tag",It="controlado-filter-icon",P="controlado-filter-icon--trash",se="controlado-champion-option__content",re="controlado-champion-option__icon",ae="controlado-champion-option__name",it=`
|
|
11
11
|
${l.dropdownRoot} {
|
|
12
12
|
position: relative;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
:host {
|
|
16
|
-
--framed-dropdown-scrollable-max-height: ${
|
|
16
|
+
--framed-dropdown-scrollable-max-height: ${M}px;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
:host ${l.dropdownRoot} dt${l.dropdownCurrent} {
|
|
@@ -38,7 +38,7 @@ import{request as w,sleep as g,linkEndpoint as z}from"https://cdn.jsdelivr.net/n
|
|
|
38
38
|
position: absolute;
|
|
39
39
|
top: auto;
|
|
40
40
|
bottom: 100%;
|
|
41
|
-
height: ${
|
|
41
|
+
height: ${M}px;
|
|
42
42
|
overflow: hidden;
|
|
43
43
|
transform-origin: bottom;
|
|
44
44
|
transform: translateY(0);
|
|
@@ -46,10 +46,85 @@ import{request as w,sleep as g,linkEndpoint as z}from"https://cdn.jsdelivr.net/n
|
|
|
46
46
|
|
|
47
47
|
${l.dropdownOptions},
|
|
48
48
|
${l.dropdownScrollable} {
|
|
49
|
-
height: ${
|
|
49
|
+
height: ${M}px;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
${l.dropdownOptions} {
|
|
53
|
+
width: 100%;
|
|
54
|
+
box-sizing: border-box;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
${l.dropdownOptions} ${l.dropdownScrollable} {
|
|
58
|
+
box-sizing: border-box;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
${l.dropdownOptionsContainer}.${q} ${l.dropdownOptions} ${l.dropdownScrollable} {
|
|
62
|
+
padding-top: ${x}px;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.${_} {
|
|
66
|
+
position: absolute;
|
|
67
|
+
left: 0;
|
|
68
|
+
right: 0;
|
|
69
|
+
top: 0;
|
|
70
|
+
z-index: 3;
|
|
71
|
+
display: flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
justify-content: space-between;
|
|
74
|
+
height: ${x}px;
|
|
75
|
+
min-height: ${x}px;
|
|
76
|
+
padding: 0 17px;
|
|
77
|
+
border-bottom: 1px solid #1e282d;
|
|
78
|
+
background: #010a13;
|
|
79
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
|
|
80
|
+
box-sizing: border-box;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.${g} {
|
|
84
|
+
appearance: none;
|
|
85
|
+
display: grid;
|
|
86
|
+
place-items: center;
|
|
87
|
+
flex: 0 0 28px;
|
|
88
|
+
width: 28px;
|
|
89
|
+
height: 28px;
|
|
90
|
+
padding: 0;
|
|
91
|
+
border: 1px solid #463714;
|
|
92
|
+
border-radius: 50%;
|
|
93
|
+
background: #1e2328;
|
|
94
|
+
box-shadow: 0 0 0 1px rgba(1, 10, 19, 0.85);
|
|
95
|
+
box-sizing: border-box;
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
outline: none;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.${g}:hover,
|
|
101
|
+
.${g}:focus {
|
|
102
|
+
border-color: #c8aa6e;
|
|
103
|
+
background: #0f1b2d;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.${z} {
|
|
107
|
+
border-color: #f0e6d2;
|
|
108
|
+
background: #09202c;
|
|
109
|
+
box-shadow: 0 0 0 1px #c89b3c, 0 0 10px rgba(200, 155, 60, 0.45);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.${g} img {
|
|
113
|
+
display: block;
|
|
114
|
+
width: 18px;
|
|
115
|
+
height: 18px;
|
|
116
|
+
object-fit: contain;
|
|
117
|
+
opacity: 0.72;
|
|
118
|
+
pointer-events: none;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.${g}:hover img,
|
|
122
|
+
.${g}:focus img,
|
|
123
|
+
.${z} img {
|
|
124
|
+
opacity: 1;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.${It} {
|
|
53
128
|
cursor: default;
|
|
54
129
|
display: inline-block;
|
|
55
130
|
flex: 0 0 auto;
|
|
@@ -62,14 +137,14 @@ import{request as w,sleep as g,linkEndpoint as z}from"https://cdn.jsdelivr.net/n
|
|
|
62
137
|
-webkit-mask-size: 18px 18px;
|
|
63
138
|
}
|
|
64
139
|
|
|
65
|
-
.${
|
|
140
|
+
.${P} {
|
|
66
141
|
cursor: pointer;
|
|
67
142
|
background-color: #c86e6e;
|
|
68
143
|
-webkit-mask-image: url('/fe/lol-uikit/images/icon_delete.png');
|
|
69
144
|
-webkit-mask-size: 12px 12px;
|
|
70
145
|
}
|
|
71
146
|
|
|
72
|
-
.${
|
|
147
|
+
.${Pt} {
|
|
73
148
|
flex: 0 0 auto;
|
|
74
149
|
min-width: 0;
|
|
75
150
|
width: auto;
|
|
@@ -83,7 +158,7 @@ import{request as w,sleep as g,linkEndpoint as z}from"https://cdn.jsdelivr.net/n
|
|
|
83
158
|
font-weight: inherit;
|
|
84
159
|
}
|
|
85
160
|
|
|
86
|
-
.${
|
|
161
|
+
.${Et} {
|
|
87
162
|
cursor: default;
|
|
88
163
|
display: inline-flex;
|
|
89
164
|
align-items: center;
|
|
@@ -101,7 +176,7 @@ import{request as w,sleep as g,linkEndpoint as z}from"https://cdn.jsdelivr.net/n
|
|
|
101
176
|
box-shadow: inset 0 0 8px rgba(15, 30, 45, 0.6);
|
|
102
177
|
}
|
|
103
178
|
|
|
104
|
-
.${
|
|
179
|
+
.${At} {
|
|
105
180
|
border-color: #d7b46a;
|
|
106
181
|
color: #f6e1b2;
|
|
107
182
|
background: #1a232f;
|
|
@@ -137,7 +212,7 @@ import{request as w,sleep as g,linkEndpoint as z}from"https://cdn.jsdelivr.net/n
|
|
|
137
212
|
width: 16px;
|
|
138
213
|
height: 16px;
|
|
139
214
|
background-color: #785a28;
|
|
140
|
-
-webkit-mask-image: ${
|
|
215
|
+
-webkit-mask-image: ${ie};
|
|
141
216
|
-webkit-mask-repeat: no-repeat;
|
|
142
217
|
-webkit-mask-position: center;
|
|
143
218
|
-webkit-mask-size: 16px 16px;
|
|
@@ -149,8 +224,8 @@ import{request as w,sleep as g,linkEndpoint as z}from"https://cdn.jsdelivr.net/n
|
|
|
149
224
|
background-color: #c8aa6e;
|
|
150
225
|
}
|
|
151
226
|
|
|
152
|
-
.${
|
|
227
|
+
.${St}::before {
|
|
153
228
|
background-color: #f0e6d2;
|
|
154
229
|
filter: drop-shadow(0 0 3px rgba(200, 170, 110, 0.75));
|
|
155
230
|
}
|
|
156
|
-
`;function Z(o){const t=document.createElement(m.dropdownOption);return t.setAttribute("slot",m.dropdownOption),t.innerText=o,t}class ee{constructor(t,e,n,i={}){this.dropdownElement=t,this.placeholderText=e,this.searchPlaceholderText=i.searchPlaceholderText||"Search",this.quickActionLabel=i.quickActionLabel||"Pick/ban instantly",this.isQuickActionEnabled=typeof i.isQuickActionEnabled=="function"?i.isQuickActionEnabled:null,this.onQuickActionToggle=typeof i.onQuickActionToggle=="function"?i.onQuickActionToggle:null,this.onChampionSelected=n,this.placeholderOption=null}renderOptions(t){this.dropdownElement.replaceChildren(),this.placeholderOption=Z(this.placeholderText),this.placeholderOption.setAttribute("selected","true"),this.hidePlaceholderOption(),this.dropdownElement.appendChild(this.placeholderOption);for(const e of t){const n=this.createChampionOption(e);this.dropdownElement.appendChild(n)}}createChampionOption(t){const e=Z("");return e.classList.add(Xt),e.title=t.name,e.appendChild(this.createChampionOptionContent(t)),e.addEventListener("click",()=>{this.onChampionSelected(t.id),requestAnimationFrame(()=>this.reset())}),e}createChampionOptionContent(t){const e=document.createElement("span");e.classList.add(Kt);const n=document.createElement("img");n.classList.add(Jt),n.src=t.squarePortraitPath,n.alt="",n.draggable=!1,n.loading="lazy";const i=document.createElement("span");return i.classList.add(Zt),i.innerText=t.name,e.append(n,i),e}async waitForRender(){for(let t=0;t<jt;t++){const e=this.dropdownElement.shadowRoot;if(this.dropdownElement.isConnected&&(e!=null&&e.querySelector(l.dropdownCurrent)))return e;await g(Vt)}return null}ensureSearchPlaceholder(t){if(t.querySelector(`#${X}`))return;const e=t.querySelector(l.dropdownCurrent);e&&e.appendChild(this.createSearchPlaceholder())}ensureQuickActionToggle(t){if(!this.isQuickActionAvailable()||t.querySelector(`#${v}`)){this.syncQuickActionToggle(t);return}const e=t.querySelector(l.dropdownCurrent);e&&(e.appendChild(this.createQuickActionToggle()),this.syncQuickActionToggle(t))}createSearchPlaceholder(){const t=document.createElement("div");t.classList.add(wt,bt),t.id=X;const e=document.createElement("input");e.classList.add(gt),e.id=K,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(ft),n.addEventListener("click",()=>{n.classList.contains(y)&&this.clearSearch(e,n)}),e.addEventListener("input",i=>{this.ensureOpen(),this.filterOptions(i.target.value),n.classList.toggle(y,!!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(E),t.id=v,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(`#${v}`);if(!e)return;const n=this.isQuickActionEnabled()===!0;e.classList.toggle(Ct,n),e.setAttribute("aria-pressed",String(n)),e.title=this.quickActionLabel,e.setAttribute("aria-label",this.quickActionLabel)}clearSearch(t,e){t.value="",this.filterOptions(""),e.classList.toggle(y,!1)}filterOptions(t){const e=t.toLowerCase();this.dropdownElement.querySelectorAll(l.dropdownOption).forEach(i=>{if(i===this.placeholderOption){this.hidePlaceholderOption();return}(i.textContent??"").toLowerCase().includes(e)?i.style.display="":i.style.display="none"})}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(`#${K}`),i=e.querySelector(`.${y}`);n&&i?this.clearSearch(n,i):(n&&(n.value="",this.filterOptions("")),i&&i.classList.remove(y)),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)})}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=J;return}const n=document.createElement("style");n.dataset.controlado="dropdown-tags",n.textContent=J,t.appendChild(n)}withShadowRoot(t){const e=this.dropdownElement.shadowRoot;e&&t(e)}}const ne=".champion-priority-selector__position-badge",oe=".champion-priority-selector__position-option",ie=".champion-priority-selector__remove",se="✕",re=0,tt=1,I=8,ae=5,ce=150,le="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 ee(this.dropdownElement,t,a=>this.addChampion(a),{quickActionLabel:i.quickActionLabel,searchPlaceholderText:i.searchPlaceholderText,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.positionMenuElement=this.enablePositionRestrictions?this.createPositionMenu():null,this.positionMenuChampionId=null,this.positionsByChampionId={},this.emptyElement=this.createEmptyState(t),this.element.append(this.dropdownElement,this.scrollElement),this.positionMenuElement&&this.element.appendChild(this.positionMenuElement),this.config=null,this.configKey=e,this.quickAction=!1,this.loadChampions=n,this.champions=[],this.championById=new Map,this.selectedChampionIds=[],this.iconButtons=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(m.dropdown);return t.classList.add("dropdown-champions-default","dropdown-drop-up"),t}createSelectedChampionsScroll(){const t=document.createElement(m.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 k)t.appendChild(this.createPositionOption(e));return t}createPositionOption(t){const e=document.createElement("button");e.classList.add("champion-priority-selector__position-option"),e.type="button",e.dataset.position=t.value,e.title=t.label,e.setAttribute("aria-label",t.label),e.setAttribute("aria-pressed","false"),e.addEventListener("pointerdown",i=>i.stopPropagation()),e.addEventListener("click",i=>{i.stopPropagation(),this.toggleChampionPosition(t.value)});const n=document.createElement("img");return n.src=t.iconPath,n.alt=t.label,n.draggable=!1,e.appendChild(n),e}async setup(){return this.setupPending=!0,this.setupInFlight||(this.setupInFlight=this.runSetupLoop()),this.setupInFlight}refresh(){return this.setup()}async runSetupLoop(){try{for(;this.setupPending;)this.setupPending=!1,await this.performSetup()}finally{this.setupInFlight=null}}async performSetup(){this.champions=await this.loadChampions(),this.championById=new Map(this.champions.map(n=>[n.id,n]));const t=this.getAllowedChampionIds();this.config=ut(this.configKey,{allowedChampionIds:t}),this.quickAction=this.config.quickAction===!0,this.selectedChampionIds=at(this.config.champions,t),this.enablePositionRestrictions&&(this.positionsByChampionId=x(this.config.positionsByChampionId,this.selectedChampionIds)),this.championDropdown.renderOptions(this.champions),this.renderSelectedChampions();const e=await this.championDropdown.waitForRender();e&&(this.championDropdown.ensureSearchPlaceholder(e),this.championDropdown.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=O(this.configKey,e=>(e.quickAction=e.quickAction!==!0,e),{allowedChampionIds:t,selectedChampionIds:this.selectedChampionIds}),this.quickAction=this.config.quickAction===!0,this.championDropdown.syncQuickActionToggle(),this.quickAction}addChampion(t){const e=d(t);e===null||!this.championById.has(e)||this.selectedChampionIds.includes(e)||(this.selectedChampionIds.push(e),this.renderSelectedChampions(),this.saveConfig())}removeChampion(t){const e=d(t),n=this.selectedChampionIds.indexOf(e);e===null||n===-1||(this.selectedChampionIds.splice(n,1),this.positionMenuChampionId===e&&this.closePositionMenu(),this.enablePositionRestrictions&&delete this.positionsByChampionId[String(e)],this.renderSelectedChampions(),this.saveConfig())}moveChampionToIndex(t,e){const n=d(t),i=this.selectedChampionIds.indexOf(n);if(n===null||i===-1)return!1;const[s]=this.selectedChampionIds.splice(i,1),r=Math.max(0,Math.min(e,this.selectedChampionIds.length));return this.selectedChampionIds.splice(r,0,s),i!==r}syncPositionsByChampionId(){this.enablePositionRestrictions&&(this.positionsByChampionId=x(this.positionsByChampionId,this.selectedChampionIds))}saveConfig(){this.syncPositionsByChampionId();const t=this.getAllowedChampionIds();this.config=O(this.configKey,e=>(e.champions=[...this.selectedChampionIds],this.enablePositionRestrictions&&(e.positionsByChampionId={...this.positionsByChampionId}),e),{allowedChampionIds:t,selectedChampionIds:this.selectedChampionIds}),this.enablePositionRestrictions&&(this.positionsByChampionId=this.config.positionsByChampionId||{}),console.debug(this.configKey,this.config)}renderSelectedChampions(t=null,e=null){this.positionMenuChampionId!==null&&this.closePositionMenu();const n=new Set(this.selectedChampionIds);for(const[s,r]of this.iconButtons)n.has(s)||(r.remove(),this.iconButtons.delete(s));if(this.selectedChampionIds.length===0){this.trackElement.replaceChildren(this.emptyElement);return}this.emptyElement.remove();const i=this.selectedChampionIds.map((s,r)=>this.getIconButton(s,r)).filter(Boolean);this.trackElement.append(...i),t&&this.animateReorder(t,e)}getIconButton(t,e){const n=this.championById.get(t);if(!n)return null;let i=this.iconButtons.get(t);i||(i=this.createIconButton(n),this.iconButtons.set(t,i)),i.dataset.rank=String(e+1);const s=this.getChampionPositionTitleSuffix(t);i.title=`${e+1}. ${n.name}${s}`,i.setAttribute("aria-label",`${e+1}. ${n.name}${s}`);const r=i.querySelector("img");r.src=n.squarePortraitPath,r.alt=n.name;const a=i.querySelector(ie);return a.setAttribute("aria-label",`Remove ${n.name}`),a.title=`Remove ${n.name}`,this.renderPositionBadge(i,t),i}createIconButton(t){const e=document.createElement("div");e.classList.add("champion-priority-selector__icon"),e.setAttribute("role","button"),e.tabIndex=0;const n=document.createElement("img");n.draggable=!1;const i=document.createElement("button");return i.classList.add("champion-priority-selector__remove"),i.type="button",i.dataset.icon=se,i.addEventListener("pointerdown",s=>s.stopPropagation()),i.addEventListener("click",s=>{s.stopPropagation(),this.removeChampion(t.id)}),e.addEventListener("pointerdown",s=>this.startDrag(s,t.id)),e.addEventListener("auxclick",s=>this.removeChampionOnMiddleClick(s,t.id)),this.enablePositionRestrictions&&e.addEventListener("contextmenu",s=>this.openPositionMenu(s,t.id)),e.append(n,i),e}getChampionAllowedPositions(t){const e=d(t);return e===null?[]:this.positionsByChampionId[String(e)]||[]}getChampionAllowedPositionLabels(t){return this.getChampionAllowedPositions(t).map(e=>{var n;return(n=U(e))==null?void 0:n.label}).filter(Boolean)}getChampionPositionTitleSuffix(t){const e=this.getChampionAllowedPositionLabels(t);return e.length>0?` (${e.join(", ")})`:""}renderPositionBadge(t,e){var i;if((i=t.querySelector(ne))==null||i.remove(),!this.enablePositionRestrictions)return;const n=this.createPositionBadge(e);n&&t.appendChild(n)}createPositionBadge(t){const e=this.getChampionAllowedPositions(t),n=this.getChampionAllowedPositionLabels(t),i=document.createElement("button");if(i.classList.add("champion-priority-selector__position-badge"),i.type="button",i.title=n.length>0?`${n.join(", ")}. Click to edit positions.`:"Any position. Click to restrict positions.",i.setAttribute("aria-label",i.title),i.addEventListener("pointerdown",a=>a.stopPropagation()),i.addEventListener("click",a=>this.openPositionMenu(a,t,i)),e.length===0)return i.classList.add("champion-priority-selector__position-badge--empty"),i.innerText="+",i;const s=U(e[0]);if(!s)return null;e.length>1&&(i.dataset.count=String(e.length));const r=document.createElement("img");return r.src=s.iconPath,r.alt=s.label,r.draggable=!1,i.appendChild(r),i}openPositionMenu(t,e,n=null){if(!this.enablePositionRestrictions||!this.positionMenuElement)return;const i=d(e);if(i===null||!this.selectedChampionIds.includes(i))return;t.preventDefault(),t.stopPropagation(),this.positionMenuChampionId=i,this.renderPositionMenu(),this.positionMenuElement.hidden=!1,this.positionMenuElement.style.left="0px",this.positionMenuElement.style.top="0px";const{left:s,top: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,I),window.innerWidth-n.width-I),a=Math.min(Math.max(s,I),window.innerHeight-n.height-I);return{left:r,top:a}}renderPositionMenu(){if(!this.positionMenuElement||this.positionMenuChampionId===null)return;const t=new Set(this.getChampionAllowedPositions(this.positionMenuChampionId));this.positionMenuElement.querySelectorAll(oe).forEach(e=>{const n=t.has(e.dataset.position);e.classList.toggle("champion-priority-selector__position-option--selected",n),e.setAttribute("aria-pressed",String(n))})}toggleChampionPosition(t){if(!this.enablePositionRestrictions||this.positionMenuChampionId===null)return;const e=T(t);if(!e)return;const n=String(this.positionMenuChampionId),i=new Set(this.positionsByChampionId[n]||[]);i.has(e)?i.delete(e):i.add(e);const s=k.map(c=>c.value).filter(c=>i.has(c));s.length>0?this.positionsByChampionId[n]=s:delete this.positionsByChampionId[n],this.renderPositionMenu();const r=this.iconButtons.get(this.positionMenuChampionId),a=this.selectedChampionIds.indexOf(this.positionMenuChampionId);r&&a!==-1&&this.getIconButton(this.positionMenuChampionId,a),this.saveConfig()}closePositionMenuOnOutsidePointerDown(t){var e;(e=this.positionMenuElement)!=null&&e.contains(t.target)||this.closePositionMenu()}closePositionMenuOnKeyDown(t){t.key==="Escape"&&this.closePositionMenu()}closePositionMenu(){this.positionMenuElement&&(this.positionMenuElement.hidden=!0,this.positionMenuChampionId=null,document.removeEventListener("pointerdown",this.handlePositionMenuOutsidePointerDown,!0),document.removeEventListener("keydown",this.handlePositionMenuKeyDown,!0))}startDrag(t,e){var i;if(t.button===tt){t.preventDefault();return}if(t.button!==re)return;this.dragState&&this.clearDragState();const n=this.iconButtons.get(e);if(n){this.dragState={championId:e,pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,active:!1,moved:!1};try{(i=n.setPointerCapture)==null||i.call(n,t.pointerId)}catch{}window.addEventListener("pointermove",this.handleWindowPointerMove),window.addEventListener("pointerup",this.handleWindowPointerUp),window.addEventListener("pointercancel",this.handleWindowPointerCancel)}}removeChampionOnMiddleClick(t,e){t.button===tt&&(t.preventDefault(),t.stopPropagation(),this.removeChampion(e))}moveDrag(t){var h;if(!this.dragState||this.dragState.pointerId!==t.pointerId)return;const e=this.dragState.championId,n=t.clientX-this.dragState.startX,i=t.clientY-this.dragState.startY,s=Math.hypot(n,i);if(!this.dragState.active){if(s<ae)return;this.dragState.active=!0,(h=this.iconButtons.get(e))==null||h.classList.add("champion-priority-selector__icon--dragging")}t.preventDefault();const r=this.getDropIndex(t.clientX,e),a=this.selectedChampionIds.indexOf(e);if(r===a||r===-1)return;const c=this.getIconPositions();this.moveChampionToIndex(e,r)&&(this.dragState.moved=!0,this.renderSelectedChampions(c,e))}finishDrag(t){if(!this.dragState||this.dragState.pointerId!==t.pointerId)return;const e=this.dragState.active,n=this.dragState.moved;this.clearDragState(),e&&n&&this.saveConfig()}cancelDrag(t){!this.dragState||this.dragState.pointerId!==t.pointerId||this.clearDragState()}clearDragState(){var i;if(!this.dragState)return;const{championId:t,pointerId:e}=this.dragState,n=this.iconButtons.get(t);n==null||n.classList.remove("champion-priority-selector__icon--dragging");try{(i=n==null?void 0:n.releasePointerCapture)==null||i.call(n,e)}catch{}window.removeEventListener("pointermove",this.handleWindowPointerMove),window.removeEventListener("pointerup",this.handleWindowPointerUp),window.removeEventListener("pointercancel",this.handleWindowPointerCancel),this.dragState=null}getDropIndex(t,e){const n=this.selectedChampionIds.filter(i=>i!==e);for(let i=0;i<n.length;i++){const s=this.iconButtons.get(n[i]);if(!s)continue;const r=s.getBoundingClientRect();if(t<r.left+r.width/2)return i}return n.length}getIconPositions(){const t=new Map;for(const e of this.selectedChampionIds){const n=this.iconButtons.get(e);n&&t.set(e,n.getBoundingClientRect())}return t}animateReorder(t,e){for(const n of this.selectedChampionIds){if(n===e)continue;const i=this.iconButtons.get(n),s=t.get(n);if(!i||!s||typeof i.animate!="function")continue;const r=i.getBoundingClientRect(),a=s.left-r.left,c=s.top-r.top;a===0&&c===0||i.animate([{transform:`translate(${a}px, ${c}px)`},{transform:"translate(0, 0)"}],{duration:ce,easing:le})}}}const de=200,M="auto-select-champ-select-menu--collapsed",he="auto-select-champ-select-menu-button-wrapper--open";class R{constructor(t,e){this.element=document.createElement(m.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=ut(this.configKey),this.element.toggleAttribute("selected",this.config.enabled===!0)}toggle(){return console.debug("auto-champion-select: Toggling",this.configKey),this.config=O(this.configKey,t=>(t.enabled=!t.enabled,t)),this.element.toggleAttribute("selected",this.config.enabled===!0),this.config.enabled}}class ue{constructor(t,e,n){this.element=document.createElement("div"),this.element.classList.add("auto-select-champ-select-menu",M),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(M)}setOpen(t){this.element.classList.toggle(M,!t),this.buttonWrapper.classList.toggle(he,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=D();for(;this.mounted&&!t;)await g(de),t=D();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 pe{constructor(t,...e){this.element=document.createElement(m.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 N(o){var t,e;o&&((e=(t=globalThis.Toast)==null?void 0:t.error)==null||e.call(t,o))}function me(o,t){const e=globalThis.Toast;return typeof(e==null?void 0:e.promise)=="function"?e.promise(o,t):o}const S="Balaclava: Auto Champion Select";function fe(o){return typeof(o==null?void 0:o.then)=="function"}class q{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(fe(t))return me(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){N(this.toasts.error),console.error(t)}}}class At extends q{constructor(t,e,n){super({id:`${e}Switch`,name:()=>`Auto ${t} [${b(e).enabled?"ON":"OFF"}]`,legend:()=>b(e).enabled?"Turn OFF":"Turn ON",tags:[S,e,"switch"],group:S,callback:n,toasts:{on:`Auto ${t} is ON!`,off:`Auto ${t} is OFF!`,error:`Failed to toggle Auto ${t}. Check console.`}})}}function ge(o){return O(o,e=>(e.force=!e.force,e)).force}class St extends q{constructor(t,e){super({id:`${e}ForceSwitch`,name:()=>`Force ${t} [${b(e).force?"ON":"OFF"}]`,legend:()=>`Ignore team intent and force ${t} the selected champion`,tags:[S,e,"force","switch"],group:S,callback:()=>ge(e),toasts:{on:`Force ${t} is ON!`,off:`Force ${t} is OFF!`,error:`Failed to toggle Force ${t}. Check console.`}})}}class Ce extends q{constructor(t){super({id:"RefreshDropdowns",name:()=>"Refresh Champions",legend:()=>"Normally champion selectors refresh automatically...",tags:[S,"refresh"],group:S,callback:t,toasts:{success:"Refreshed Champions!",error:"Failed to refresh Champions. Check console."}})}}class we extends At{constructor(t){super("Pick","controladoPick",t)}}class be extends At{constructor(t){super("Ban","controladoBan",t)}}class ye extends St{constructor(){super("Pick","controladoPick")}}class Ae extends St{constructor(){super("Ban","controladoBan")}}function Se(o){for(const t of o)CommandBar.addAction(t)}const Ee=200,Pe=6e4,nt=2e3,Ie=".ready-check-root-element",ke="#lol-uikit-layer-manager-wrapper > .modal",Oe="Accepted ready check!",ot="Failed to accept ready check. Check console.",Te=".auto-select-champ-select-menu__header",A=Object.freeze({autoAccept:"controladoAutoAccept",pick:"controladoPick",ban:"controladoBan"});function Et(){return b(A.autoAccept).enabled===!0}class _e{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=Le();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);it(t,"display",e==null?void 0:e.display,e==null?void 0:e.displayPriority),it(t,"pointer-events",e==null?void 0:e.pointerEvents,e==null?void 0:e.pointerEventsPriority),this.hiddenModalStyles.delete(t),this.hiddenModal=null}}function Le(){const o=document.querySelector(Ie);return(o==null?void 0:o.closest(ke))||null}function it(o,t,e,n){e?o.style.setProperty(t,e,n||""):o.style.removeProperty(t)}async function ve(o){function t(){return Et()?!1:(o.restore(),!0)}if(t()||(console.debug(`auto-champion-select(auto-accept): Ready check detected, accepting in ${nt}ms...`),await g(nt),t()))return;let e=!1;try{e=await Me()}catch(n){throw o.restore(),N(ot),n}e?yt(Oe):(o.restore(),N(ot))}async function Me(){const o=await w("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 Re(o){const t=await w("GET",p.gameflowPhase),e=t.ok?await t.json():null;o.handleGameflowPhase(e)}function xe({championSelect:o,champSelectControlsMenu:t,readyCheckModalSuppressor:e,setupChampionSelectors:n}){let i=0;return async function(c){const h=++i;try{await s(c,h)}catch(u){console.error("auto-champion-select: Failed to handle gameflow phase",u)}};async function s(a,c){a==="ReadyCheck"?ve(e).catch(h=>{console.error("auto-champion-select(auto-accept): Failed to handle ready check",h)}):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 Be(){const o=new Wt,t=new R("Accept",A.autoAccept),e=new R("Pick",A.pick),n=new et("Add pick",A.pick,zt,{enablePositionRestrictions:!0,quickActionLabel:"Pick instantly"}),i=new R("Ban",A.ban),s=new et("Add ban",A.ban,Ut,{quickActionLabel:"Ban instantly"}),r=De(n,s),a=Ne(t,e,i),c=new pe("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 De(...o){const t=document.createElement("div");return t.append(...o.map(e=>e.element)),t}function Ne(...o){const t=document.createElement("div");return t.classList.add("auto-select-checkboxes-div"),t.append(...o.map(e=>e.element)),t}function $e({pluginSection:o,checkboxesContainer:t,selectorsContainer:e}){let n=null,i=0,s=()=>!1;async function r(a){let c=V();for(;!c;){if(s()||a!==i)return;await g(Ee),c=V()}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 Fe({autoAcceptToggle:o,pickToggle:t,banToggle:e,readyCheckModalSuppressor:n}){o.setup(),o.element.addEventListener("click",()=>n.sync()),t.setup(),e.setup()}async function qe(o){await Promise.all(o.map(t=>t.setup()))}async function ze(o){await Promise.all(o.map(t=>t.refresh()))}function Ue(){const o=Be(),t=new _e(Et),e=$e(o),n=new ue("Auto Champion Select",e.returnControlsToSocialRoster,[o.checkboxesContainer,o.selectorsContainer]);e.setIsChampSelectControlsMounted(()=>n.mounted);const i={...o,champSelectControlsMenu:n,readyCheckModalSuppressor:t,setupToggles:()=>Fe({...o,readyCheckModalSuppressor:t}),setupChampionSelectors:()=>qe(o.championSelectors),refreshChampionSelectors:()=>ze(o.championSelectors),refreshPickChampionSelector:async()=>{await o.pickChampionSelector.refresh()}};return i.handleGameflowPhase=xe(i),i}function Ge(o){z(p.gameflowPhase,t=>{o.handleGameflowPhase(t.data)}),z(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 He({pickToggle:o,banToggle:t,refreshChampionSelectors:e}){Se([new we(()=>o.toggle()),new be(()=>t.toggle()),new ye,new Ae,new Ce(e)])}function Ye(o){let t=null,e=null;function n(){e==null||e.disconnect(),e=null,t!==null&&(cancelAnimationFrame(t),t=null)}const i=setTimeout(()=>{n()},Pe);function s(){if(!(D()!==null))return;clearTimeout(i),n(),document.querySelector(Te)!==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 Qe(){const o=Ue();o.setupToggles(),o.readyCheckModalSuppressor.start(),He(o),Ge(o),await Re(o),Ye(o),console.debug(`auto-champion-select(${Pt}): Report bugs to Balaclava#1912`)}let st=!1;function rt(){st||(st=!0,Qe().catch(o=>console.error("auto-champion-select: Failed to initialize",o)))}document.readyState==="loading"?window.addEventListener("load",rt,{once:!0}):rt();export{rt as load};
|
|
231
|
+
`;function st(o){const t=document.createElement(m.dropdownOption);return t.setAttribute("slot",m.dropdownOption),t.innerText=o,t}class ce{constructor(t,e,n,i={}){this.dropdownElement=t,this.placeholderText=e,this.searchPlaceholderText=i.searchPlaceholderText||"Search",this.quickActionLabel=i.quickActionLabel||"Pick/ban instantly",this.isQuickActionEnabled=typeof i.isQuickActionEnabled=="function"?i.isQuickActionEnabled:null,this.onQuickActionToggle=typeof i.onQuickActionToggle=="function"?i.onQuickActionToggle:null,this.onChampionSelected=n,this.placeholderOption=null,this.searchQuery="",this.activePositionFilter=null,this.hasRecommendedPositionData=!1,this.recommendedPositionsByOption=new WeakMap}renderOptions(t){this.dropdownElement.replaceChildren(),this.hasRecommendedPositionData=!1,this.placeholderOption=st(this.placeholderText),this.placeholderOption.setAttribute("selected","true"),this.hidePlaceholderOption(),this.dropdownElement.appendChild(this.placeholderOption);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=st("");return this.recommendedPositionsByOption.set(n,new Set(e)),n.title=t.name,n.appendChild(this.createChampionOptionContent(t)),n.addEventListener("click",()=>{this.onChampionSelected(t.id),requestAnimationFrame(()=>this.reset())}),n}createChampionOptionContent(t){const e=document.createElement("span");e.classList.add(se);const n=document.createElement("img");n.classList.add(re),n.src=t.squarePortraitPath,n.alt="",n.draggable=!1,n.loading="lazy";const i=document.createElement("span");return i.classList.add(ae),i.innerText=t.name,e.append(n,i),e}getChampionRecommendedPositions(t){return Array.isArray(t.recommendedPositions)?t.recommendedPositions:[]}async waitForRender(){for(let t=0;t<ne;t++){const e=this.dropdownElement.shadowRoot;if(this.dropdownElement.isConnected&&(e!=null&&e.querySelector(l.dropdownCurrent)))return e;await C(oe)}return null}ensureSearchPlaceholder(t){if(t.querySelector(`#${nt}`))return;const e=t.querySelector(l.dropdownCurrent);e&&e.appendChild(this.createSearchPlaceholder())}ensureQuickActionToggle(t){if(!this.isQuickActionAvailable()||t.querySelector(`#${B}`)){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(q),this.activePositionFilter=null;return}e.classList.add(q),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 I)t.appendChild(this.createPositionFilterBadge(e));return t}createPositionFilterBadge(t){const e=document.createElement("button");e.classList.add(g),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(Et,At),t.id=nt;const e=document.createElement("input");e.classList.add(Pt),e.id=ot,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(It),n.addEventListener("click",()=>{n.classList.contains(P)&&this.clearSearch(e,n)}),e.addEventListener("input",i=>{this.ensureOpen(),this.setSearchQuery(i.target.value),n.classList.toggle(P,!!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(E),t.id=B,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(`#${B}`);if(!e)return;const n=this.isQuickActionEnabled()===!0;e.classList.toggle(St,n),e.setAttribute("aria-pressed",String(n)),e.title=this.quickActionLabel,e.setAttribute("aria-label",this.quickActionLabel)}togglePositionFilter(t){const e=k(t);e&&(this.activePositionFilter=this.activePositionFilter===e?null:e,this.withShadowRoot(n=>this.syncPositionFilter(n)),this.applyOptionFilters())}syncPositionFilter(t){t.querySelectorAll(`.${g}`).forEach(e=>{const n=e.dataset.position===this.activePositionFilter;e.classList.toggle(z,n),e.setAttribute("aria-pressed",String(n))})}clearSearch(t,e){t.value="",this.setSearchQuery(""),e.classList.toggle(P,!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.activePositionFilter?((e=this.recommendedPositionsByOption.get(t))==null?void 0:e.has(this.activePositionFilter))===!0:!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(`#${ot}`),i=e.querySelector(`.${P}`);n&&i?this.clearSearch(n,i):(n&&(n.value="",this.setSearchQuery("")),i&&i.classList.remove(P)),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=it;return}const n=document.createElement("style");n.dataset.controlado="dropdown-tags",n.textContent=it,t.appendChild(n)}withShadowRoot(t){const e=this.dropdownElement.shadowRoot;e&&t(e)}}const le=".champion-priority-selector__position-badge",de=".champion-priority-selector__position-option",he=".champion-priority-selector__remove",ue="✕",pe=0,rt=1,T=8,me=5,fe=150,ge="cubic-bezier(0.2, 0, 0, 1)";class at{constructor(t,e,n,i={}){this.element=this.createRootElement(),this.dropdownElement=this.createDropdownElement(),this.championDropdown=new ce(this.dropdownElement,t,a=>this.addChampion(a),{quickActionLabel:i.quickActionLabel,searchPlaceholderText:i.searchPlaceholderText,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.positionMenuElement=this.enablePositionRestrictions?this.createPositionMenu():null,this.positionMenuChampionId=null,this.positionsByChampionId={},this.emptyElement=this.createEmptyState(t),this.element.append(this.dropdownElement,this.scrollElement),this.positionMenuElement&&this.element.appendChild(this.positionMenuElement),this.config=null,this.configKey=e,this.quickAction=!1,this.loadChampions=n,this.champions=[],this.championById=new Map,this.selectedChampionIds=[],this.iconButtons=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(m.dropdown);return t.classList.add("dropdown-champions-default","dropdown-drop-up"),t}createSelectedChampionsScroll(){const t=document.createElement(m.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 I)t.appendChild(this.createPositionOption(e));return t}createPositionOption(t){const e=document.createElement("button");e.classList.add("champion-priority-selector__position-option"),e.type="button",e.dataset.position=t.value,e.title=t.label,e.setAttribute("aria-label",t.label),e.setAttribute("aria-pressed","false"),e.addEventListener("pointerdown",i=>i.stopPropagation()),e.addEventListener("click",i=>{i.stopPropagation(),this.toggleChampionPosition(t.value)});const n=document.createElement("img");return n.src=t.iconPath,n.alt=t.label,n.draggable=!1,e.appendChild(n),e}async setup(){return this.setupPending=!0,this.setupInFlight||(this.setupInFlight=this.runSetupLoop()),this.setupInFlight}refresh(){return this.setup()}async runSetupLoop(){try{for(;this.setupPending;)this.setupPending=!1,await this.performSetup()}finally{this.setupInFlight=null}}async performSetup(){this.champions=await this.loadChampions(),this.championById=new Map(this.champions.map(n=>[n.id,n]));const t=this.getAllowedChampionIds();this.config=bt(this.configKey,{allowedChampionIds:t}),this.quickAction=this.config.quickAction===!0,this.selectedChampionIds=pt(this.config.champions,t),this.enablePositionRestrictions&&(this.positionsByChampionId=L(this.config.positionsByChampionId,this.selectedChampionIds)),this.championDropdown.renderOptions(this.champions),this.renderSelectedChampions();const e=await this.championDropdown.waitForRender();e&&(this.championDropdown.ensureSearchPlaceholder(e),this.championDropdown.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=v(this.configKey,e=>(e.quickAction=e.quickAction!==!0,e),{allowedChampionIds:t,selectedChampionIds:this.selectedChampionIds}),this.quickAction=this.config.quickAction===!0,this.championDropdown.syncQuickActionToggle(),this.quickAction}addChampion(t){const e=d(t);e===null||!this.championById.has(e)||this.selectedChampionIds.includes(e)||(this.selectedChampionIds.push(e),this.renderSelectedChampions(),this.saveConfig())}removeChampion(t){const e=d(t),n=this.selectedChampionIds.indexOf(e);e===null||n===-1||(this.selectedChampionIds.splice(n,1),this.positionMenuChampionId===e&&this.closePositionMenu(),this.enablePositionRestrictions&&delete this.positionsByChampionId[String(e)],this.renderSelectedChampions(),this.saveConfig())}moveChampionToIndex(t,e){const n=d(t),i=this.selectedChampionIds.indexOf(n);if(n===null||i===-1)return!1;const[s]=this.selectedChampionIds.splice(i,1),r=Math.max(0,Math.min(e,this.selectedChampionIds.length));return this.selectedChampionIds.splice(r,0,s),i!==r}syncPositionsByChampionId(){this.enablePositionRestrictions&&(this.positionsByChampionId=L(this.positionsByChampionId,this.selectedChampionIds))}saveConfig(){this.syncPositionsByChampionId();const t=this.getAllowedChampionIds();this.config=v(this.configKey,e=>(e.champions=[...this.selectedChampionIds],this.enablePositionRestrictions&&(e.positionsByChampionId={...this.positionsByChampionId}),e),{allowedChampionIds:t,selectedChampionIds:this.selectedChampionIds}),this.enablePositionRestrictions&&(this.positionsByChampionId=this.config.positionsByChampionId||{}),console.debug(this.configKey,this.config)}renderSelectedChampions(t=null,e=null){this.positionMenuChampionId!==null&&this.closePositionMenu();const n=new Set(this.selectedChampionIds);for(const[s,r]of this.iconButtons)n.has(s)||(r.remove(),this.iconButtons.delete(s));if(this.selectedChampionIds.length===0){this.trackElement.replaceChildren(this.emptyElement);return}this.emptyElement.remove();const i=this.selectedChampionIds.map((s,r)=>this.getIconButton(s,r)).filter(Boolean);this.trackElement.append(...i),t&&this.animateReorder(t,e)}getIconButton(t,e){const n=this.championById.get(t);if(!n)return null;let i=this.iconButtons.get(t);i||(i=this.createIconButton(n),this.iconButtons.set(t,i)),i.dataset.rank=String(e+1);const s=this.getChampionPositionTitleSuffix(t);i.title=`${e+1}. ${n.name}${s}`,i.setAttribute("aria-label",`${e+1}. ${n.name}${s}`);const r=i.querySelector("img");r.src=n.squarePortraitPath,r.alt=n.name;const a=i.querySelector(he);return a.setAttribute("aria-label",`Remove ${n.name}`),a.title=`Remove ${n.name}`,this.renderPositionBadge(i,t),i}createIconButton(t){const e=document.createElement("div");e.classList.add("champion-priority-selector__icon"),e.setAttribute("role","button"),e.tabIndex=0;const n=document.createElement("img");n.draggable=!1;const i=document.createElement("button");return i.classList.add("champion-priority-selector__remove"),i.type="button",i.dataset.icon=ue,i.addEventListener("pointerdown",s=>s.stopPropagation()),i.addEventListener("click",s=>{s.stopPropagation(),this.removeChampion(t.id)}),e.addEventListener("pointerdown",s=>this.startDrag(s,t.id)),e.addEventListener("auxclick",s=>this.removeChampionOnMiddleClick(s,t.id)),this.enablePositionRestrictions&&e.addEventListener("contextmenu",s=>this.openPositionMenu(s,t.id)),e.append(n,i),e}getChampionAllowedPositions(t){const e=d(t);return e===null?[]:this.positionsByChampionId[String(e)]||[]}getChampionAllowedPositionLabels(t){return this.getChampionAllowedPositions(t).map(e=>{var n;return(n=j(e))==null?void 0:n.label}).filter(Boolean)}getChampionPositionTitleSuffix(t){const e=this.getChampionAllowedPositionLabels(t);return e.length>0?` (${e.join(", ")})`:""}renderPositionBadge(t,e){var i;if((i=t.querySelector(le))==null||i.remove(),!this.enablePositionRestrictions)return;const n=this.createPositionBadge(e);n&&t.appendChild(n)}createPositionBadge(t){const e=this.getChampionAllowedPositions(t),n=this.getChampionAllowedPositionLabels(t),i=document.createElement("button");if(i.classList.add("champion-priority-selector__position-badge"),i.type="button",i.title=n.length>0?`${n.join(", ")}. Click to edit positions.`:"Any position. Click to restrict positions.",i.setAttribute("aria-label",i.title),i.addEventListener("pointerdown",a=>a.stopPropagation()),i.addEventListener("click",a=>this.openPositionMenu(a,t,i)),e.length===0)return i.classList.add("champion-priority-selector__position-badge--empty"),i.innerText="+",i;const s=j(e[0]);if(!s)return null;e.length>1&&(i.dataset.count=String(e.length));const r=document.createElement("img");return r.src=s.iconPath,r.alt=s.label,r.draggable=!1,i.appendChild(r),i}openPositionMenu(t,e,n=null){if(!this.enablePositionRestrictions||!this.positionMenuElement)return;const i=d(e);if(i===null||!this.selectedChampionIds.includes(i))return;t.preventDefault(),t.stopPropagation(),this.positionMenuChampionId=i,this.renderPositionMenu(),this.positionMenuElement.hidden=!1,this.positionMenuElement.style.left="0px",this.positionMenuElement.style.top="0px";const{left:s,top: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,T),window.innerWidth-n.width-T),a=Math.min(Math.max(s,T),window.innerHeight-n.height-T);return{left:r,top:a}}renderPositionMenu(){if(!this.positionMenuElement||this.positionMenuChampionId===null)return;const t=new Set(this.getChampionAllowedPositions(this.positionMenuChampionId));this.positionMenuElement.querySelectorAll(de).forEach(e=>{const n=t.has(e.dataset.position);e.classList.toggle("champion-priority-selector__position-option--selected",n),e.setAttribute("aria-pressed",String(n))})}toggleChampionPosition(t){if(!this.enablePositionRestrictions||this.positionMenuChampionId===null)return;const e=k(t);if(!e)return;const n=String(this.positionMenuChampionId),i=new Set(this.positionsByChampionId[n]||[]);i.has(e)?i.delete(e):i.add(e);const s=I.map(c=>c.value).filter(c=>i.has(c));s.length>0?this.positionsByChampionId[n]=s:delete this.positionsByChampionId[n],this.renderPositionMenu();const r=this.iconButtons.get(this.positionMenuChampionId),a=this.selectedChampionIds.indexOf(this.positionMenuChampionId);r&&a!==-1&&this.getIconButton(this.positionMenuChampionId,a),this.saveConfig()}closePositionMenuOnOutsidePointerDown(t){var e;(e=this.positionMenuElement)!=null&&e.contains(t.target)||this.closePositionMenu()}closePositionMenuOnKeyDown(t){t.key==="Escape"&&this.closePositionMenu()}closePositionMenu(){this.positionMenuElement&&(this.positionMenuElement.hidden=!0,this.positionMenuChampionId=null,document.removeEventListener("pointerdown",this.handlePositionMenuOutsidePointerDown,!0),document.removeEventListener("keydown",this.handlePositionMenuKeyDown,!0))}startDrag(t,e){var i;if(t.button===rt){t.preventDefault();return}if(t.button!==pe)return;this.dragState&&this.clearDragState();const n=this.iconButtons.get(e);if(n){this.dragState={championId:e,pointerId:t.pointerId,startX:t.clientX,startY:t.clientY,active:!1,moved:!1};try{(i=n.setPointerCapture)==null||i.call(n,t.pointerId)}catch{}window.addEventListener("pointermove",this.handleWindowPointerMove),window.addEventListener("pointerup",this.handleWindowPointerUp),window.addEventListener("pointercancel",this.handleWindowPointerCancel)}}removeChampionOnMiddleClick(t,e){t.button===rt&&(t.preventDefault(),t.stopPropagation(),this.removeChampion(e))}moveDrag(t){var h;if(!this.dragState||this.dragState.pointerId!==t.pointerId)return;const e=this.dragState.championId,n=t.clientX-this.dragState.startX,i=t.clientY-this.dragState.startY,s=Math.hypot(n,i);if(!this.dragState.active){if(s<me)return;this.dragState.active=!0,(h=this.iconButtons.get(e))==null||h.classList.add("champion-priority-selector__icon--dragging")}t.preventDefault();const r=this.getDropIndex(t.clientX,e),a=this.selectedChampionIds.indexOf(e);if(r===a||r===-1)return;const c=this.getIconPositions();this.moveChampionToIndex(e,r)&&(this.dragState.moved=!0,this.renderSelectedChampions(c,e))}finishDrag(t){if(!this.dragState||this.dragState.pointerId!==t.pointerId)return;const e=this.dragState.active,n=this.dragState.moved;this.clearDragState(),e&&n&&this.saveConfig()}cancelDrag(t){!this.dragState||this.dragState.pointerId!==t.pointerId||this.clearDragState()}clearDragState(){var i;if(!this.dragState)return;const{championId:t,pointerId:e}=this.dragState,n=this.iconButtons.get(t);n==null||n.classList.remove("champion-priority-selector__icon--dragging");try{(i=n==null?void 0:n.releasePointerCapture)==null||i.call(n,e)}catch{}window.removeEventListener("pointermove",this.handleWindowPointerMove),window.removeEventListener("pointerup",this.handleWindowPointerUp),window.removeEventListener("pointercancel",this.handleWindowPointerCancel),this.dragState=null}getDropIndex(t,e){const n=this.selectedChampionIds.filter(i=>i!==e);for(let i=0;i<n.length;i++){const s=this.iconButtons.get(n[i]);if(!s)continue;const r=s.getBoundingClientRect();if(t<r.left+r.width/2)return i}return n.length}getIconPositions(){const t=new Map;for(const e of this.selectedChampionIds){const n=this.iconButtons.get(e);n&&t.set(e,n.getBoundingClientRect())}return t}animateReorder(t,e){for(const n of this.selectedChampionIds){if(n===e)continue;const i=this.iconButtons.get(n),s=t.get(n);if(!i||!s||typeof i.animate!="function")continue;const r=i.getBoundingClientRect(),a=s.left-r.left,c=s.top-r.top;a===0&&c===0||i.animate([{transform:`translate(${a}px, ${c}px)`},{transform:"translate(0, 0)"}],{duration:fe,easing:ge})}}}const Ce=200,D="auto-select-champ-select-menu--collapsed",be="auto-select-champ-select-menu-button-wrapper--open";class F{constructor(t,e){this.element=document.createElement(m.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=bt(this.configKey),this.element.toggleAttribute("selected",this.config.enabled===!0)}toggle(){return console.debug("auto-champion-select: Toggling",this.configKey),this.config=v(this.configKey,t=>(t.enabled=!t.enabled,t)),this.element.toggleAttribute("selected",this.config.enabled===!0),this.config.enabled}}class we{constructor(t,e,n){this.element=document.createElement("div"),this.element.classList.add("auto-select-champ-select-menu",D),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(D)}setOpen(t){this.element.classList.toggle(D,!t),this.buttonWrapper.classList.toggle(be,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=N();for(;this.mounted&&!t;)await C(Ce),t=N();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 ye{constructor(t,...e){this.element=document.createElement(m.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 kt(o){var t,e;o&&((e=(t=globalThis.Toast)==null?void 0:t.success)==null||e.call(t,o))}function G(o){var t,e;o&&((e=(t=globalThis.Toast)==null?void 0:t.error)==null||e.call(t,o))}function Pe(o,t){const e=globalThis.Toast;return typeof(e==null?void 0:e.promise)=="function"?e.promise(o,t):o}const S="Balaclava: Auto Champion Select";function Ae(o){return typeof(o==null?void 0:o.then)=="function"}class Y{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(Ae(t))return Pe(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);kt(e)}catch(t){G(this.toasts.error),console.error(t)}}}class Ot extends Y{constructor(t,e,n){super({id:`${e}Switch`,name:()=>`Auto ${t} [${y(e).enabled?"ON":"OFF"}]`,legend:()=>y(e).enabled?"Turn OFF":"Turn ON",tags:[S,e,"switch"],group:S,callback:n,toasts:{on:`Auto ${t} is ON!`,off:`Auto ${t} is OFF!`,error:`Failed to toggle Auto ${t}. Check console.`}})}}function Se(o){return v(o,e=>(e.force=!e.force,e)).force}class Tt extends Y{constructor(t,e){super({id:`${e}ForceSwitch`,name:()=>`Force ${t} [${y(e).force?"ON":"OFF"}]`,legend:()=>`Ignore team intent and force ${t} the selected champion`,tags:[S,e,"force","switch"],group:S,callback:()=>Se(e),toasts:{on:`Force ${t} is ON!`,off:`Force ${t} is OFF!`,error:`Failed to toggle Force ${t}. Check console.`}})}}class Ee extends Y{constructor(t){super({id:"RefreshDropdowns",name:()=>"Refresh Champions",legend:()=>"Normally champion selectors refresh automatically...",tags:[S,"refresh"],group:S,callback:t,toasts:{success:"Refreshed Champions!",error:"Failed to refresh Champions. Check console."}})}}class Ie extends Ot{constructor(t){super("Pick","controladoPick",t)}}class ke extends Ot{constructor(t){super("Ban","controladoBan",t)}}class Oe extends Tt{constructor(){super("Pick","controladoPick")}}class Te extends Tt{constructor(){super("Ban","controladoBan")}}function _e(o){for(const t of o)CommandBar.addAction(t)}const Le=200,ve=6e4,ct=2e3,Re=".ready-check-root-element",Me="#lol-uikit-layer-manager-wrapper > .modal",xe="Accepted ready check!",lt="Failed to accept ready check. Check console.",Be=".auto-select-champ-select-menu__header",A=Object.freeze({autoAccept:"controladoAutoAccept",pick:"controladoPick",ban:"controladoBan"});function _t(){return y(A.autoAccept).enabled===!0}class De{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=Fe();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);dt(t,"display",e==null?void 0:e.display,e==null?void 0:e.displayPriority),dt(t,"pointer-events",e==null?void 0:e.pointerEvents,e==null?void 0:e.pointerEventsPriority),this.hiddenModalStyles.delete(t),this.hiddenModal=null}}function Fe(){const o=document.querySelector(Re);return(o==null?void 0:o.closest(Me))||null}function dt(o,t,e,n){e?o.style.setProperty(t,e,n||""):o.style.removeProperty(t)}async function $e(o){function t(){return _t()?!1:(o.restore(),!0)}if(t()||(console.debug(`auto-champion-select(auto-accept): Ready check detected, accepting in ${ct}ms...`),await C(ct),t()))return;let e=!1;try{e=await Ne()}catch(n){throw o.restore(),G(lt),n}e?kt(xe):(o.restore(),G(lt))}async function Ne(){const o=await b("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 qe(o){const t=await b("GET",p.gameflowPhase),e=t.ok?await t.json():null;o.handleGameflowPhase(e)}function ze({championSelect:o,champSelectControlsMenu:t,readyCheckModalSuppressor:e,setupChampionSelectors:n}){let i=0;return async function(c){const h=++i;try{await s(c,h)}catch(u){console.error("auto-champion-select: Failed to handle gameflow phase",u)}};async function s(a,c){a==="ReadyCheck"?$e(e).catch(h=>{console.error("auto-champion-select(auto-accept): Failed to handle ready check",h)}):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 Ge(){const o=new ee,t=new F("Accept",A.autoAccept),e=new F("Pick",A.pick),n=new at("Add pick",A.pick,Vt,{enablePositionRestrictions:!0,quickActionLabel:"Pick instantly"}),i=new F("Ban",A.ban),s=new at("Add ban",A.ban,Xt,{quickActionLabel:"Ban instantly"}),r=Ue(n,s),a=Qe(t,e,i),c=new ye("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 Ue(...o){const t=document.createElement("div");return t.append(...o.map(e=>e.element)),t}function Qe(...o){const t=document.createElement("div");return t.classList.add("auto-select-checkboxes-div"),t.append(...o.map(e=>e.element)),t}function He({pluginSection:o,checkboxesContainer:t,selectorsContainer:e}){let n=null,i=0,s=()=>!1;async function r(a){let c=et();for(;!c;){if(s()||a!==i)return;await C(Le),c=et()}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 Ye({autoAcceptToggle:o,pickToggle:t,banToggle:e,readyCheckModalSuppressor:n}){o.setup(),o.element.addEventListener("click",()=>n.sync()),t.setup(),e.setup()}async function We(o){await Promise.all(o.map(t=>t.setup()))}async function je(o){await Promise.all(o.map(t=>t.refresh()))}function Ve(){const o=Ge(),t=new De(_t),e=He(o),n=new we("Auto Champion Select",e.returnControlsToSocialRoster,[o.checkboxesContainer,o.selectorsContainer]);e.setIsChampSelectControlsMounted(()=>n.mounted);const i={...o,champSelectControlsMenu:n,readyCheckModalSuppressor:t,setupToggles:()=>Ye({...o,readyCheckModalSuppressor:t}),setupChampionSelectors:()=>We(o.championSelectors),refreshChampionSelectors:()=>je(o.championSelectors),refreshPickChampionSelector:async()=>{await o.pickChampionSelector.refresh()}};return i.handleGameflowPhase=ze(i),i}function Xe(o){W(p.gameflowPhase,t=>{o.handleGameflowPhase(t.data)}),W(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 Ke({pickToggle:o,banToggle:t,refreshChampionSelectors:e}){_e([new Ie(()=>o.toggle()),new ke(()=>t.toggle()),new Oe,new Te,new Ee(e)])}function Je(o){let t=null,e=null;function n(){e==null||e.disconnect(),e=null,t!==null&&(cancelAnimationFrame(t),t=null)}const i=setTimeout(()=>{n()},ve);function s(){if(!(N()!==null))return;clearTimeout(i),n(),document.querySelector(Be)!==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 Ze(){const o=Ve();o.setupToggles(),o.readyCheckModalSuppressor.start(),Ke(o),Xe(o),await qe(o),Je(o),console.debug(`auto-champion-select(${Lt}): Report bugs to Balaclava#1912`)}let ht=!1;function ut(){ht||(ht=!0,Ze().catch(o=>console.error("auto-champion-select: Failed to initialize",o)))}document.readyState==="loading"?window.addEventListener("load",ut,{once:!0}):ut();export{ut as load};
|