jonnybarnes.uk/public/assets/js/is-land.min.js
Jonny Barnes 6bc7f20783
Update composer and npm dependencies within semver ranges
Minor and patch updates only, including Laravel 13.22 -> 13.40.
Refresh the vendored is-land.min.js from the updated npm package.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 15:42:55 +00:00

2 lines
No EOL
5.6 KiB
JavaScript

//! <is-land>
const e=window,t=e.document,a=e.navigator;function r(){let e,t;return{promise:new Promise((a,r)=>{e=a,t=r}),resolve:e,reject:t}}class i extends HTMLElement{static attributePrefix="on:";static attr={template:"data-island",ready:"ready",defer:"defer-hydration",type:"type",import:"import",importMount:"import-mount"};static _tagNames=new Set;static _once=new Map;static ctm(){return"undefined"!=typeof globalThis}static define(t=e.customElements){let a="is-land";this.ctm()&&!t.get(a)&&t.define(a,this)}static _initTypes={default:async e=>{let t=e.getAttribute(i.attr.import),a=await(import(t));if(e.hasAttribute(i.attr.importMount)){if("function"!=typeof a.default)throw new Error(`[${i.attr.importMount}] expects a default export function: ${t}`);await a.default(e)}}};static addInitType(e,t){this._initTypes[e]=t}static setSwapBehavior(e){this._swapFn=e}static _fallback={};static addFallback(e,a){this._fallback[e]=a;let r=Array.from(this._tagNames);r.length&&t.querySelectorAll(r.map(e=>`${e}:defined`).join(",")).forEach(e=>{e.replaceFallbackContent()})}getFallback(){return Object.assign({[`:not(:defined):not(${this.localName}):not([${i.attr.defer}])`]:(e,t)=>{let a=i.renameNode(e,t+e.localName);return()=>{a.shadowRoot&&e.shadowRoot.append(...a.shadowRoot.childNodes),e.append(...a.childNodes),a.replaceWith(e)}}},i._fallback)}static renameNode(e,a){let r=t.createElement(a);for(let t of e.getAttributeNames())r.setAttribute(t,e.getAttribute(t));let i=e.shadowRoot;if(!i){let t=e.querySelector(":scope > template[shadowrootmode], :scope > template[shadowroot]");if(t){let a=t.getAttribute("shadowrootmode")||t.getAttribute("shadowroot")||"closed";i=e.attachShadow({mode:a}),i.appendChild(t.content.cloneNode(!0))}}return i&&r.attachShadow({mode:i.mode}).append(...i.childNodes),r.append(...e.childNodes),e.replaceWith(r),r}constructor(){super(),this._ready=r(),this._fallbackExec={},this._fallbackRestores=[],i._tagNames.add(this.localName)}getParents(e,a=!1){let r=[];for(;(e=e.parentNode)&&e&&e!==t.body;)if(e.matches&&e.matches(this.localName)){if(a&&e===a)break;s.hasConditions(e,i.attributePrefix)&&r.push(e)}return r}replaceTemplates(){let e=this.querySelectorAll(`template[${i.attr.template}]`);for(let t of e){if(this.getParents(t,this).length>0)continue;let e=t.getAttribute(i.attr.template);if("replace"===e){let e=Array.from(this.childNodes);for(let t of e)this.removeChild(t);this.appendChild(t.content);break}{let a=t.innerHTML;if("once"===e&&a){if(i._once.has(a))return void t.remove();i._once.set(a,!0)}t.replaceWith(t.content)}}}async beforeReady(){let e,t=this.getAttribute(i.attr.type);t?e=i._initTypes[t]:this.getAttribute(i.attr.import)&&(e=i._initTypes.default),e&&await e(this)}async ready(e,t){return Array.isArray(t)||(t=this.getParents(e)),Promise.all(t.map(e=>e.wait()))}replaceFallbackContent(){let e=`${this.localName}--`;for(let[t,a]of Object.entries(this.getFallback())){if(this._fallbackExec[t])continue;let r=Array.from(this.querySelectorAll(t)).reverse(),i=[];for(let t of r){if(!t.isConnected)continue;let r=this.getParents(t);if(r[0]===this){let s,o=a(t,e),l=()=>{!s&&o&&(s=!0,o())};this._fallbackRestores.push(l),i.push({node:t,parents:r,returned:l})}}for(let{node:e,parents:t,returned:a}of i.reverse())this.ready(e,t).then(a);this._fallbackExec[t]=!0}}wait(){return this._ready.promise}async connectedCallback(){s.hasConditions(this,i.attributePrefix)&&this.replaceFallbackContent(),await this.hydrate()}swap(){this.replaceTemplates();for(let e of this._fallbackRestores.reverse())e();this._fallbackRestores=[]}async hydrate(){let e=[],t=this.getParents(this);t.length&&e.push(t[0].wait()),e.push(...s.getConditions(this,i.attributePrefix)),await Promise.all(e);let a=i._swapFn;a?await new Promise(e=>a(()=>e(this.swap()),this)):this.swap(),await this.beforeReady(),this._ready.resolve();let{ready:r,defer:o}=i.attr;this.setAttribute(r,""),this.querySelectorAll(`[${o}]`).forEach(e=>e.removeAttribute(o))}}class s{static _cache={};static map={visible:s.visible,idle:s.idle,load:s.pageLoad,interaction:s.interaction,media:s.media,"save-data":s.saveData};static cached(e,t){let a=s._cache;return a[e]||(a[e]=t())}static hasConditions(e,t){return Object.keys(s.map).some(a=>e.hasAttribute(t+a))}static getConditions(e,t){let a=[];for(let[r,i]of Object.entries(s.map)){let s=t+r;e.hasAttribute(s)&&a.push(i(e.getAttribute(s),e))}return a}static visible(t,a){let{promise:i,resolve:s}=r();if("IntersectionObserver"in e){let e=new IntersectionObserver(t=>{let[a]=t;a.isIntersecting&&(e.unobserve(a.target),s())},t?{rootMargin:t}:void 0);e.observe(a)}else s();return i}static pageLoad(){return s.cached("load",()=>{let{promise:a,resolve:i}=r();return"complete"===t.readyState?i():e.addEventListener("load",()=>i(),{once:!0}),a})}static idle(t){let a=Number(t),i=a>0;return s.cached(i?"idle:"+a:"idle",()=>{let{promise:t,resolve:o}=r();return"requestIdleCallback"in e?requestIdleCallback(()=>o(),i?{timeout:a}:void 0):o(),Promise.all([s.pageLoad(),t])})}static interaction(e,t){let a=(e||"click,touchstart").split(",").map(e=>e.trim()),{promise:i,resolve:s}=r();function o(e){s();for(let e of a)t.removeEventListener(e,o)}for(let e of a)t.addEventListener(e,o,{once:!0,passive:!0});return i}static media(t){return s.cached("media:"+t,()=>{let a,{promise:i,resolve:s}=r();return t&&"matchMedia"in e&&!(a=e.matchMedia(t)).matches?a.addListener(e=>{e.matches&&s()}):s(),i})}static saveData(e){let{promise:t,resolve:i}=r();return"connection"in a&&a.connection.saveData!==("false"!==e)||i(),t}}for(let[e,t]of Object.entries(s.map))i["on"+e.replace("-","")]=(e,a)=>e instanceof Node?t(a,e):t(e,a);new URL(import.meta.url).searchParams.has("nodefine")||i.define(),e.Island=i;export{i as Island};