@aceshooting/lyra-ui 29.1.0 → 29.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +3 -2
- package/dist/components/agent-tools/task-list/task-list.class.js +1 -1
- package/dist/components/conversation/code-block/code-block-base.class.js +1 -1
- package/dist/components/media/avatar-group/avatar-group.class.js +1 -1
- package/dist/components/utility/json-viewer/json-viewer.class.js +2 -2
- package/dist/components/viewers/geojson-view/geojson-viewer.class.js +1 -1
- package/dist/internal/anchored-overlay-runtime.js +1 -1
- package/dist/internal/announcer.js +1 -1
- package/dist/internal/aria-controls.js +1 -1
- package/dist/internal/collection-snapshot.js +1 -1
- package/dist/internal/locale-loaders.generated.js +1 -1
- package/dist/internal/overlay-manager.js +1 -1
- package/dist/internal/overlay-stack.js +1 -1
- package/dist/internal/package-metadata.js +1 -1
- package/dist/theme/theme.js +1 -1
- package/llms/components/lr-map.md +9 -0
- package/llms/peers.md +3 -3
- package/llms/shared/imports-and-registration.md +1 -1
- package/llms/shared/localization-and-rtl.md +12 -5
- package/llms/shared/testing-and-utilities.md +5 -0
- package/llms/shared.md +18 -6
- package/llms.txt +2 -1
- package/locales.json +125 -0
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
import{LitElement}from"lit";import{MISSING_OWN_DATA_DESCRIPTOR,UNSAFE_OWN_DATA_DESCRIPTOR,getOwnDataDescriptor,isPlainDataRecord as isRealmNeutralPlainRecord,readOwnArrayLength}from"./data-descriptors.js";import{devWarnOnce}from"./dev-warning.js";const PUBLIC_COLLECTION_ENTRY_LIMIT=1e4,PUBLIC_COLLECTION_NODE_LIMIT=5e4,PUBLIC_COLLECTION_WORK_LIMIT=PUBLIC_COLLECTION_NODE_LIMIT*2,PUBLIC_COLLECTION_DEPTH_LIMIT=256,OMIT_COLLECTION_VALUE=Symbol("omit-public-collection-value"),EXHAUSTED_COLLECTION_VALUE=Symbol("exhausted-public-collection-value"),normalizedCollectionWrites=new WeakMap,readonlySnapshotWrappers=new WeakMap;function writeNormalizedOwnedCollection(host,property,write){let active=normalizedCollectionWrites.get(host);active||normalizedCollectionWrites.set(host,active=new Set);const alreadyActive=active.has(property);active.add(property);try{write()}finally{alreadyActive||active.delete(property),active.size===0&&normalizedCollectionWrites.delete(host)}}function isCollectionSnapshotFailure(value){return value===OMIT_COLLECTION_VALUE||value===EXHAUSTED_COLLECTION_VALUE}function boundedSnapshotLimit(value,maximum){return typeof value=="number"&&Number.isSafeInteger(value)&&value>0?Math.min(value,maximum):maximum}function recordRootLoss(budget,kept,source,retained){retained<source&&(budget.rootLoss=Object.freeze({kept,retained,source}),budget.truncated=!0)}function consumeSnapshotWork(budget){return budget.remainingWork<=0?!1:(budget.remainingWork-=1,!0)}function snapshotRealm(view){const candidate=view;return{Array:candidate?.Array??Array,Date:candidate?.Date??Date,Map:candidate?.Map??Map,Object:candidate?.Object??Object,Set:candidate?.Set??Set}}function isArrayValue(value){try{return Array.isArray(value)}catch{return!1}}function isNativeArrayBufferView(value){try{return ArrayBuffer.isView(value)}catch{return!1}}function isImmutableBlob(value){if(typeof Blob>"u")return!1;const sizeGetter=Object.getOwnPropertyDescriptor(Blob.prototype,"size")?.get;if(!sizeGetter)return!1;try{return sizeGetter.call(value),!0}catch{return!1}}const MUTATING_DATE_METHODS=new Set(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);function nativeDateTime(value){const wrapper=readonlySnapshotWrappers.get(value);if(wrapper?.kind==="date")return wrapper.time;try{return Date.prototype.getTime.call(value)}catch{return OMIT_COLLECTION_VALUE}}function snapshotReadonlyDate(source,time,budget){const target=new budget.realm.Date(time),boundMethods=new Map,rejectMutation=()=>{throw new TypeError("Cannot mutate a readonly Date snapshot")},snapshot=new Proxy(target,{get(date,key){if(MUTATING_DATE_METHODS.has(key))return rejectMutation;if(key==="constructor")return budget.realm.Date;const value=Reflect.get(date,key,date);if(typeof value!="function")return value;const cached=boundMethods.get(key);if(cached)return cached;const bound=value.bind(date);return boundMethods.set(key,bound),bound}});return readonlySnapshotWrappers.set(snapshot,{kind:"date",time}),rememberSnapshot(budget,source,snapshot),Object.freeze(snapshot)}function rememberSnapshot(budget,source,snapshot){budget.seen.set(source,snapshot),budget.additions.push(source)}function snapshotTransaction(budget,create){const remaining=budget.remaining,additions=budget.additions.length,result=create();if(!isCollectionSnapshotFailure(result))return result;budget.remaining=remaining;for(let index=budget.additions.length-1;index>=additions;index-=1)budget.seen.delete(budget.additions[index]);return budget.additions.length=additions,result}function emptyRealmArray(realm){return Object.freeze(new realm.Array)}function*ownEnumerableStringKeys(value){for(const key in value)yield key}function snapshotDataRecord(value,keys,prototype,budget,depth,preserveRecordKeys,preserveCollectionItemKeys){const output=budget.realm.Object.create(null);rememberSnapshot(budget,value,output);try{for(const key of keys){if(!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;const descriptor=getOwnDataDescriptor(value,key);if(descriptor===MISSING_OWN_DATA_DESCRIPTOR||descriptor===UNSAFE_OWN_DATA_DESCRIPTOR||!descriptor.enumerable){descriptor===UNSAFE_OWN_DATA_DESCRIPTOR&&(budget.invalid=!0);continue}if(budget.remaining<=0)return EXHAUSTED_COLLECTION_VALUE;budget.remaining-=1;const disposition=budget.recordKey?.(key,descriptor.value,depth)??"copy";if(disposition==="omit"){budget.invalid=!0;continue}const entry=disposition==="preserve"||preserveRecordKeys?.has(key)?descriptor.value:preserveCollectionItemKeys?.has(key)?snapshotIdentityCollection(descriptor.value,budget.realm,budget):snapshotCollectionValue(descriptor.value,budget,depth+1,void 0,void 0,budget.nestedArrayPrefix&&isArrayValue(descriptor.value));if(isCollectionSnapshotFailure(entry))return entry===OMIT_COLLECTION_VALUE?budget.invalid=!0:budget.truncated=!0,entry;output[key]=entry}}catch{return OMIT_COLLECTION_VALUE}return Object.setPrototypeOf(output,prototype),Object.freeze(output)}function snapshotCollectionValue(value,budget,depth,preserveRecordKeys,preserveCollectionItemKeys,allowPrefixTruncation=!1){if(value===null||typeof value!="object"&&typeof value!="function"||typeof value=="function")return value;if(budget.seen.has(value))return budget.seen.get(value);if(depth>budget.depthLimit||budget.remaining<=0)return EXHAUSTED_COLLECTION_VALUE;if(isArrayValue(value)){if(!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;const sourceLength=readOwnArrayLength(value);if(sourceLength===void 0)return budget.invalid=!0,allowPrefixTruncation?emptyRealmArray(budget.realm):OMIT_COLLECTION_VALUE;if(!allowPrefixTruncation&&sourceLength>budget.entryLimit)return EXHAUSTED_COLLECTION_VALUE;const length=Math.min(sourceLength,budget.entryLimit),newest=depth===0&&allowPrefixTruncation&&budget.retention==="newest",output=new budget.realm.Array;Object.setPrototypeOf(output,null),rememberSnapshot(budget,value,output);const kept=[];let walked=0,dropped=0;for(;walked<length;walked+=1){if(budget.remaining<=0||!consumeSnapshotWork(budget)){if(!allowPrefixTruncation)return EXHAUSTED_COLLECTION_VALUE;break}const index=newest?sourceLength-1-walked:walked,descriptor=getOwnDataDescriptor(value,String(index));if(descriptor===MISSING_OWN_DATA_DESCRIPTOR)continue;if(descriptor===UNSAFE_OWN_DATA_DESCRIPTOR){if(budget.invalid=!0,!allowPrefixTruncation)return OMIT_COLLECTION_VALUE;dropped+=1;continue}const entry=snapshotTransaction(budget,()=>(budget.remaining-=1,snapshotCollectionValue(descriptor.value,budget,depth+1,void 0,void 0,budget.nestedArrayPrefix&&isArrayValue(descriptor.value))));if(entry===OMIT_COLLECTION_VALUE){if(budget.invalid=!0,!allowPrefixTruncation)return OMIT_COLLECTION_VALUE;dropped+=1;continue}if(entry===EXHAUSTED_COLLECTION_VALUE){if(budget.truncated=!0,!allowPrefixTruncation)return EXHAUSTED_COLLECTION_VALUE;break}kept.push(index,entry)}output.length=walked;const offset=newest?sourceLength-walked:0;for(let index=0;index<kept.length;index+=2)output[kept[index]-offset]=kept[index+1];return Object.setPrototypeOf(output,budget.realm.Array.prototype),walked-dropped<sourceLength&&(budget.truncated=!0),allowPrefixTruncation&&depth===0&&recordRootLoss(budget,newest?"newest":"oldest",sourceLength,walked-dropped),Object.freeze(output)}if(!readonlySnapshotWrappers.has(value)&&isRealmNeutralPlainRecord(value)){let prototype;try{prototype=Object.getPrototypeOf(value)}catch{return OMIT_COLLECTION_VALUE}return snapshotDataRecord(value,ownEnumerableStringKeys(value),prototype===null?null:budget.realm.Object.prototype,budget,depth,preserveRecordKeys,preserveCollectionItemKeys)}const dateTime=nativeDateTime(value);if(dateTime!==OMIT_COLLECTION_VALUE)return snapshotReadonlyDate(value,dateTime,budget);const entries=nativeMapEntries(value);if(entries)return snapshotDetachedMap(value,entries,budget,depth,allowPrefixTruncation);const values=nativeSetValues(value);if(values)return snapshotDetachedSet(value,values,budget,depth,allowPrefixTruncation);if(isNativeArrayBufferView(value))return budget.invalid=!0,OMIT_COLLECTION_VALUE;const rect=snapshotDOMRect(value,budget);return rect!==OMIT_COLLECTION_VALUE?rect:isImmutableBlob(value)?value:(budget.invalid=!0,OMIT_COLLECTION_VALUE)}function boundedRecordSize(value,limit=PUBLIC_COLLECTION_WORK_LIMIT){let size=0;try{for(const key in value)if(typeof key=="string"&&(size+=1),size>=limit)break}catch{return}return size}function snapshotPublicCollection(value,view,options={}){if(value===null||typeof value!="object"&&typeof value!="function")return options.onResult?.(Object.freeze({invalid:!1,truncated:!1})),value;const realm=snapshotRealm(view),nodeLimit=boundedSnapshotLimit(options.limits?.nodes,PUBLIC_COLLECTION_NODE_LIMIT),budget={remaining:nodeLimit,remainingWork:nodeLimit*2,seen:new WeakMap,additions:[],realm,entryLimit:boundedSnapshotLimit(options.limits?.entries,PUBLIC_COLLECTION_ENTRY_LIMIT),depthLimit:boundedSnapshotLimit(options.limits?.depth,PUBLIC_COLLECTION_DEPTH_LIMIT),nestedArrayPrefix:options.nestedArrayPrefix??!1,recordKey:options.recordKey,invalid:!1,truncated:!1,retention:options.retain??"oldest"},snapshot=snapshotTransaction(budget,()=>snapshotCollectionValue(value,budget,0,void 0,void 0,!0));if(!isCollectionSnapshotFailure(snapshot))return budget.rootLoss&&options.onTruncate?.(budget.rootLoss),options.onResult?.(Object.freeze({invalid:budget.invalid,truncated:budget.truncated})),snapshot;if(options.onResult?.(Object.freeze({invalid:budget.invalid||snapshot===OMIT_COLLECTION_VALUE,truncated:budget.truncated||snapshot===EXHAUSTED_COLLECTION_VALUE})),isArrayValue(value)||isNativeArrayBufferView(value))return emptyRealmArray(realm);if(typeof value=="object"){if(nativeMapEntries(value))return readonlyMapFacade(new realm.Map,realm);if(nativeSetValues(value))return readonlySetFacade(new realm.Set,realm);if(isRealmNeutralPlainRecord(value)){const size=boundedRecordSize(value,nodeLimit*2);size&&options.onTruncate?.(Object.freeze({kept:"oldest",retained:0,source:size}));const prototype=Object.getPrototypeOf(value);return Object.freeze(realm.Object.create(prototype===null?null:realm.Object.prototype))}}return emptyRealmArray(realm)}function nativeMapEntries(value){const wrapper=readonlySnapshotWrappers.get(value);try{return Map.prototype.entries.call(wrapper?.kind==="map"?wrapper.backing:value)}catch{return}}function nativeSetValues(value){const wrapper=readonlySnapshotWrappers.get(value);try{return Set.prototype.values.call(wrapper?.kind==="set"?wrapper.backing:value)}catch{return}}function snapshotDOMRect(value,budget){if(typeof DOMRectReadOnly>"u")return OMIT_COLLECTION_VALUE;const nativePrototype=DOMRectReadOnly.prototype,output=budget.realm.Object.create(budget.realm.Object.prototype);for(const key of["x","y","width","height","top","right","bottom","left"]){let coordinate;try{const getter=Object.getOwnPropertyDescriptor(nativePrototype,key)?.get;if(!getter)return OMIT_COLLECTION_VALUE;coordinate=getter.call(value)}catch{return OMIT_COLLECTION_VALUE}if(typeof coordinate!="number"||!Number.isFinite(coordinate))return OMIT_COLLECTION_VALUE;Object.defineProperty(output,key,{value:coordinate,enumerable:!0,configurable:!1,writable:!1})}return Object.freeze(output)}function readonlyMapFacade(backing,realm=snapshotRealm()){let facade;return facade=realm.Object.create(realm.Object.prototype),Object.defineProperties(facade,{size:{enumerable:!0,get:()=>backing.size},entries:{value:()=>backing.entries()},get:{value:key=>backing.get(key)},has:{value:key=>backing.has(key)},keys:{value:()=>backing.keys()},values:{value:()=>backing.values()},forEach:{value:(callback,thisArg)=>backing.forEach((entry,key)=>callback.call(thisArg,entry,key,facade))},[Symbol.iterator]:{value:()=>backing[Symbol.iterator]()}}),readonlySnapshotWrappers.set(facade,{kind:"map",backing}),Object.freeze(facade)}function readonlySetFacade(backing,realm=snapshotRealm()){let facade;return facade=realm.Object.create(realm.Object.prototype),Object.defineProperties(facade,{size:{enumerable:!0,get:()=>backing.size},entries:{value:()=>backing.entries()},has:{value:entry=>backing.has(entry)},keys:{value:()=>backing.keys()},values:{value:()=>backing.values()},forEach:{value:(callback,thisArg)=>backing.forEach(entry=>callback.call(thisArg,entry,entry,facade))},[Symbol.iterator]:{value:()=>backing[Symbol.iterator]()}}),readonlySnapshotWrappers.set(facade,{kind:"set",backing}),Object.freeze(facade)}function snapshotIdentityMap(entries,realm=snapshotRealm(),budget,entryLimit=budget?.entryLimit??PUBLIC_COLLECTION_ENTRY_LIMIT){const backing=new realm.Map;for(let count=0;count<entryLimit;count+=1){const next=entries.next();if(next.done)break;if(budget&&!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;backing.set(next.value[0],next.value[1])}return readonlyMapFacade(backing,realm)}function snapshotIdentitySet(values,realm=snapshotRealm(),budget,entryLimit=budget?.entryLimit??PUBLIC_COLLECTION_ENTRY_LIMIT){const backing=new realm.Set;for(let count=0;count<entryLimit;count+=1){const next=values.next();if(next.done)break;if(budget&&!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;backing.add(next.value)}return readonlySetFacade(backing,realm)}function nativeCollectionSize(source,kind){const wrapper=readonlySnapshotWrappers.get(source);try{const size=Object.getOwnPropertyDescriptor(kind==="map"?Map.prototype:Set.prototype,"size")?.get?.call(wrapper?.kind===kind?wrapper.backing:source);return typeof size=="number"?size:void 0}catch{return}}function recordNativeCollectionLoss(budget,source,kind,retained){const size=nativeCollectionSize(source,kind);size!==void 0&&recordRootLoss(budget,"oldest",size,retained)}function snapshotDetachedMap(source,entries,budget,depth,allowPrefixTruncation){const backing=new budget.realm.Map,facade=readonlyMapFacade(backing,budget.realm);rememberSnapshot(budget,source,facade);const settle=()=>(allowPrefixTruncation?recordNativeCollectionLoss(budget,source,"map",backing.size):(nativeCollectionSize(source,"map")??0)>budget.entryLimit&&(budget.truncated=!0),facade);for(let count=0;count<budget.entryLimit;count+=1){let next;try{next=entries.next()}catch{break}if(next.done)break;if(budget.remaining<=0||!consumeSnapshotWork(budget))return allowPrefixTruncation?settle():EXHAUSTED_COLLECTION_VALUE;const pair=snapshotTransaction(budget,()=>{budget.remaining-=1;const key=snapshotCollectionValue(next.value[0],budget,depth+1);if(isCollectionSnapshotFailure(key))return key;const entry=snapshotCollectionValue(next.value[1],budget,depth+1);return isCollectionSnapshotFailure(entry)?entry:[key,entry]});if(pair===EXHAUSTED_COLLECTION_VALUE)return budget.truncated=!0,allowPrefixTruncation?settle():EXHAUSTED_COLLECTION_VALUE;pair===OMIT_COLLECTION_VALUE?budget.invalid=!0:backing.set(pair[0],pair[1])}return settle()}function snapshotDetachedSet(source,values,budget,depth,allowPrefixTruncation){const backing=new budget.realm.Set,facade=readonlySetFacade(backing,budget.realm);rememberSnapshot(budget,source,facade);const settle=()=>(allowPrefixTruncation?recordNativeCollectionLoss(budget,source,"set",backing.size):(nativeCollectionSize(source,"set")??0)>budget.entryLimit&&(budget.truncated=!0),facade);for(let count=0;count<budget.entryLimit;count+=1){let next;try{next=values.next()}catch{break}if(next.done)break;if(budget.remaining<=0||!consumeSnapshotWork(budget))return allowPrefixTruncation?settle():EXHAUSTED_COLLECTION_VALUE;const entry=snapshotTransaction(budget,()=>(budget.remaining-=1,snapshotCollectionValue(next.value,budget,depth+1)));if(entry===EXHAUSTED_COLLECTION_VALUE)return budget.truncated=!0,allowPrefixTruncation?settle():EXHAUSTED_COLLECTION_VALUE;entry===OMIT_COLLECTION_VALUE?budget.invalid=!0:backing.add(entry)}return settle()}function snapshotIdentityCollection(value,view,budget,root){const realm=snapshotRealm(view);if(budget&&value!==null&&(typeof value=="object"||typeof value=="function")&&budget.seen.has(value))return budget.seen.get(value);if(isArrayValue(value)){if(budget&&!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;const sourceLength=readOwnArrayLength(value)??0,length=Math.min(sourceLength,boundedSnapshotLimit(root?.limits?.entries,PUBLIC_COLLECTION_ENTRY_LIMIT)),kept=root?.retain??"oldest",offset=kept==="newest"?sourceLength-length:0,output=new realm.Array(length);Object.setPrototypeOf(output,null),budget&&rememberSnapshot(budget,value,output);for(let index=0;index<length;index+=1){if(budget&&!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;const descriptor=getOwnDataDescriptor(value,String(offset+index));descriptor===MISSING_OWN_DATA_DESCRIPTOR||descriptor===UNSAFE_OWN_DATA_DESCRIPTOR||(output[index]=descriptor.value)}return Object.setPrototypeOf(output,realm.Array.prototype),length<sourceLength&&root?.onTruncate?.(Object.freeze({kept,retained:length,source:sourceLength})),Object.freeze(output)}if(value===null||typeof value!="object")return value;const mapEntries=nativeMapEntries(value);if(mapEntries){const output=snapshotIdentityMap(mapEntries,realm,budget,boundedSnapshotLimit(root?.limits?.entries,budget?.entryLimit??PUBLIC_COLLECTION_ENTRY_LIMIT));return output===EXHAUSTED_COLLECTION_VALUE||(budget&&rememberSnapshot(budget,value,output),reportIdentityCollectionLoss(root,value,"map",output.size)),output}const setValues=nativeSetValues(value);if(setValues){const output=snapshotIdentitySet(setValues,realm,budget,boundedSnapshotLimit(root?.limits?.entries,budget?.entryLimit??PUBLIC_COLLECTION_ENTRY_LIMIT));return output===EXHAUSTED_COLLECTION_VALUE||(budget&&rememberSnapshot(budget,value,output),reportIdentityCollectionLoss(root,value,"set",output.size)),output}return emptyRealmArray(realm)}function reportIdentityCollectionLoss(root,source,kind,retained){if(!root?.onTruncate)return;const size=nativeCollectionSize(source,kind);size!==void 0&&retained<size&&root.onTruncate(Object.freeze({kept:"oldest",retained,source:size}))}function snapshotEventDetail(value,view,preserveRootKeys=new Set,preserveCollectionItemKeys=new Set){if(value==null)return value;const budget={remaining:PUBLIC_COLLECTION_NODE_LIMIT,remainingWork:PUBLIC_COLLECTION_WORK_LIMIT,seen:new WeakMap,additions:[],realm:snapshotRealm(view),entryLimit:PUBLIC_COLLECTION_ENTRY_LIMIT,depthLimit:PUBLIC_COLLECTION_DEPTH_LIMIT,nestedArrayPrefix:!1,invalid:!1,truncated:!1},snapshot=snapshotTransaction(budget,()=>snapshotCollectionValue(value,budget,0,preserveRootKeys,preserveCollectionItemKeys));return isCollectionSnapshotFailure(snapshot)?null:snapshot}function trustedLyraConstructorChain(instance){const constructors=[];let prototype=Object.getPrototypeOf(instance);for(;prototype&&prototype!==LitElement.prototype;){const descriptor=Object.getOwnPropertyDescriptor(prototype,"constructor");typeof descriptor?.value=="function"&&constructors.push(descriptor.value),prototype=Object.getPrototypeOf(prototype)}return constructors}function lyraClassChain(ctor){const constructors=[];let current=ctor;for(;typeof current=="function"&¤t!==LitElement;)constructors.push(current),current=Object.getPrototypeOf(current);return constructors}const collectionPolicyByConstructor=new WeakMap;function collectionPropertyPolicy(ctor,name){let policies=collectionPolicyByConstructor.get(ctor);policies||(policies=new Map,collectionPolicyByConstructor.set(ctor,policies));const cached=policies.get(name);if(cached)return cached;let limits,owns=!1,preservesItemIdentity=!1,preservesObjectIdentity=!1,retainsNewest=!1,immutableSource=!1;for(const constructor of lyraClassChain(ctor)){const declared=constructor;!limits&&Object.hasOwn(constructor,"ownedCollectionLimits")&&declared.ownedCollectionLimits&&Object.hasOwn(declared.ownedCollectionLimits,name)&&(limits=declared.ownedCollectionLimits[name]),Object.prototype.hasOwnProperty.call(constructor,"ownedCollectionProperties")&&declared.ownedCollectionProperties.includes(name)&&(owns=!0),Object.prototype.hasOwnProperty.call(constructor,"identityCollectionProperties")&&declared.identityCollectionProperties.includes(name)&&(preservesItemIdentity=!0),Object.prototype.hasOwnProperty.call(constructor,"identityCollectionObjectProperties")&&declared.identityCollectionObjectProperties.includes(name)&&(preservesObjectIdentity=!0),Object.prototype.hasOwnProperty.call(constructor,"immutableSourceCollectionProperties")&&declared.immutableSourceCollectionProperties.includes(name)&&(immutableSource=!0),Object.prototype.hasOwnProperty.call(constructor,"appendOrderedCollectionProperties")&&declared.appendOrderedCollectionProperties.includes(name)&&(retainsNewest=!0)}const policy=Object.freeze({limits,owns,preservesItemIdentity,preservesObjectIdentity,retainsNewest,immutableSource});return policies.set(name,policy),policy}const COLLECTION_ENROLLMENT_FIELDS=["ownedCollectionProperties","identityCollectionProperties","identityCollectionObjectProperties","appendOrderedCollectionProperties","immutableSourceCollectionProperties"];function enrolledCollectionPropertyNames(ctor){const names=new Set;for(const constructor of lyraClassChain(ctor))for(const field of COLLECTION_ENROLLMENT_FIELDS){if(!Object.prototype.hasOwnProperty.call(constructor,field))continue;const declared=constructor;for(const name of declared[field])names.add(name)}return names}function inheritedPropertyDescriptor(prototype,name){let current=prototype;for(;current;){const descriptor=Object.getOwnPropertyDescriptor(current,name);if(descriptor)return descriptor;current=Object.getPrototypeOf(current)}}const installedOwnershipBoundaries=new WeakSet,ownershipBoundarySetters=new WeakMap;function samePolicy(a,b){return a.limits===b.limits&&a.owns===b.owns&&a.preservesItemIdentity===b.preservesItemIdentity&&a.preservesObjectIdentity===b.preservesObjectIdentity&&a.retainsNewest===b.retainsNewest&&a.immutableSource===b.immutableSource}function installOwnedCollectionAccessors(ctor){if(installedOwnershipBoundaries.has(ctor))return;installedOwnershipBoundaries.add(ctor);const prototype=ctor.prototype;for(const name of enrolledCollectionPropertyNames(ctor)){const policy=collectionPropertyPolicy(ctor,name);if(!policy.owns)continue;const declaration=ctor.elementProperties.get(name);if(!declaration||declaration.noAccessor)continue;const descriptor=inheritedPropertyDescriptor(prototype,name),inheritedSet=descriptor?.set;if(!inheritedSet)continue;const installed=ownershipBoundarySetters.get(inheritedSet);if(installed&&samePolicy(installed.policy,policy))continue;const originalSet=installed?.originalSet??inheritedSet,lastAssignments=new WeakMap,set=function(value){const previous=lastAssignments.get(this);if(previous&&declaration.hasChanged===void 0&&(!policy.preservesItemIdentity||policy.immutableSource)&&!policy.preservesObjectIdentity&&(("primitive"in previous.source?Object.is(value,previous.source.primitive):value!==void 0&&Object.is(value,previous.source.deref()))||Object.is(value,previous.retained)))return;const retainedLoss=previous&&!policy.preservesObjectIdentity&&Object.is(value,previous.retained)?publicCollectionTruncation(this,name):void 0,ownerView=this.ownerDocument?.defaultView;let truncation;const options={limits:policy.limits,retain:policy.retainsNewest?"newest":"oldest",onTruncate:report=>{truncation=report}},snapshot=policy.preservesObjectIdentity&&value!==null&&typeof value=="object"&&!isArrayValue(value)?value:policy.preservesItemIdentity?snapshotIdentityCollection(value,ownerView,void 0,options):snapshotPublicCollection(value,ownerView,options);if(retainedLoss){const retained=truncation?.retained??(policy.preservesItemIdentity?isArrayValue(snapshot)?readOwnArrayLength(snapshot):snapshot!==null&&typeof snapshot=="object"?nativeCollectionSize(snapshot,"map")??nativeCollectionSize(snapshot,"set"):void 0:void 0)??retainedLoss.retained;truncation=Object.freeze({kept:truncation?.kept??retainedLoss.kept,retained,source:retainedLoss.source})}recordCollectionTruncation(this,name,truncation),originalSet.call(this,snapshot);const source=normalizedCollectionWrites.get(this)?.has(name)&&previous?previous.source:typeof value=="object"&&value!==null||typeof value=="function"?new WeakRef(value):{primitive:value};lastAssignments.set(this,{source,retained:descriptor.get?.call(this)??snapshot})};ownershipBoundarySetters.set(set,{policy,originalSet}),Object.defineProperty(prototype,name,{...descriptor,set})}}const collectionTruncations=new WeakMap;function collectionTruncationWarningKey(tagName,property){return`lyra-collection-truncated:${tagName}:${String(property)}`}function recordCollectionTruncation(host,name,truncation){let byName=collectionTruncations.get(host);if(!truncation){byName?.delete(name);return}byName||(byName=new Map,collectionTruncations.set(host,byName)),byName.set(name,truncation);const tagName=host.localName,property=String(name);devWarnOnce(collectionTruncationWarningKey(tagName,property),`<${tagName}>: '${property}' kept ${truncation.retained} of ${truncation.source} entries, the ${truncation.kept}; an assignment keeps at most ${PUBLIC_COLLECTION_ENTRY_LIMIT} per array and ${PUBLIC_COLLECTION_NODE_LIMIT} values, and drops values it cannot copy.`)}function publicCollectionTruncation(host,property){return collectionTruncations.get(host)?.get(property)}function snapshotEnrolledEventDetail(host,name,detail){let snapshotsDetail=!1;const identityDetailKeys=new Set,identityCollectionItemKeys=new Set;for(const candidate of trustedLyraConstructorChain(host)){const constructor=candidate;if(Object.prototype.hasOwnProperty.call(constructor,"immutableEventDetails")&&constructor.immutableEventDetails.includes(name)&&(snapshotsDetail=!0),Object.prototype.hasOwnProperty.call(constructor,"identityEventDetailProperties"))for(const key of constructor.identityEventDetailProperties[name]??[])identityDetailKeys.add(key);if(Object.prototype.hasOwnProperty.call(constructor,"identityEventDetailCollectionItems"))for(const key of constructor.identityEventDetailCollectionItems[name]??[])identityCollectionItemKeys.add(key)}return snapshotsDetail?snapshotEventDetail(detail,host.ownerDocument?.defaultView,identityDetailKeys,identityCollectionItemKeys):detail}function declaresOwnedCollections(ctor){for(const constructor of lyraClassChain(ctor)){if(!Object.prototype.hasOwnProperty.call(constructor,"ownedCollectionProperties"))continue;if(constructor.ownedCollectionProperties.length>0)return!0}return!1}const collectionSupport=/* @__PURE__ */Object.freeze({installProperties:installOwnedCollectionAccessors,snapshotEvent:snapshotEnrolledEventDetail}),eventCollectionSupport=/* @__PURE__ */Object.freeze({installProperties(ctor){declaresOwnedCollections(ctor)&&devWarnOnce(`lyra-event-collection-support:${ctor.name}`,`${ctor.name} enrolls ownedCollectionProperties but declares eventCollectionSupport; declare collectionSupport so those properties cross the immutable collection boundary.`)},snapshotEvent:snapshotEnrolledEventDetail});export{collectionSupport,collectionTruncationWarningKey,eventCollectionSupport,publicCollectionTruncation,snapshotEventDetail,snapshotPublicCollection,writeNormalizedOwnedCollection};
|
|
1
|
+
import{LitElement}from"lit";import{MISSING_OWN_DATA_DESCRIPTOR,UNSAFE_OWN_DATA_DESCRIPTOR,getOwnDataDescriptor,isPlainDataRecord as isRealmNeutralPlainRecord,readOwnArrayLength}from"./data-descriptors.js";import{devWarnOnce}from"./dev-warning.js";const PUBLIC_COLLECTION_ENTRY_LIMIT=1e4,PUBLIC_COLLECTION_NODE_LIMIT=5e4,PUBLIC_COLLECTION_WORK_LIMIT=PUBLIC_COLLECTION_NODE_LIMIT*2,PUBLIC_COLLECTION_DEPTH_LIMIT=256,OMIT_COLLECTION_VALUE=Symbol("omit-public-collection-value"),EXHAUSTED_COLLECTION_VALUE=Symbol("exhausted-public-collection-value"),normalizedCollectionWrites=new WeakMap,readonlySnapshotWrappers=new WeakMap;function writeNormalizedOwnedCollection(host,property,write){let active=normalizedCollectionWrites.get(host);active||normalizedCollectionWrites.set(host,active=new Set);const alreadyActive=active.has(property);active.add(property);try{write()}finally{alreadyActive||active.delete(property),active.size===0&&normalizedCollectionWrites.delete(host)}}function isCollectionSnapshotFailure(value){return value===OMIT_COLLECTION_VALUE||value===EXHAUSTED_COLLECTION_VALUE}function boundedSnapshotLimit(value,maximum){return typeof value=="number"&&Number.isSafeInteger(value)&&value>0?Math.min(value,maximum):maximum}function recordRootLoss(budget,kept,source,retained){retained<source&&(budget.rootLoss=Object.freeze({kept,retained,source}),budget.truncated=!0)}function consumeSnapshotWork(budget){return budget.remainingWork<=0?!1:(budget.remainingWork-=1,!0)}function snapshotRealm(view){const candidate=view;return{Array:candidate?.Array??Array,Date:candidate?.Date??Date,Map:candidate?.Map??Map,Object:candidate?.Object??Object,Set:candidate?.Set??Set}}function isArrayValue(value){try{return Array.isArray(value)}catch{return!1}}function isNativeArrayBufferView(value){return ArrayBuffer.isView(value)}function isImmutableBlob(value){if(typeof Blob>"u")return!1;const sizeGetter=Object.getOwnPropertyDescriptor(Blob.prototype,"size")?.get;if(!sizeGetter)return!1;try{return sizeGetter.call(value),!0}catch{return!1}}const MUTATING_DATE_METHODS=new Set(["setDate","setFullYear","setHours","setMilliseconds","setMinutes","setMonth","setSeconds","setTime","setUTCDate","setUTCFullYear","setUTCHours","setUTCMilliseconds","setUTCMinutes","setUTCMonth","setUTCSeconds","setYear"]);function nativeDateTime(value){const wrapper=readonlySnapshotWrappers.get(value);if(wrapper?.kind==="date")return wrapper.time;try{return Date.prototype.getTime.call(value)}catch{return OMIT_COLLECTION_VALUE}}function snapshotReadonlyDate(source,time,budget){const target=new budget.realm.Date(time),boundMethods=new Map,rejectMutation=()=>{throw new TypeError("Cannot mutate a readonly Date snapshot")},snapshot=new Proxy(target,{get(date,key){if(MUTATING_DATE_METHODS.has(key))return rejectMutation;if(key==="constructor")return budget.realm.Date;const value=Reflect.get(date,key,date);if(typeof value!="function")return value;const cached=boundMethods.get(key);if(cached)return cached;const bound=value.bind(date);return boundMethods.set(key,bound),bound}});return readonlySnapshotWrappers.set(snapshot,{kind:"date",time}),rememberSnapshot(budget,source,snapshot),Object.freeze(snapshot)}function rememberSnapshot(budget,source,snapshot){budget.seen.set(source,snapshot),budget.additions.push(source)}function snapshotTransaction(budget,create){const remaining=budget.remaining,additions=budget.additions.length,result=create();if(!isCollectionSnapshotFailure(result))return result;budget.remaining=remaining;for(let index=budget.additions.length-1;index>=additions;index-=1)budget.seen.delete(budget.additions[index]);return budget.additions.length=additions,result}function emptyRealmArray(realm){return Object.freeze(new realm.Array)}function*ownEnumerableStringKeys(value){for(const key in value)yield key}function snapshotDataRecord(value,keys,prototype,budget,depth,preserveRecordKeys,preserveCollectionItemKeys){const output=budget.realm.Object.create(null);rememberSnapshot(budget,value,output);try{for(const key of keys){if(!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;const descriptor=getOwnDataDescriptor(value,key);if(descriptor===MISSING_OWN_DATA_DESCRIPTOR||descriptor===UNSAFE_OWN_DATA_DESCRIPTOR||!descriptor.enumerable){descriptor===UNSAFE_OWN_DATA_DESCRIPTOR&&(budget.invalid=!0);continue}if(budget.remaining<=0)return EXHAUSTED_COLLECTION_VALUE;budget.remaining-=1;const disposition=budget.recordKey?.(key,descriptor.value,depth)??"copy";if(disposition==="omit"){budget.invalid=!0;continue}const entry=disposition==="preserve"||preserveRecordKeys?.has(key)?descriptor.value:preserveCollectionItemKeys?.has(key)?snapshotIdentityCollection(descriptor.value,budget.realm,budget):snapshotCollectionValue(descriptor.value,budget,depth+1,void 0,void 0,budget.nestedArrayPrefix&&isArrayValue(descriptor.value));if(isCollectionSnapshotFailure(entry))return entry===OMIT_COLLECTION_VALUE?budget.invalid=!0:budget.truncated=!0,entry;output[key]=entry}}catch{return OMIT_COLLECTION_VALUE}return Object.setPrototypeOf(output,prototype),Object.freeze(output)}function snapshotCollectionValue(value,budget,depth,preserveRecordKeys,preserveCollectionItemKeys,allowPrefixTruncation=!1){if(value===null||typeof value!="object"&&typeof value!="function"||typeof value=="function")return value;if(budget.seen.has(value))return budget.seen.get(value);if(depth>budget.depthLimit||budget.remaining<=0)return EXHAUSTED_COLLECTION_VALUE;if(isArrayValue(value)){if(!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;const sourceLength=readOwnArrayLength(value);if(sourceLength===void 0)return budget.invalid=!0,allowPrefixTruncation?emptyRealmArray(budget.realm):OMIT_COLLECTION_VALUE;if(!allowPrefixTruncation&&sourceLength>budget.entryLimit)return EXHAUSTED_COLLECTION_VALUE;const length=Math.min(sourceLength,budget.entryLimit),newest=depth===0&&allowPrefixTruncation&&budget.retention==="newest",output=new budget.realm.Array;Object.setPrototypeOf(output,null),rememberSnapshot(budget,value,output);const kept=[];let walked=0,dropped=0;for(;walked<length;walked+=1){if(budget.remaining<=0||!consumeSnapshotWork(budget)){if(!allowPrefixTruncation)return EXHAUSTED_COLLECTION_VALUE;break}const index=newest?sourceLength-1-walked:walked,descriptor=getOwnDataDescriptor(value,String(index));if(descriptor===MISSING_OWN_DATA_DESCRIPTOR)continue;if(descriptor===UNSAFE_OWN_DATA_DESCRIPTOR){if(budget.invalid=!0,!allowPrefixTruncation)return OMIT_COLLECTION_VALUE;dropped+=1;continue}const entry=snapshotTransaction(budget,()=>(budget.remaining-=1,snapshotCollectionValue(descriptor.value,budget,depth+1,void 0,void 0,budget.nestedArrayPrefix&&isArrayValue(descriptor.value))));if(entry===OMIT_COLLECTION_VALUE){if(budget.invalid=!0,!allowPrefixTruncation)return OMIT_COLLECTION_VALUE;dropped+=1;continue}if(entry===EXHAUSTED_COLLECTION_VALUE){if(budget.truncated=!0,!allowPrefixTruncation)return EXHAUSTED_COLLECTION_VALUE;break}kept.push(index,entry)}output.length=walked;const offset=newest?sourceLength-walked:0;for(let index=0;index<kept.length;index+=2)output[kept[index]-offset]=kept[index+1];return Object.setPrototypeOf(output,budget.realm.Array.prototype),walked-dropped<sourceLength&&(budget.truncated=!0),allowPrefixTruncation&&depth===0&&recordRootLoss(budget,newest?"newest":"oldest",sourceLength,walked-dropped),Object.freeze(output)}if(!readonlySnapshotWrappers.has(value)&&isRealmNeutralPlainRecord(value)){let prototype;try{prototype=Object.getPrototypeOf(value)}catch{return OMIT_COLLECTION_VALUE}return snapshotDataRecord(value,ownEnumerableStringKeys(value),prototype===null?null:budget.realm.Object.prototype,budget,depth,preserveRecordKeys,preserveCollectionItemKeys)}const dateTime=nativeDateTime(value);if(dateTime!==OMIT_COLLECTION_VALUE)return snapshotReadonlyDate(value,dateTime,budget);const entries=nativeMapEntries(value);if(entries)return snapshotDetachedMap(value,entries,budget,depth,allowPrefixTruncation);const values=nativeSetValues(value);if(values)return snapshotDetachedSet(value,values,budget,depth,allowPrefixTruncation);if(isNativeArrayBufferView(value))return budget.invalid=!0,OMIT_COLLECTION_VALUE;const rect=snapshotDOMRect(value,budget);return rect!==OMIT_COLLECTION_VALUE?rect:isImmutableBlob(value)?value:(budget.invalid=!0,OMIT_COLLECTION_VALUE)}function boundedRecordSize(value,limit=PUBLIC_COLLECTION_WORK_LIMIT){let size=0;try{for(const key in value)if(typeof key=="string"&&(size+=1),size>=limit)break}catch{return}return size}function snapshotPublicCollection(value,view,options={}){if(value===null||typeof value!="object"&&typeof value!="function")return options.onResult?.(Object.freeze({invalid:!1,truncated:!1})),value;const realm=snapshotRealm(view),nodeLimit=boundedSnapshotLimit(options.limits?.nodes,PUBLIC_COLLECTION_NODE_LIMIT),budget={remaining:nodeLimit,remainingWork:nodeLimit*2,seen:new WeakMap,additions:[],realm,entryLimit:boundedSnapshotLimit(options.limits?.entries,PUBLIC_COLLECTION_ENTRY_LIMIT),depthLimit:boundedSnapshotLimit(options.limits?.depth,PUBLIC_COLLECTION_DEPTH_LIMIT),nestedArrayPrefix:options.nestedArrayPrefix??!1,recordKey:options.recordKey,invalid:!1,truncated:!1,retention:options.retain??"oldest"},snapshot=snapshotTransaction(budget,()=>snapshotCollectionValue(value,budget,0,void 0,void 0,!0));if(!isCollectionSnapshotFailure(snapshot))return budget.rootLoss&&options.onTruncate?.(budget.rootLoss),options.onResult?.(Object.freeze({invalid:budget.invalid,truncated:budget.truncated})),snapshot;if(options.onResult?.(Object.freeze({invalid:budget.invalid||snapshot===OMIT_COLLECTION_VALUE,truncated:budget.truncated||snapshot===EXHAUSTED_COLLECTION_VALUE})),isArrayValue(value)||isNativeArrayBufferView(value))return emptyRealmArray(realm);if(typeof value=="object"){if(nativeMapEntries(value))return readonlyMapFacade(new realm.Map,realm);if(nativeSetValues(value))return readonlySetFacade(new realm.Set,realm);if(isRealmNeutralPlainRecord(value)){const size=boundedRecordSize(value,nodeLimit*2);size&&options.onTruncate?.(Object.freeze({kept:"oldest",retained:0,source:size}));const prototype=Object.getPrototypeOf(value);return Object.freeze(realm.Object.create(prototype===null?null:realm.Object.prototype))}}return emptyRealmArray(realm)}function nativeMapEntries(value){const wrapper=readonlySnapshotWrappers.get(value);try{return Map.prototype.entries.call(wrapper?.kind==="map"?wrapper.backing:value)}catch{return}}function nativeSetValues(value){const wrapper=readonlySnapshotWrappers.get(value);try{return Set.prototype.values.call(wrapper?.kind==="set"?wrapper.backing:value)}catch{return}}function snapshotDOMRect(value,budget){if(typeof DOMRectReadOnly>"u")return OMIT_COLLECTION_VALUE;const nativePrototype=DOMRectReadOnly.prototype,output=budget.realm.Object.create(budget.realm.Object.prototype);for(const key of["x","y","width","height","top","right","bottom","left"]){let coordinate;try{const getter=Object.getOwnPropertyDescriptor(nativePrototype,key)?.get;if(!getter)return OMIT_COLLECTION_VALUE;coordinate=getter.call(value)}catch{return OMIT_COLLECTION_VALUE}if(typeof coordinate!="number"||!Number.isFinite(coordinate))return OMIT_COLLECTION_VALUE;Object.defineProperty(output,key,{value:coordinate,enumerable:!0,configurable:!1,writable:!1})}return Object.freeze(output)}function readonlyMapFacade(backing,realm=snapshotRealm()){let facade;return facade=realm.Object.create(realm.Object.prototype),Object.defineProperties(facade,{size:{enumerable:!0,get:()=>backing.size},entries:{value:()=>backing.entries()},get:{value:key=>backing.get(key)},has:{value:key=>backing.has(key)},keys:{value:()=>backing.keys()},values:{value:()=>backing.values()},forEach:{value:(callback,thisArg)=>backing.forEach((entry,key)=>callback.call(thisArg,entry,key,facade))},[Symbol.iterator]:{value:()=>backing[Symbol.iterator]()}}),readonlySnapshotWrappers.set(facade,{kind:"map",backing}),Object.freeze(facade)}function readonlySetFacade(backing,realm=snapshotRealm()){let facade;return facade=realm.Object.create(realm.Object.prototype),Object.defineProperties(facade,{size:{enumerable:!0,get:()=>backing.size},entries:{value:()=>backing.entries()},has:{value:entry=>backing.has(entry)},keys:{value:()=>backing.keys()},values:{value:()=>backing.values()},forEach:{value:(callback,thisArg)=>backing.forEach(entry=>callback.call(thisArg,entry,entry,facade))},[Symbol.iterator]:{value:()=>backing[Symbol.iterator]()}}),readonlySnapshotWrappers.set(facade,{kind:"set",backing}),Object.freeze(facade)}function snapshotIdentityMap(entries,realm=snapshotRealm(),budget,entryLimit=budget?.entryLimit??PUBLIC_COLLECTION_ENTRY_LIMIT){const backing=new realm.Map;for(let count=0;count<entryLimit;count+=1){const next=entries.next();if(next.done)break;if(budget&&!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;backing.set(next.value[0],next.value[1])}return readonlyMapFacade(backing,realm)}function snapshotIdentitySet(values,realm=snapshotRealm(),budget,entryLimit=budget?.entryLimit??PUBLIC_COLLECTION_ENTRY_LIMIT){const backing=new realm.Set;for(let count=0;count<entryLimit;count+=1){const next=values.next();if(next.done)break;if(budget&&!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;backing.add(next.value)}return readonlySetFacade(backing,realm)}function nativeCollectionSize(source,kind){const wrapper=readonlySnapshotWrappers.get(source);try{const size=Object.getOwnPropertyDescriptor(kind==="map"?Map.prototype:Set.prototype,"size")?.get?.call(wrapper?.kind===kind?wrapper.backing:source);return typeof size=="number"?size:void 0}catch{return}}function recordNativeCollectionLoss(budget,source,kind,retained){const size=nativeCollectionSize(source,kind);size!==void 0&&recordRootLoss(budget,"oldest",size,retained)}function snapshotDetachedMap(source,entries,budget,depth,allowPrefixTruncation){const backing=new budget.realm.Map,facade=readonlyMapFacade(backing,budget.realm);rememberSnapshot(budget,source,facade);const settle=()=>(allowPrefixTruncation?recordNativeCollectionLoss(budget,source,"map",backing.size):(nativeCollectionSize(source,"map")??0)>budget.entryLimit&&(budget.truncated=!0),facade);for(let count=0;count<budget.entryLimit;count+=1){let next;try{next=entries.next()}catch{break}if(next.done)break;if(budget.remaining<=0||!consumeSnapshotWork(budget))return allowPrefixTruncation?settle():EXHAUSTED_COLLECTION_VALUE;const pair=snapshotTransaction(budget,()=>{budget.remaining-=1;const key=snapshotCollectionValue(next.value[0],budget,depth+1);if(isCollectionSnapshotFailure(key))return key;const entry=snapshotCollectionValue(next.value[1],budget,depth+1);return isCollectionSnapshotFailure(entry)?entry:[key,entry]});if(pair===EXHAUSTED_COLLECTION_VALUE)return budget.truncated=!0,allowPrefixTruncation?settle():EXHAUSTED_COLLECTION_VALUE;pair===OMIT_COLLECTION_VALUE?budget.invalid=!0:backing.set(pair[0],pair[1])}return settle()}function snapshotDetachedSet(source,values,budget,depth,allowPrefixTruncation){const backing=new budget.realm.Set,facade=readonlySetFacade(backing,budget.realm);rememberSnapshot(budget,source,facade);const settle=()=>(allowPrefixTruncation?recordNativeCollectionLoss(budget,source,"set",backing.size):(nativeCollectionSize(source,"set")??0)>budget.entryLimit&&(budget.truncated=!0),facade);for(let count=0;count<budget.entryLimit;count+=1){let next;try{next=values.next()}catch{break}if(next.done)break;if(budget.remaining<=0||!consumeSnapshotWork(budget))return allowPrefixTruncation?settle():EXHAUSTED_COLLECTION_VALUE;const entry=snapshotTransaction(budget,()=>(budget.remaining-=1,snapshotCollectionValue(next.value,budget,depth+1)));if(entry===EXHAUSTED_COLLECTION_VALUE)return budget.truncated=!0,allowPrefixTruncation?settle():EXHAUSTED_COLLECTION_VALUE;entry===OMIT_COLLECTION_VALUE?budget.invalid=!0:backing.add(entry)}return settle()}function snapshotIdentityCollection(value,view,budget,root){const realm=snapshotRealm(view);if(budget&&value!==null&&(typeof value=="object"||typeof value=="function")&&budget.seen.has(value))return budget.seen.get(value);if(isArrayValue(value)){if(budget&&!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;const sourceLength=readOwnArrayLength(value)??0,length=Math.min(sourceLength,boundedSnapshotLimit(root?.limits?.entries,PUBLIC_COLLECTION_ENTRY_LIMIT)),kept=root?.retain??"oldest",offset=kept==="newest"?sourceLength-length:0,output=new realm.Array(length);Object.setPrototypeOf(output,null),budget&&rememberSnapshot(budget,value,output);for(let index=0;index<length;index+=1){if(budget&&!consumeSnapshotWork(budget))return EXHAUSTED_COLLECTION_VALUE;const descriptor=getOwnDataDescriptor(value,String(offset+index));descriptor===MISSING_OWN_DATA_DESCRIPTOR||descriptor===UNSAFE_OWN_DATA_DESCRIPTOR||(output[index]=descriptor.value)}return Object.setPrototypeOf(output,realm.Array.prototype),length<sourceLength&&root?.onTruncate?.(Object.freeze({kept,retained:length,source:sourceLength})),Object.freeze(output)}if(value===null||typeof value!="object")return value;const mapEntries=nativeMapEntries(value);if(mapEntries){const output=snapshotIdentityMap(mapEntries,realm,budget,boundedSnapshotLimit(root?.limits?.entries,budget?.entryLimit??PUBLIC_COLLECTION_ENTRY_LIMIT));return output===EXHAUSTED_COLLECTION_VALUE||(budget&&rememberSnapshot(budget,value,output),reportIdentityCollectionLoss(root,value,"map",output.size)),output}const setValues=nativeSetValues(value);if(setValues){const output=snapshotIdentitySet(setValues,realm,budget,boundedSnapshotLimit(root?.limits?.entries,budget?.entryLimit??PUBLIC_COLLECTION_ENTRY_LIMIT));return output===EXHAUSTED_COLLECTION_VALUE||(budget&&rememberSnapshot(budget,value,output),reportIdentityCollectionLoss(root,value,"set",output.size)),output}return emptyRealmArray(realm)}function reportIdentityCollectionLoss(root,source,kind,retained){if(!root?.onTruncate)return;const size=nativeCollectionSize(source,kind);size!==void 0&&retained<size&&root.onTruncate(Object.freeze({kept:"oldest",retained,source:size}))}function snapshotEventDetail(value,view,preserveRootKeys=new Set,preserveCollectionItemKeys=new Set){if(value==null)return value;const budget={remaining:PUBLIC_COLLECTION_NODE_LIMIT,remainingWork:PUBLIC_COLLECTION_WORK_LIMIT,seen:new WeakMap,additions:[],realm:snapshotRealm(view),entryLimit:PUBLIC_COLLECTION_ENTRY_LIMIT,depthLimit:PUBLIC_COLLECTION_DEPTH_LIMIT,nestedArrayPrefix:!1,invalid:!1,truncated:!1},snapshot=snapshotTransaction(budget,()=>snapshotCollectionValue(value,budget,0,preserveRootKeys,preserveCollectionItemKeys));return isCollectionSnapshotFailure(snapshot)?null:snapshot}function trustedLyraConstructorChain(instance){const constructors=[];let prototype=Object.getPrototypeOf(instance);for(;prototype&&prototype!==LitElement.prototype;){const descriptor=Object.getOwnPropertyDescriptor(prototype,"constructor");typeof descriptor?.value=="function"&&constructors.push(descriptor.value),prototype=Object.getPrototypeOf(prototype)}return constructors}function lyraClassChain(ctor){const constructors=[];let current=ctor;for(;typeof current=="function"&¤t!==LitElement;)constructors.push(current),current=Object.getPrototypeOf(current);return constructors}const collectionPolicyByConstructor=new WeakMap;function collectionPropertyPolicy(ctor,name){let policies=collectionPolicyByConstructor.get(ctor);policies||(policies=new Map,collectionPolicyByConstructor.set(ctor,policies));const cached=policies.get(name);if(cached)return cached;let limits,owns=!1,preservesItemIdentity=!1,preservesObjectIdentity=!1,retainsNewest=!1,immutableSource=!1;for(const constructor of lyraClassChain(ctor)){const declared=constructor;!limits&&Object.hasOwn(constructor,"ownedCollectionLimits")&&declared.ownedCollectionLimits&&Object.hasOwn(declared.ownedCollectionLimits,name)&&(limits=declared.ownedCollectionLimits[name]),Object.prototype.hasOwnProperty.call(constructor,"ownedCollectionProperties")&&declared.ownedCollectionProperties.includes(name)&&(owns=!0),Object.prototype.hasOwnProperty.call(constructor,"identityCollectionProperties")&&declared.identityCollectionProperties.includes(name)&&(preservesItemIdentity=!0),Object.prototype.hasOwnProperty.call(constructor,"identityCollectionObjectProperties")&&declared.identityCollectionObjectProperties.includes(name)&&(preservesObjectIdentity=!0),Object.prototype.hasOwnProperty.call(constructor,"immutableSourceCollectionProperties")&&declared.immutableSourceCollectionProperties.includes(name)&&(immutableSource=!0),Object.prototype.hasOwnProperty.call(constructor,"appendOrderedCollectionProperties")&&declared.appendOrderedCollectionProperties.includes(name)&&(retainsNewest=!0)}const policy=Object.freeze({limits,owns,preservesItemIdentity,preservesObjectIdentity,retainsNewest,immutableSource});return policies.set(name,policy),policy}const COLLECTION_ENROLLMENT_FIELDS=["ownedCollectionProperties","identityCollectionProperties","identityCollectionObjectProperties","appendOrderedCollectionProperties","immutableSourceCollectionProperties"];function enrolledCollectionPropertyNames(ctor){const names=new Set;for(const constructor of lyraClassChain(ctor))for(const field of COLLECTION_ENROLLMENT_FIELDS){if(!Object.prototype.hasOwnProperty.call(constructor,field))continue;const declared=constructor;for(const name of declared[field])names.add(name)}return names}function inheritedPropertyDescriptor(prototype,name){let current=prototype;for(;current;){const descriptor=Object.getOwnPropertyDescriptor(current,name);if(descriptor)return descriptor;current=Object.getPrototypeOf(current)}}const installedOwnershipBoundaries=new WeakSet,ownershipBoundarySetters=new WeakMap;function samePolicy(a,b){return a.limits===b.limits&&a.owns===b.owns&&a.preservesItemIdentity===b.preservesItemIdentity&&a.preservesObjectIdentity===b.preservesObjectIdentity&&a.retainsNewest===b.retainsNewest&&a.immutableSource===b.immutableSource}function installOwnedCollectionAccessors(ctor){if(installedOwnershipBoundaries.has(ctor))return;installedOwnershipBoundaries.add(ctor);const prototype=ctor.prototype;for(const name of enrolledCollectionPropertyNames(ctor)){const policy=collectionPropertyPolicy(ctor,name);if(!policy.owns)continue;const declaration=ctor.elementProperties.get(name);if(!declaration||declaration.noAccessor)continue;const descriptor=inheritedPropertyDescriptor(prototype,name),inheritedSet=descriptor?.set;if(!inheritedSet)continue;const installed=ownershipBoundarySetters.get(inheritedSet);if(installed&&samePolicy(installed.policy,policy))continue;const originalSet=installed?.originalSet??inheritedSet,lastAssignments=new WeakMap,set=function(value){const previous=lastAssignments.get(this);if(previous&&declaration.hasChanged===void 0&&(!policy.preservesItemIdentity||policy.immutableSource)&&!policy.preservesObjectIdentity&&(("primitive"in previous.source?Object.is(value,previous.source.primitive):value!==void 0&&Object.is(value,previous.source.deref()))||Object.is(value,previous.retained)))return;const retainedLoss=previous&&!policy.preservesObjectIdentity&&Object.is(value,previous.retained)?publicCollectionTruncation(this,name):void 0,ownerView=this.ownerDocument?.defaultView;let truncation;const options={limits:policy.limits,retain:policy.retainsNewest?"newest":"oldest",onTruncate:report=>{truncation=report}},snapshot=policy.preservesObjectIdentity&&value!==null&&typeof value=="object"&&!isArrayValue(value)?value:policy.preservesItemIdentity?snapshotIdentityCollection(value,ownerView,void 0,options):snapshotPublicCollection(value,ownerView,options);if(retainedLoss){const retained=truncation?.retained??(policy.preservesItemIdentity?isArrayValue(snapshot)?readOwnArrayLength(snapshot):snapshot!==null&&typeof snapshot=="object"?nativeCollectionSize(snapshot,"map")??nativeCollectionSize(snapshot,"set"):void 0:void 0)??retainedLoss.retained;truncation=Object.freeze({kept:truncation?.kept??retainedLoss.kept,retained,source:retainedLoss.source})}recordCollectionTruncation(this,name,truncation),originalSet.call(this,snapshot);const source=normalizedCollectionWrites.get(this)?.has(name)&&previous?previous.source:typeof value=="object"&&value!==null||typeof value=="function"?new WeakRef(value):{primitive:value};lastAssignments.set(this,{source,retained:descriptor.get?.call(this)??snapshot})};ownershipBoundarySetters.set(set,{policy,originalSet}),Object.defineProperty(prototype,name,{...descriptor,set})}}const collectionTruncations=new WeakMap;function collectionTruncationWarningKey(tagName,property){return`lyra-collection-truncated:${tagName}:${String(property)}`}function recordCollectionTruncation(host,name,truncation){let byName=collectionTruncations.get(host);if(!truncation){byName?.delete(name);return}byName||(byName=new Map,collectionTruncations.set(host,byName)),byName.set(name,truncation);const tagName=host.localName,property=String(name);devWarnOnce(collectionTruncationWarningKey(tagName,property),`<${tagName}>: '${property}' kept ${truncation.retained} of ${truncation.source} entries, the ${truncation.kept}; an assignment keeps at most ${PUBLIC_COLLECTION_ENTRY_LIMIT} per array and ${PUBLIC_COLLECTION_NODE_LIMIT} values, and drops values it cannot copy.`)}function publicCollectionTruncation(host,property){return collectionTruncations.get(host)?.get(property)}function snapshotEnrolledEventDetail(host,name,detail){let snapshotsDetail=!1;const identityDetailKeys=new Set,identityCollectionItemKeys=new Set;for(const candidate of trustedLyraConstructorChain(host)){const constructor=candidate;if(Object.prototype.hasOwnProperty.call(constructor,"immutableEventDetails")&&constructor.immutableEventDetails.includes(name)&&(snapshotsDetail=!0),Object.prototype.hasOwnProperty.call(constructor,"identityEventDetailProperties"))for(const key of constructor.identityEventDetailProperties[name]??[])identityDetailKeys.add(key);if(Object.prototype.hasOwnProperty.call(constructor,"identityEventDetailCollectionItems"))for(const key of constructor.identityEventDetailCollectionItems[name]??[])identityCollectionItemKeys.add(key)}return snapshotsDetail?snapshotEventDetail(detail,host.ownerDocument?.defaultView,identityDetailKeys,identityCollectionItemKeys):detail}function declaresOwnedCollections(ctor){for(const constructor of lyraClassChain(ctor)){if(!Object.prototype.hasOwnProperty.call(constructor,"ownedCollectionProperties"))continue;if(constructor.ownedCollectionProperties.length>0)return!0}return!1}const collectionSupport=/* @__PURE__ */Object.freeze({installProperties:installOwnedCollectionAccessors,snapshotEvent:snapshotEnrolledEventDetail}),eventCollectionSupport=/* @__PURE__ */Object.freeze({installProperties(ctor){declaresOwnedCollections(ctor)&&devWarnOnce(`lyra-event-collection-support:${ctor.name}`,`${ctor.name} enrolls ownedCollectionProperties but declares eventCollectionSupport; declare collectionSupport so those properties cross the immutable collection boundary.`)},snapshotEvent:snapshotEnrolledEventDetail});export{collectionSupport,collectionTruncationWarningKey,eventCollectionSupport,publicCollectionTruncation,snapshotEventDetail,snapshotPublicCollection,writeNormalizedOwnedCollection};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const localeLoaders=Object.freeze({am:()=>import("@aceshooting/lyra-translations/am.js"),ar:()=>import("@aceshooting/lyra-translations/ar.js"),bho:()=>import("@aceshooting/lyra-translations/bho.js"),bn:()=>import("@aceshooting/lyra-translations/bn.js"),cs:()=>import("@aceshooting/lyra-translations/cs.js"),da:()=>import("@aceshooting/lyra-translations/da.js"),de:()=>import("@aceshooting/lyra-translations/de.js"),"de-CH":()=>import("@aceshooting/lyra-translations/de-CH.js"),el:()=>import("@aceshooting/lyra-translations/el.js"),es:()=>import("@aceshooting/lyra-translations/es.js"),fa:()=>import("@aceshooting/lyra-translations/fa.js"),"fa-AF":()=>import("@aceshooting/lyra-translations/fa-AF.js"),fi:()=>import("@aceshooting/lyra-translations/fi.js"),fil:()=>import("@aceshooting/lyra-translations/tl.js"),fr:()=>import("@aceshooting/lyra-translations/fr.js"),gu:()=>import("@aceshooting/lyra-translations/gu.js"),ha:()=>import("@aceshooting/lyra-translations/ha.js"),he:()=>import("@aceshooting/lyra-translations/he.js"),hi:()=>import("@aceshooting/lyra-translations/hi.js"),hr:()=>import("@aceshooting/lyra-translations/hr.js"),hu:()=>import("@aceshooting/lyra-translations/hu.js"),id:()=>import("@aceshooting/lyra-translations/id.js"),ig:()=>import("@aceshooting/lyra-translations/ig.js"),it:()=>import("@aceshooting/lyra-translations/it.js"),ja:()=>import("@aceshooting/lyra-translations/ja.js"),jv:()=>import("@aceshooting/lyra-translations/jv.js"),kk:()=>import("@aceshooting/lyra-translations/kk.js"),kn:()=>import("@aceshooting/lyra-translations/kn.js"),ko:()=>import("@aceshooting/lyra-translations/ko.js"),lah:()=>import("@aceshooting/lyra-translations/pnb.js"),ln:()=>import("@aceshooting/lyra-translations/ln.js"),ml:()=>import("@aceshooting/lyra-translations/ml.js"),mr:()=>import("@aceshooting/lyra-translations/mr.js"),ms:()=>import("@aceshooting/lyra-translations/ms.js"),my:()=>import("@aceshooting/lyra-translations/my.js"),nb:()=>import("@aceshooting/lyra-translations/nb.js"),ne:()=>import("@aceshooting/lyra-translations/ne.js"),nl:()=>import("@aceshooting/lyra-translations/nl.js"),nn:()=>import("@aceshooting/lyra-translations/nn.js"),om:()=>import("@aceshooting/lyra-translations/om.js"),or:()=>import("@aceshooting/lyra-translations/or.js"),pa:()=>import("@aceshooting/lyra-translations/pa.js"),pcm:()=>import("@aceshooting/lyra-translations/pcm.js"),pl:()=>import("@aceshooting/lyra-translations/pl.js"),ps:()=>import("@aceshooting/lyra-translations/ps.js"),"pt-BR":()=>import("@aceshooting/lyra-translations/pt-BR.js"),"pt-PT":()=>import("@aceshooting/lyra-translations/pt-PT.js"),ro:()=>import("@aceshooting/lyra-translations/ro.js"),ru:()=>import("@aceshooting/lyra-translations/ru.js"),sd:()=>import("@aceshooting/lyra-translations/sd.js"),sl:()=>import("@aceshooting/lyra-translations/sl.js"),su:()=>import("@aceshooting/lyra-translations/su.js"),sv:()=>import("@aceshooting/lyra-translations/sv.js"),sw:()=>import("@aceshooting/lyra-translations/sw.js"),ta:()=>import("@aceshooting/lyra-translations/ta.js"),te:()=>import("@aceshooting/lyra-translations/te.js"),th:()=>import("@aceshooting/lyra-translations/th.js"),tr:()=>import("@aceshooting/lyra-translations/tr.js"),uk:()=>import("@aceshooting/lyra-translations/uk.js"),ur:()=>import("@aceshooting/lyra-translations/ur.js"),uz:()=>import("@aceshooting/lyra-translations/uz.js"),vi:()=>import("@aceshooting/lyra-translations/vi.js"),yo:()=>import("@aceshooting/lyra-translations/yo.js"),"zh-CN":()=>import("@aceshooting/lyra-translations/zh-CN.js"),"zh-TW":()=>import("@aceshooting/lyra-translations/zh-TW.js"),zu:()=>import("@aceshooting/lyra-translations/zu.js")});export{localeLoaders};
|
|
1
|
+
const localeLoaders=Object.freeze({am:()=>import("@aceshooting/lyra-translations/am.js"),ar:()=>import("@aceshooting/lyra-translations/ar.js"),bho:()=>import("@aceshooting/lyra-translations/bho.js"),bn:()=>import("@aceshooting/lyra-translations/bn.js"),cs:()=>import("@aceshooting/lyra-translations/cs.js"),da:()=>import("@aceshooting/lyra-translations/da.js"),de:()=>import("@aceshooting/lyra-translations/de.js"),"de-CH":()=>import("@aceshooting/lyra-translations/de-CH.js"),el:()=>import("@aceshooting/lyra-translations/el.js"),"en-GB":()=>import("@aceshooting/lyra-translations/en-GB.js"),es:()=>import("@aceshooting/lyra-translations/es.js"),"es-419":()=>import("@aceshooting/lyra-translations/es-419.js"),fa:()=>import("@aceshooting/lyra-translations/fa.js"),"fa-AF":()=>import("@aceshooting/lyra-translations/fa-AF.js"),fi:()=>import("@aceshooting/lyra-translations/fi.js"),fil:()=>import("@aceshooting/lyra-translations/tl.js"),fr:()=>import("@aceshooting/lyra-translations/fr.js"),"fr-CA":()=>import("@aceshooting/lyra-translations/fr-CA.js"),gu:()=>import("@aceshooting/lyra-translations/gu.js"),ha:()=>import("@aceshooting/lyra-translations/ha.js"),he:()=>import("@aceshooting/lyra-translations/he.js"),hi:()=>import("@aceshooting/lyra-translations/hi.js"),hr:()=>import("@aceshooting/lyra-translations/hr.js"),hu:()=>import("@aceshooting/lyra-translations/hu.js"),id:()=>import("@aceshooting/lyra-translations/id.js"),ig:()=>import("@aceshooting/lyra-translations/ig.js"),it:()=>import("@aceshooting/lyra-translations/it.js"),ja:()=>import("@aceshooting/lyra-translations/ja.js"),jv:()=>import("@aceshooting/lyra-translations/jv.js"),kk:()=>import("@aceshooting/lyra-translations/kk.js"),kn:()=>import("@aceshooting/lyra-translations/kn.js"),ko:()=>import("@aceshooting/lyra-translations/ko.js"),lah:()=>import("@aceshooting/lyra-translations/pnb.js"),ln:()=>import("@aceshooting/lyra-translations/ln.js"),ml:()=>import("@aceshooting/lyra-translations/ml.js"),mr:()=>import("@aceshooting/lyra-translations/mr.js"),ms:()=>import("@aceshooting/lyra-translations/ms.js"),my:()=>import("@aceshooting/lyra-translations/my.js"),nb:()=>import("@aceshooting/lyra-translations/nb.js"),ne:()=>import("@aceshooting/lyra-translations/ne.js"),nl:()=>import("@aceshooting/lyra-translations/nl.js"),nn:()=>import("@aceshooting/lyra-translations/nn.js"),om:()=>import("@aceshooting/lyra-translations/om.js"),or:()=>import("@aceshooting/lyra-translations/or.js"),pa:()=>import("@aceshooting/lyra-translations/pa.js"),pcm:()=>import("@aceshooting/lyra-translations/pcm.js"),pl:()=>import("@aceshooting/lyra-translations/pl.js"),ps:()=>import("@aceshooting/lyra-translations/ps.js"),"pt-BR":()=>import("@aceshooting/lyra-translations/pt-BR.js"),"pt-PT":()=>import("@aceshooting/lyra-translations/pt-PT.js"),ro:()=>import("@aceshooting/lyra-translations/ro.js"),ru:()=>import("@aceshooting/lyra-translations/ru.js"),sd:()=>import("@aceshooting/lyra-translations/sd.js"),sl:()=>import("@aceshooting/lyra-translations/sl.js"),su:()=>import("@aceshooting/lyra-translations/su.js"),sv:()=>import("@aceshooting/lyra-translations/sv.js"),sw:()=>import("@aceshooting/lyra-translations/sw.js"),ta:()=>import("@aceshooting/lyra-translations/ta.js"),te:()=>import("@aceshooting/lyra-translations/te.js"),th:()=>import("@aceshooting/lyra-translations/th.js"),tr:()=>import("@aceshooting/lyra-translations/tr.js"),uk:()=>import("@aceshooting/lyra-translations/uk.js"),ur:()=>import("@aceshooting/lyra-translations/ur.js"),uz:()=>import("@aceshooting/lyra-translations/uz.js"),vi:()=>import("@aceshooting/lyra-translations/vi.js"),yo:()=>import("@aceshooting/lyra-translations/yo.js"),"zh-CN":()=>import("@aceshooting/lyra-translations/zh-CN.js"),"zh-HK":()=>import("@aceshooting/lyra-translations/zh-HK.js"),"zh-TW":()=>import("@aceshooting/lyra-translations/zh-TW.js"),zu:()=>import("@aceshooting/lyra-translations/zu.js")});export{localeLoaders};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getActiveNativeModal,isPageHelperRegion}from"./native-modal-context.js";import{activateNonmodalOverlay}from"./nonmodal-overlay-manager.js";import{RenderedStateController}from"./rendered-state.js";import{lockScroll}from"./scroll-lock.js";import{acquireOverlayRoutingSuspension,activateOverlayStack,observeOverlayStack}from"./overlay-stack.js";const EMPTY_STACK={entries:[]},modalStates=new WeakMap;function authoredOverlayInert(host){const state=modalStates.get(host.ownerDocument);if(!state)return host.inert;const records=state.observer?.takeRecords();return records?.length&&handleMutations(state,records),state.inerted.get(host)??host.inert}function modalStateFor(doc){const existing=modalStates.get(doc);if(existing)return existing;const state={document:doc,snapshot:EMPTY_STACK,registrations:0,externalModalSuspensions:new Set,inerted:new Map,pendingInertWrites:new Map,observedRoots:new Set,allowedParents:new Set,inertUpdateQueued:!1,started:!1};return modalStates.set(doc,state),state}function scheduleInertUpdate(state){state.inertUpdateQueued||(state.inertUpdateQueued=!0,queueMicrotask(()=>{state.inertUpdateQueued=!1,applyTopmostInert(state)}))}function pruneExternalModalSuspensions(state){let changed=!1;for(const entry of state.externalModalSuspensions)entry.root.isConnected&&entry.root.ownerDocument===state.document||(entry.active=!1,state.externalModalSuspensions.delete(entry),entry.releaseRouting(),changed=!0);return changed}function movesStackHost(state,record){for(const entry of state.snapshot.entries)for(const list of[record.addedNodes,record.removedNodes])for(const node of list)if(node.contains(entry.host))return!0;return!1}function handleMutations(state,records){const prunedExternalModal=pruneExternalModalSuspensions(state);let needsInertUpdate=prunedExternalModal;for(let index=0;index<records.length;index++){const record=records[index];if(!record)continue;if(record.type==="childList"){(state.allowedParents.has(record.target)||movesStackHost(state,record))&&(needsInertUpdate=!0);continue}if(record.attributeName==="open"){needsInertUpdate=!0;continue}const element=record.target;let nextRecord;for(let nextIndex=index+1;nextIndex<records.length;nextIndex++){const candidate=records[nextIndex];if(candidate?.type==="attributes"&&candidate.attributeName==="inert"&&candidate.target===element){nextRecord=candidate;break}}const newValue=nextRecord?nextRecord.oldValue!==null:element.hasAttribute("inert"),pending=state.pendingInertWrites.get(element);if(pending?.[0]===newValue){pending.shift(),pending.length===0&&state.pendingInertWrites.delete(element);continue}state.inerted.has(element)&&(state.inerted.set(element,newValue),needsInertUpdate=!0)}needsInertUpdate&&(prunedExternalModal?applyTopmostInert(state):scheduleInertUpdate(state)),stopModalStateIfIdle(state)}const mutationObserverOptions={attributeFilter:["inert","open"],attributeOldValue:!0,attributes:!0,childList:!0,subtree:!0};function observeMutationRoot(state,root){!state.observer||state.observedRoots.has(root)||(state.observer.observe(root===state.document?state.document.documentElement:root,mutationObserverOptions),state.observedRoots.add(root))}function startModalState(state){if(state.started)return;state.started=!0;const Observer=state.document.defaultView?.MutationObserver??MutationObserver;state.observer=new Observer(records=>handleMutations(state,records)),observeMutationRoot(state,state.document),state.unsubscribeStack=observeOverlayStack(state.document,snapshot=>{state.snapshot=snapshot,applyTopmostInert(state)})}function stopModalState(state){if(state.started){state.started=!1,state.unsubscribeStack?.(),state.unsubscribeStack=void 0;for(const[element,intended]of state.inerted)element.inert=intended;state.inerted.clear(),state.observer?.disconnect(),state.observer=void 0,state.observedRoots.clear(),state.pendingInertWrites.clear(),state.snapshot=EMPTY_STACK}}function stopModalStateIfIdle(state){state.registrations===0&&state.externalModalSuspensions.size===0&&stopModalState(state)}function retainModalState(doc){const state=modalStateFor(doc);state.registrations++,startModalState(state);let active=!0;return()=>{active&&(active=!1,state.registrations--,stopModalStateIfIdle(state))}}function setInertByManager(state,element,value){if(element.inert!==value){if(state.observer&&state.observedRoots.has(element.getRootNode())){let pending=state.pendingInertWrites.get(element);pending||(pending=[],state.pendingInertWrites.set(element,pending)),pending.push(value)}else state.pendingInertWrites.delete(element);element.inert=value}}function inertElement(state,element,desired){if(!("inert"in element)||element.localName==="dialog"&&element.matches(":modal")||isPageHelperRegion(element))return;const htmlElement=element;desired.add(htmlElement),state.inerted.has(htmlElement)||state.inerted.set(htmlElement,htmlElement.inert),setInertByManager(state,htmlElement,!0)}function pathParent(element){return element.assignedSlot??element.parentNode}function parentPathElement(parent){return parent.nodeType===Node.ELEMENT_NODE?parent:parent.host??null}function composedChildren(parent){return parent.localName==="slot"?parent.assignedElements({flatten:!0}):"children"in parent?Array.from(parent.children):[]}function isShadowRoot(node){return node.nodeType===11&&"host"in node}function addAllowedPath(allowed,host,doc){let current=host;for(;current&¤t!==doc.body&¤t!==doc.documentElement;){const parent=pathParent(current);if(!parent)break;let children=allowed.get(parent);children||(children=new Set,allowed.set(parent,children)),children.add(current),current=parentPathElement(parent)}}function modalAllowedRoot(entry,doc){const explicit=entry.modalRoot?.()??null;return explicit?.isConnected&&explicit.ownerDocument===doc?explicit:entry.host}function applyTopmostInert(state){let modalIndex=-1;for(let index=state.snapshot.entries.length-1;index>=0;index--)if(state.snapshot.entries[index]?.modal){modalIndex=index;break}const desired=new Set;if(state.allowedParents=new Set,state.externalModalSuspensions.size>0){const allowed=new Map;for(const suspension of state.externalModalSuspensions)addAllowedPath(allowed,suspension.root,state.document);inertOutsideAllowedPaths(state,allowed,desired)}else if(modalIndex!==-1){const allowed=new Map;for(const entry of state.snapshot.entries.slice(modalIndex))if(entry.host.isConnected){addAllowedPath(allowed,modalAllowedRoot(entry,state.document),state.document);for(const root of entry.auxiliaryRoots?.()??[])root.isConnected&&root.ownerDocument===state.document&&addAllowedPath(allowed,root,state.document)}const nativeModal=getActiveNativeModal(state.document);nativeModal&&addAllowedPath(allowed,nativeModal,state.document),inertOutsideAllowedPaths(state,allowed,desired)}for(const[element,intended]of state.inerted)desired.has(element)||(setInertByManager(state,element,intended),state.inerted.delete(element))}function inertOutsideAllowedPaths(state,allowed,desired){for(const[parent,children]of allowed){state.allowedParents.add(parent),isShadowRoot(parent)&&observeMutationRoot(state,parent);for(const child of composedChildren(parent))children.has(child)||inertElement(state,child,desired)}}function activateOverlay(options){if(options.modal===!1&&options.trapFocus===!1&&!options.suspendWhenUnrendered&&!options.lockScroll)return activateNonmodalOverlay(options);const modal=options.modal!==!1;let releaseModalState,releaseScrollLock,renderedState;const coreHandle=activateOverlayStack({...options,initiallySuspended:options.suspendWhenUnrendered===!0,modal,trapFocus:options.trapFocus!==!1,onRegistered:doc=>{modal&&(releaseModalState=retainModalState(doc)),options.lockScroll&&(releaseScrollLock=lockScroll(doc))},onUnregistered:(_doc,deferResourceRelease)=>{const releaseModal=releaseModalState;releaseModalState=void 0;const release=releaseScrollLock;releaseScrollLock=void 0;const deferredRelease=release&&deferResourceRelease?release:void 0;return release&&!deferResourceRelease&&release(),releaseModal?.(),deferredRelease},onDeactivate:()=>renderedState?.stop()});return coreHandle.isActive()?(options.suspendWhenUnrendered&&(renderedState=new RenderedStateController(options.host,options.panel,rendered=>{if(!coreHandle.isActive())return;if(!rendered){coreHandle.suspend();return}const wasTopmost=coreHandle.isTopmost();coreHandle.resume(),!wasTopmost&&coreHandle.isTopmost()&&queueMicrotask(()=>coreHandle.focusInitial())}),renderedState.start()),{focusInitial:()=>{renderedState?.check(),coreHandle.focusInitial()},focusAutofocus:()=>(renderedState?.check(),coreHandle.focusAutofocus()),updateRestoreFocusTo:target=>coreHandle.updateRestoreFocusTo(target),deactivate:deactivateOptions=>coreHandle.deactivate(deactivateOptions),suspend:()=>coreHandle.suspend(),resume:()=>{renderedState&&!renderedState.check()||coreHandle.resume()},isTopmost:()=>(renderedState?.check(),coreHandle.isTopmost()),isActive:()=>coreHandle.isActive(),dismissBackdrop:()=>(renderedState?.check(),coreHandle.dismissBackdrop())}):coreHandle}function suspendLyraModalsFor(externalModal){if(!externalModal.isConnected)return()=>{};const state=modalStateFor(externalModal.ownerDocument);startModalState(state);const entry={root:externalModal,active:!0,releaseRouting:()=>{},state};return state.externalModalSuspensions.add(entry),entry.releaseRouting=acquireOverlayRoutingSuspension(state.document),applyTopmostInert(state),()=>{entry.active&&(entry.active=!1,entry.state.externalModalSuspensions.delete(entry),entry.releaseRouting(),applyTopmostInert(entry.state),stopModalStateIfIdle(entry.state))}}import{collectAutofocusElements,collectFocusableElements,composedContains,deepActiveElement}from"./overlay-stack.js";export{activateOverlay,authoredOverlayInert,collectAutofocusElements,collectFocusableElements,composedContains,deepActiveElement,suspendLyraModalsFor};
|
|
1
|
+
import{getActiveNativeModal,isPageHelperRegion}from"./native-modal-context.js";import{activateNonmodalOverlay}from"./nonmodal-overlay-manager.js";import{RenderedStateController}from"./rendered-state.js";import{lockScroll}from"./scroll-lock.js";import{acquireOverlayRoutingSuspension,activateOverlayStack,composedContains,observeOverlayStack}from"./overlay-stack.js";const EMPTY_STACK={entries:[]},modalStates=new WeakMap;function authoredOverlayInert(host){const state=modalStates.get(host.ownerDocument);if(!state)return host.inert;const records=state.observer?.takeRecords();return records?.length&&handleMutations(state,records),state.inerted.get(host)??host.inert}function modalStateFor(doc){const existing=modalStates.get(doc);if(existing)return existing;const state={document:doc,snapshot:EMPTY_STACK,registrations:0,externalModalSuspensions:new Set,inerted:new Map,pendingInertWrites:new Map,observedRoots:new Set,allowedParents:new Set,inertUpdateQueued:!1,started:!1};return modalStates.set(doc,state),state}function scheduleInertUpdate(state){state.inertUpdateQueued||(state.inertUpdateQueued=!0,queueMicrotask(()=>{state.inertUpdateQueued=!1,applyTopmostInert(state)}))}function pruneExternalModalSuspensions(state){let changed=!1;for(const entry of state.externalModalSuspensions)entry.root.isConnected&&entry.root.ownerDocument===state.document||(entry.active=!1,state.externalModalSuspensions.delete(entry),entry.releaseRouting(),changed=!0);return changed}function movesStackHost(state,record){for(const entry of state.snapshot.entries)for(const list of[record.addedNodes,record.removedNodes])for(const node of list)if(node.contains(entry.host))return!0;return!1}function handleMutations(state,records){const prunedExternalModal=pruneExternalModalSuspensions(state);let needsInertUpdate=prunedExternalModal;for(let index=0;index<records.length;index++){const record=records[index];if(!record)continue;if(record.type==="childList"){(state.allowedParents.has(record.target)||movesStackHost(state,record))&&(needsInertUpdate=!0);continue}if(record.attributeName==="open"){needsInertUpdate=!0;continue}const element=record.target;let nextRecord;for(let nextIndex=index+1;nextIndex<records.length;nextIndex++){const candidate=records[nextIndex];if(candidate?.type==="attributes"&&candidate.attributeName==="inert"&&candidate.target===element){nextRecord=candidate;break}}const newValue=nextRecord?nextRecord.oldValue!==null:element.hasAttribute("inert"),pending=state.pendingInertWrites.get(element);if(pending?.[0]===newValue){pending.shift(),pending.length===0&&state.pendingInertWrites.delete(element);continue}state.inerted.has(element)&&(state.inerted.set(element,newValue),needsInertUpdate=!0)}needsInertUpdate&&(prunedExternalModal?applyTopmostInert(state):scheduleInertUpdate(state)),stopModalStateIfIdle(state)}const mutationObserverOptions={attributeFilter:["inert","open"],attributeOldValue:!0,attributes:!0,childList:!0,subtree:!0};function observeMutationRoot(state,root){!state.observer||state.observedRoots.has(root)||(state.observer.observe(root===state.document?state.document.documentElement:root,mutationObserverOptions),state.observedRoots.add(root))}function startModalState(state){if(state.started)return;state.started=!0;const Observer=state.document.defaultView?.MutationObserver??MutationObserver;state.observer=new Observer(records=>handleMutations(state,records)),observeMutationRoot(state,state.document),state.unsubscribeStack=observeOverlayStack(state.document,snapshot=>{state.snapshot=snapshot,applyTopmostInert(state)})}function stopModalState(state){if(state.started){state.started=!1,state.unsubscribeStack?.(),state.unsubscribeStack=void 0;for(const[element,intended]of state.inerted)element.inert=intended;state.inerted.clear(),state.observer?.disconnect(),state.observer=void 0,state.observedRoots.clear(),state.pendingInertWrites.clear(),state.snapshot=EMPTY_STACK}}function stopModalStateIfIdle(state){state.registrations===0&&state.externalModalSuspensions.size===0&&stopModalState(state)}function retainModalState(doc){const state=modalStateFor(doc);state.registrations++,startModalState(state);let active=!0;return()=>{active&&(active=!1,state.registrations--,stopModalStateIfIdle(state))}}function setInertByManager(state,element,value){if(element.inert!==value){if(state.observer&&state.observedRoots.has(element.getRootNode())){let pending=state.pendingInertWrites.get(element);pending||(pending=[],state.pendingInertWrites.set(element,pending)),pending.push(value)}else state.pendingInertWrites.delete(element);element.inert=value}}function inertElement(state,element,desired){if(!("inert"in element)||element.localName==="dialog"&&element.matches(":modal")||isPageHelperRegion(element))return;const htmlElement=element;desired.add(htmlElement),state.inerted.has(htmlElement)||state.inerted.set(htmlElement,htmlElement.inert),setInertByManager(state,htmlElement,!0)}function pathParent(element){return element.assignedSlot??element.parentNode}function parentPathElement(parent){return parent.nodeType===Node.ELEMENT_NODE?parent:parent.host??null}function composedChildren(parent){return parent.localName==="slot"?parent.assignedElements({flatten:!0}):"children"in parent?Array.from(parent.children):[]}function isShadowRoot(node){return node.nodeType===11&&"host"in node}function addAllowedPath(allowed,host,doc){let current=host;for(;current&¤t!==doc.body&¤t!==doc.documentElement;){const parent=pathParent(current);if(!parent)break;let children=allowed.get(parent);children||(children=new Set,allowed.set(parent,children)),children.add(current),current=parentPathElement(parent)}}function modalAllowedRoot(entry,doc){const explicit=entry.modalRoot?.()??null;return explicit?.isConnected&&explicit.ownerDocument===doc?explicit:entry.host}function applyTopmostInert(state){let modalIndex=-1;for(let index=state.snapshot.entries.length-1;index>=0;index--)if(state.snapshot.entries[index]?.modal){modalIndex=index;break}const desired=new Set;if(state.allowedParents=new Set,state.externalModalSuspensions.size>0){const allowed=new Map;for(const suspension of state.externalModalSuspensions)addAllowedPath(allowed,suspension.root,state.document);inertOutsideAllowedPaths(state,allowed,desired)}else if(modalIndex!==-1){const allowed=new Map,interactiveRoots=[];for(const entry of state.snapshot.entries.slice(modalIndex)){if(!entry.host.isConnected||interactiveRoots.some(root=>composedContains(root,entry.host)))continue;const modalRoot=modalAllowedRoot(entry,state.document);addAllowedPath(allowed,modalRoot,state.document),interactiveRoots.push(modalRoot);for(const root of entry.auxiliaryRoots?.()??[])root.isConnected&&root.ownerDocument===state.document&&(addAllowedPath(allowed,root,state.document),interactiveRoots.push(root))}const nativeModal=getActiveNativeModal(state.document);nativeModal&&addAllowedPath(allowed,nativeModal,state.document),inertOutsideAllowedPaths(state,allowed,desired)}for(const[element,intended]of state.inerted)desired.has(element)||(setInertByManager(state,element,intended),state.inerted.delete(element))}function inertOutsideAllowedPaths(state,allowed,desired){for(const[parent,children]of allowed){state.allowedParents.add(parent),isShadowRoot(parent)&&observeMutationRoot(state,parent);for(const child of composedChildren(parent))children.has(child)||inertElement(state,child,desired)}}function activateOverlay(options){if(options.modal===!1&&options.trapFocus===!1&&!options.suspendWhenUnrendered&&!options.lockScroll)return activateNonmodalOverlay(options);const modal=options.modal!==!1;let releaseModalState,releaseScrollLock,renderedState;const coreHandle=activateOverlayStack({...options,initiallySuspended:options.suspendWhenUnrendered===!0,modal,trapFocus:options.trapFocus!==!1,onRegistered:doc=>{modal&&(releaseModalState=retainModalState(doc)),options.lockScroll&&(releaseScrollLock=lockScroll(doc))},onUnregistered:(_doc,deferResourceRelease)=>{const releaseModal=releaseModalState;releaseModalState=void 0;const release=releaseScrollLock;releaseScrollLock=void 0;const deferredRelease=release&&deferResourceRelease?release:void 0;return release&&!deferResourceRelease&&release(),releaseModal?.(),deferredRelease},onDeactivate:()=>renderedState?.stop()});return coreHandle.isActive()?(options.suspendWhenUnrendered&&(renderedState=new RenderedStateController(options.host,options.panel,rendered=>{if(!coreHandle.isActive())return;if(!rendered){coreHandle.suspend();return}const wasTopmost=coreHandle.isTopmost();coreHandle.resume(),!wasTopmost&&coreHandle.isTopmost()&&queueMicrotask(()=>coreHandle.focusInitial())}),renderedState.start()),{focusInitial:()=>{renderedState?.check(),coreHandle.focusInitial()},focusAutofocus:()=>(renderedState?.check(),coreHandle.focusAutofocus()),updateRestoreFocusTo:target=>coreHandle.updateRestoreFocusTo(target),deactivate:deactivateOptions=>coreHandle.deactivate(deactivateOptions),suspend:()=>coreHandle.suspend(),resume:()=>{renderedState&&!renderedState.check()||coreHandle.resume()},isTopmost:()=>(renderedState?.check(),coreHandle.isTopmost()),isActive:()=>coreHandle.isActive(),dismissBackdrop:()=>(renderedState?.check(),coreHandle.dismissBackdrop())}):coreHandle}function suspendLyraModalsFor(externalModal){if(!externalModal.isConnected)return()=>{};const state=modalStateFor(externalModal.ownerDocument);startModalState(state);const entry={root:externalModal,active:!0,releaseRouting:()=>{},state};return state.externalModalSuspensions.add(entry),entry.releaseRouting=acquireOverlayRoutingSuspension(state.document),applyTopmostInert(state),()=>{entry.active&&(entry.active=!1,entry.state.externalModalSuspensions.delete(entry),entry.releaseRouting(),applyTopmostInert(entry.state),stopModalStateIfIdle(entry.state))}}import{collectAutofocusElements,collectFocusableElements,composedContains as composedContains2,deepActiveElement}from"./overlay-stack.js";export{activateOverlay,authoredOverlayInert,collectAutofocusElements,collectFocusableElements,composedContains2 as composedContains,deepActiveElement,suspendLyraModalsFor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getActiveNativeModal}from"./native-modal-context.js";import{takeOverlayOrder}from"./overlay-order.js";import{deepActiveElementIn}from"./active-element.js";import{composedContains,flattenedParentElement}from"./composed-tree.js";import{scheduleDeferredFocusReturn,cancelDeferredFocusReturn}from"./deferred-focus-return.js";import{collectComposedAutofocusElements,collectComposedFocusTargets,isComposedFocusAvailable}from"./focus-navigation.js";import{isHtmlElement}from"./dom-guards.js";import{leaseInlineStyleProperty}from"./style-property-lease.js";const STACK_PROPERTY="--lr-overlay-stack-index",STACK_BASE=1e3,STACK_STEP=2,states=new WeakMap,hostEntries=new WeakMap;function createInactiveOverlayHandle(){return{focusInitial:()=>{},focusAutofocus:()=>!1,updateRestoreFocusTo:()=>{},deactivate:()=>{},suspend:()=>{},resume:()=>{},isTopmost:()=>!1,isActive:()=>!1,dismissBackdrop:()=>!1}}function deepActiveElement(doc=typeof document>"u"?void 0:document){return deepActiveElementIn(doc)}function collectFocusableElements(root){return collectComposedFocusTargets(root).elements}function collectAutofocusElements(root){return collectComposedAutofocusElements(root).elements}function tryFocus(target){if(!target||!isComposedFocusAvailable(target))return!1;target.focus();const active=deepActiveElement(target.ownerDocument);return active===target||composedContains(target,active)}function focusAutofocusTarget(panel){for(const candidate of collectAutofocusElements(panel)){if(tryFocus(candidate))return!0;for(const inner of collectFocusableElements(candidate))if(tryFocus(inner))return!0}return!1}function auxiliaryRoots(entry){const panel=entry.options.panel();return[...new Set(entry.options.auxiliaryRoots?.()??[])].filter(root=>root.isConnected&&root.ownerDocument===entry.state.document&&(!panel||!composedContains(panel,root)))}function entryContainsFocus(entry,panel,active){return entry.options.auxiliaryRoots?active!==null&&isComposedFocusAvailable(active)&&[panel,...auxiliaryRoots(entry)].some(root=>composedContains(root,active)):composedContains(panel,active)}function entryTabStops(entry,panel){const roots=entry.options.auxiliaryRoots?[panel,...auxiliaryRoots(entry)]:[panel];return[...new Set(roots.flatMap(root=>collectComposedFocusTargets(root,{browserTabOrder:!0}).elements))]}function composedPath(element){const path=[];for(let current=element;current;current=flattenedParentElement(current))path.unshift(current);return path}function precedes(first,second){let index=0;for(;first[index]&&first[index]===second[index];)index+=1;return first[index]?!!(second[index]&&first[index].compareDocumentPosition(second[index])&4):!!second[index]}function focusEntry(entry,preserveCurrent=!0){const panel=entry.options.panel();if(!panel)return;const active=deepActiveElement(entry.state.document);if(preserveCurrent&&entryContainsFocus(entry,panel,active)||(entry.initialFocusDecision===void 0&&(entry.initialFocusDecision=entry.options.beforeInitialFocus?.()!==!1),!entry.initialFocusDecision)||focusAutofocusTarget(panel))return;const preferred=entry.options.preferredInitialFocus?.()??null;if(!(preferred&&composedContains(panel,preferred)&&tryFocus(preferred))){for(const target of collectFocusableElements(panel))if(tryFocus(target))return;panel.focus()}}function handleTab(state,entry,event){const panel=entry.options.panel();if(!panel)return;const focusable=entryTabStops(entry,panel);if(focusable.length===0){event.preventDefault(),panel.focus();return}const active=deepActiveElement(state.document),first=focusable[0],last=focusable[focusable.length-1],activeIndex=active?focusable.indexOf(active):-1;if(activeIndex===-1){let target;const roots=entry.options.auxiliaryRoots?[panel,...auxiliaryRoots(entry)]:[panel];if(active&&roots.some(root=>composedContains(root,active))){const activePath=composedPath(active);if(event.shiftKey)for(let index=focusable.length-1;index>=0&&!target;index-=1)precedes(composedPath(focusable[index]),activePath)&&(target=focusable[index]);else target=focusable.find(stop=>precedes(activePath,composedPath(stop)));if(target&&target.tabIndex>=0&&!entry.options.auxiliaryRoots)return}event.preventDefault(),(target??(event.shiftKey?last:first)).focus()}else if(event.shiftKey&&active===first)event.preventDefault(),last.focus();else if(!event.shiftKey&&active===last)event.preventDefault(),first.focus();else{const next=focusable[activeIndex+(event.shiftKey?-1:1)];next&&(next.tabIndex<0||auxiliaryRoots(entry).length>0)&&(event.preventDefault(),next.focus())}}function nearestTrappingEntryBelowTop(state){for(let index=state.stack.length-2;index>=0;index-=1){const entry=state.stack[index];if(entry&&entry.options.trapFocus!==!1)return entry}}function snapshotFor(state){return{entries:state.stack.map(entry=>({host:entry.options.host,modal:entry.options.modal,modalRoot:entry.options.modalRoot,auxiliaryRoots:entry.options.auxiliaryRoots}))}}function notifyStackObservers(state){if(state.observers.size===0)return;const snapshot=snapshotFor(state);for(const observer of state.observers)observer(snapshot)}function startState(state){state.started||(state.started=!0,state.document.addEventListener("keydown",state.onKeyDown))}function stopState(state){state.started&&(state.started=!1,state.document.removeEventListener("keydown",state.onKeyDown))}function stopStateIfIdle(state){state.stack.length===0&&stopState(state)}function createState(doc){const state={};return state.document=doc,state.stack=[],state.routingSuspensions=new Set,state.observers=new Set,state.started=!1,state.onKeyDown=event=>{if(event.defaultPrevented||event.isComposing||event.keyCode===229||state.routingSuspensions.size>0)return;const entry=state.stack[state.stack.length-1];if(!entry||event.key!=="Escape"&&event.key!=="Tab")return;const nativeModal=getActiveNativeModal(doc),panel=entry.options.panel();if(!(nativeModal&&(!panel||!composedContains(nativeModal,panel)))){if(event.key==="Escape")event.preventDefault(),entry.options.onEscape();else if(event.key==="Tab"){if(entry.options.trapFocus!==!1){handleTab(state,entry,event);return}entry.options.onTab?.();const trapping=nearestTrappingEntryBelowTop(state),trappingPanel=trapping?.options.panel();trapping&&trappingPanel&&!event.defaultPrevented&&(!nativeModal||composedContains(nativeModal,trappingPanel))&&entryContainsFocus(trapping,trappingPanel,deepActiveElement(doc))&&handleTab(state,trapping,event)}}},states.set(doc,state),state}function stateFor(doc){return states.get(doc)??createState(doc)}function observeOverlayStack(doc,observer){const state=stateFor(doc);return state.observers.add(observer),observer(snapshotFor(state)),()=>{state.observers.delete(observer)}}function acquireOverlayRoutingSuspension(doc){const state=stateFor(doc),token=Symbol();let active=!0;return state.routingSuspensions.add(token),()=>{active&&(active=!1,state.routingSuspensions.delete(token))}}function restoreStackStyle(entry){entry.stackStyleLease?.release(),entry.stackStyleLease=void 0}function updateStackStyles(state){state.stack.forEach((entry,index)=>{const value=String(STACK_BASE+index*STACK_STEP);entry.stackStyleLease?entry.stackStyleLease.set(value):entry.stackStyleLease=leaseInlineStyleProperty(entry.options.host,STACK_PROPERTY,value)})}function registerEntry(entry,state,preserveStackOrder=!1){if(entry.registered)return;startState(state),(!preserveStackOrder||entry.state!==state)&&(entry.stackOrder=takeOverlayOrder(state.document)),entry.state=state,entry.registered=!0,entry.options.onRegistered?.(state.document);const nextIndex=state.stack.findIndex(candidate=>candidate.stackOrder>entry.stackOrder);nextIndex===-1?state.stack.push(entry):state.stack.splice(nextIndex,0,entry),updateStackStyles(state),notifyStackObservers(state)}function unregisterEntry(entry,deferResourceRelease=!1){if(!entry.registered){const hasHigherEntry=entry.state.stack.some(candidate=>candidate.stackOrder>entry.stackOrder);return entry.state.routingSuspensions.size===0&&entry.wasTopmostOnSuspend&&!hasHigherEntry}const state=entry.state,index=state.stack.indexOf(entry),wasTopmost=state.routingSuspensions.size===0&&index===state.stack.length-1;return index!==-1&&state.stack.splice(index,1),entry.registered=!1,entry.wasTopmostOnSuspend=wasTopmost,entry.deferredResourceRelease=entry.options.onUnregistered?.(state.document,deferResourceRelease),restoreStackStyle(entry),updateStackStyles(state),notifyStackObservers(state),stopStateIfIdle(state),wasTopmost}function syncEntryRegistration(entry){if(!entry.active||entry.manuallySuspended){unregisterEntry(entry);return}const state=stateFor(entry.options.host.ownerDocument);registerEntry(entry,state,entry.state===state)}function validRestoreFocusElement(value,doc){return isHtmlElement(value)&&value.ownerDocument===doc?value:null}function resolveRestoreFocusTarget(entry){const source=entry.restoreFocusTo;if(typeof source!="function")return validRestoreFocusElement(source,entry.state.document);try{return validRestoreFocusElement(source(),entry.state.document)}catch{return null}}function rebaseReturnTargets(entry){for(const candidate of entry.state.stack){if(candidate===entry||candidate.stackOrder<=entry.stackOrder)continue;const candidateTarget=typeof candidate.restoreFocusTo=="function"?null:validRestoreFocusElement(candidate.restoreFocusTo,entry.state.document);candidateTarget&&composedContains(entry.options.host,candidateTarget)&&(candidate.restoreFocusTo=entry.restoreFocusTo)}}function restoreEntryFocus(entry){if(tryFocus(resolveRestoreFocusTarget(entry)))return;const next=entry.state.stack[entry.state.stack.length-1];next&&focusEntry(next,!1)}function deactivateEntry(entry,restoreFocus,deferResourceRelease=!1){if(!entry.active)return;const host=entry.options.host;cancelDeferredFocusReturn(host);const release=deactivateActiveEntry(entry,restoreFocus,deferResourceRelease);if(restoreFocus){const pass=entry.options.deferredReturn?.();pass&&scheduleDeferredFocusReturn({...pass,host})}return release}function deactivateActiveEntry(entry,restoreFocus,deferResourceRelease){const heldFocus=panelHoldsFocus(entry);rebaseReturnTargets(entry);const wasTopmost=unregisterEntry(entry,deferResourceRelease),deferredResourceRelease=entry.deferredResourceRelease;if(entry.deferredResourceRelease=void 0,entry.active=!1,entry.manuallySuspended=!1,entry.suspendGeneration++,entry.options.onDeactivate?.(),hostEntries.get(entry.options.host)===entry&&hostEntries.delete(entry.options.host),!wasTopmost)return deferredResourceRelease;if(restoreFocus)return restoreEntryFocus(entry),deferredResourceRelease;const next=entry.state.stack[entry.state.stack.length-1];return next&&(heldFocus||next.options.trapFocus)&&focusEntry(next),deferredResourceRelease}function panelHoldsFocus(entry){const panel=entry.options.panel();return panel!==null&&entryContainsFocus(entry,panel,deepActiveElement(entry.state.document))}function activateOverlayStack(options){cancelDeferredFocusReturn(options.host);const previous=hostEntries.get(options.host),inheritedReturnTarget=previous?.active?previous.restoreFocusTo:void 0;previous?.active&&previous.handle.deactivate({restoreFocus:!1});const doc=options.host.ownerDocument;if(!doc)return createInactiveOverlayHandle();const active=deepActiveElement(doc),captured=active&&typeof active.focus=="function"?active:null,entry={};return entry.options=options,entry.restoreFocusTo=options.restoreFocusTo!==void 0?options.restoreFocusTo:inheritedReturnTarget??captured,entry.active=!0,entry.registered=!1,entry.manuallySuspended=options.initiallySuspended===!0,entry.initialFocusDecision=void 0,entry.wasTopmostOnSuspend=!1,entry.suspendGeneration=0,entry.state=stateFor(doc),entry.stackOrder=takeOverlayOrder(doc,options.orderReservation),entry.handle={focusInitial:()=>{entry.active&&entry.registered&&entry.state.routingSuspensions.size===0&&entry.state.stack[entry.state.stack.length-1]===entry&&focusEntry(entry)},focusAutofocus:()=>{if(!entry.active||!entry.registered||entry.state.routingSuspensions.size>0)return!1;const panel=entry.options.panel();if(!panel)return!1;const active2=deepActiveElement(entry.state.document);return entryContainsFocus(entry,panel,active2)?!1:focusAutofocusTarget(panel)},updateRestoreFocusTo:target=>{entry.active&&(entry.restoreFocusTo=target)},deactivate:(deactivateOptions={})=>deactivateEntry(entry,deactivateOptions.restoreFocus!==!1,deactivateOptions.deferScrollLockRelease===!0),suspend:()=>{if(!entry.active||entry.manuallySuspended)return;entry.manuallySuspended=!0,syncEntryRegistration(entry);const generation=++entry.suspendGeneration;queueMicrotask(()=>{entry.active&&!entry.registered&&entry.suspendGeneration===generation&&!entry.options.host.isConnected&&deactivateEntry(entry,!0)})},resume:()=>{!entry.active||!entry.manuallySuspended||(entry.suspendGeneration++,entry.manuallySuspended=!1,syncEntryRegistration(entry))},isTopmost:()=>entry.active&&entry.registered&&entry.state.routingSuspensions.size===0&&entry.state.stack[entry.state.stack.length-1]===entry,isActive:()=>entry.active,dismissBackdrop:()=>!entry.handle.isTopmost()||!entry.options.onBackdrop?!1:(entry.options.onBackdrop(),!0)},hostEntries.set(options.host,entry),entry.manuallySuspended||registerEntry(entry,entry.state,!0),entry.handle}export{acquireOverlayRoutingSuspension,activateOverlayStack,collectAutofocusElements,collectFocusableElements,composedContains,deepActiveElement,observeOverlayStack};
|
|
1
|
+
import{getActiveNativeModal}from"./native-modal-context.js";import{takeOverlayOrder}from"./overlay-order.js";import{deepActiveElementIn}from"./active-element.js";import{composedContains,flattenedParentElement}from"./composed-tree.js";import{scheduleDeferredFocusReturn,cancelDeferredFocusReturn}from"./deferred-focus-return.js";import{collectComposedAutofocusElements,collectComposedFocusTargets,isComposedFocusAvailable}from"./focus-navigation.js";import{isHtmlElement}from"./dom-guards.js";import{leaseInlineStyleProperty}from"./style-property-lease.js";const STACK_PROPERTY="--lr-overlay-stack-index",STACK_BASE=1e3,STACK_STEP=2,states=new WeakMap,hostEntries=new WeakMap;function createInactiveOverlayHandle(){return{focusInitial:()=>{},focusAutofocus:()=>!1,updateRestoreFocusTo:()=>{},deactivate:()=>{},suspend:()=>{},resume:()=>{},isTopmost:()=>!1,isActive:()=>!1,dismissBackdrop:()=>!1}}function deepActiveElement(doc=typeof document>"u"?void 0:document){return deepActiveElementIn(doc)}function collectFocusableElements(root){return collectComposedFocusTargets(root).elements}function collectAutofocusElements(root){return collectComposedAutofocusElements(root).elements}function tryFocus(target){if(!target||!isComposedFocusAvailable(target))return!1;target.focus();const active=deepActiveElement(target.ownerDocument);return active===target||composedContains(target,active)}function focusAutofocusTarget(panel){for(const candidate of collectAutofocusElements(panel)){if(tryFocus(candidate))return!0;for(const inner of collectFocusableElements(candidate))if(tryFocus(inner))return!0}return!1}function auxiliaryRoots(entry){const panel=entry.options.panel();return[...new Set(entry.options.auxiliaryRoots?.()??[])].filter(root=>root.isConnected&&root.ownerDocument===entry.state.document&&(!panel||!composedContains(panel,root)))}function entryContainsFocus(entry,panel,active){return entry.options.auxiliaryRoots?active!==null&&isComposedFocusAvailable(active)&&[panel,...auxiliaryRoots(entry)].some(root=>composedContains(root,active)):composedContains(panel,active)}function entryTabStops(entry,panel){const roots=entry.options.auxiliaryRoots?[panel,...auxiliaryRoots(entry)]:[panel];return[...new Set(roots.flatMap(root=>collectComposedFocusTargets(root,{browserTabOrder:!0}).elements))]}function composedPath(element){const path=[];for(let current=element;current;current=flattenedParentElement(current))path.unshift(current);return path}function precedes(first,second){let index=0;for(;first[index]&&first[index]===second[index];)index+=1;return first[index]?!!(second[index]&&first[index].compareDocumentPosition(second[index])&4):!!second[index]}function focusEntry(entry,preserveCurrent=!0){const panel=entry.options.panel();if(!panel)return;const active=deepActiveElement(entry.state.document);if(preserveCurrent&&entryContainsFocus(entry,panel,active)||(entry.initialFocusDecision===void 0&&(entry.initialFocusDecision=entry.options.beforeInitialFocus?.()!==!1),!entry.initialFocusDecision)||focusAutofocusTarget(panel))return;const preferred=entry.options.preferredInitialFocus?.()??null;if(!(preferred&&composedContains(panel,preferred)&&tryFocus(preferred))){for(const target of collectFocusableElements(panel))if(tryFocus(target))return;panel.focus()}}function handleTab(state,entry,event){const panel=entry.options.panel();if(!panel)return;const focusable=entryTabStops(entry,panel);if(focusable.length===0){event.preventDefault(),panel.focus();return}const active=deepActiveElement(state.document),first=focusable[0],last=focusable[focusable.length-1],activeIndex=active?focusable.indexOf(active):-1;if(activeIndex===-1){let target;const roots=entry.options.auxiliaryRoots?[panel,...auxiliaryRoots(entry)]:[panel];if(active&&roots.some(root=>composedContains(root,active))){const activePath=composedPath(active);if(event.shiftKey)for(let index=focusable.length-1;index>=0&&!target;index-=1)precedes(composedPath(focusable[index]),activePath)&&(target=focusable[index]);else target=focusable.find(stop=>precedes(activePath,composedPath(stop)));if(target&&target.tabIndex>=0&&!entry.options.auxiliaryRoots)return}event.preventDefault(),(target??(event.shiftKey?last:first)).focus()}else if(event.shiftKey&&active===first)event.preventDefault(),last.focus();else if(!event.shiftKey&&active===last)event.preventDefault(),first.focus();else{const next=focusable[activeIndex+(event.shiftKey?-1:1)];next&&(next.tabIndex<0||auxiliaryRoots(entry).length>0)&&(event.preventDefault(),next.focus())}}function nearestTrappingEntryBelowTop(state){for(let index=state.stack.length-2;index>=0;index-=1){const entry=state.stack[index];if(entry&&entry.options.trapFocus!==!1)return entry}}function snapshotFor(state){return{entries:state.stack.map(entry=>({host:entry.options.host,modal:entry.options.modal,modalRoot:entry.options.modalRoot,auxiliaryRoots:entry.options.auxiliaryRoots}))}}function notifyStackObservers(state){if(state.observers.size===0)return;const snapshot=snapshotFor(state);for(const observer of state.observers)observer(snapshot)}function startState(state){state.started||(state.started=!0,state.document.addEventListener("keydown",state.onKeyDown))}function stopState(state){state.started&&(state.started=!1,state.document.removeEventListener("keydown",state.onKeyDown))}function stopStateIfIdle(state){state.stack.length===0&&stopState(state)}function createState(doc){const state={};return state.document=doc,state.stack=[],state.routingSuspensions=new Set,state.observers=new Set,state.started=!1,state.onKeyDown=event=>{if(event.defaultPrevented||event.isComposing||event.keyCode===229||state.routingSuspensions.size>0)return;const entry=state.stack[state.stack.length-1];if(!entry||event.key!=="Escape"&&event.key!=="Tab")return;const nativeModal=getActiveNativeModal(doc),panel=entry.options.panel();if(!(nativeModal&&(!panel||!composedContains(nativeModal,panel)))){if(event.key==="Escape")event.preventDefault(),entry.options.onEscape();else if(event.key==="Tab"){if(entry.options.trapFocus!==!1){handleTab(state,entry,event);return}entry.options.onTab?.();const trapping=nearestTrappingEntryBelowTop(state),trappingPanel=trapping?.options.panel();trapping&&trappingPanel&&!event.defaultPrevented&&(!nativeModal||composedContains(nativeModal,trappingPanel))&&entryContainsFocus(trapping,trappingPanel,deepActiveElement(doc))&&handleTab(state,trapping,event)}}},states.set(doc,state),state}function stateFor(doc){return states.get(doc)??createState(doc)}function observeOverlayStack(doc,observer){const state=stateFor(doc);return state.observers.add(observer),observer(snapshotFor(state)),()=>{state.observers.delete(observer)}}function acquireOverlayRoutingSuspension(doc){const state=stateFor(doc),token=Symbol();let active=!0;return state.routingSuspensions.add(token),()=>{active&&(active=!1,state.routingSuspensions.delete(token))}}function restoreStackStyle(entry){entry.stackStyleLease?.release(),entry.stackStyleLease=void 0}function updateStackStyles(state){state.stack.forEach((entry,index)=>{const value=String(STACK_BASE+index*STACK_STEP);entry.stackStyleLease?entry.stackStyleLease.set(value):entry.stackStyleLease=leaseInlineStyleProperty(entry.options.host,STACK_PROPERTY,value)})}function registerEntry(entry,state,preserveStackOrder=!1){if(entry.registered)return;startState(state),(!preserveStackOrder||entry.state!==state)&&(entry.stackOrder=takeOverlayOrder(state.document)),entry.state=state,entry.registered=!0,entry.options.onRegistered?.(state.document);const nextIndex=state.stack.findIndex(candidate=>candidate.stackOrder>entry.stackOrder);nextIndex===-1?state.stack.push(entry):state.stack.splice(nextIndex,0,entry),updateStackStyles(state),notifyStackObservers(state)}function unregisterEntry(entry,deferResourceRelease=!1){if(!entry.registered){const hasHigherEntry=entry.state.stack.some(candidate=>candidate.stackOrder>entry.stackOrder);return entry.state.routingSuspensions.size===0&&entry.wasTopmostOnSuspend&&!hasHigherEntry}const state=entry.state,index=state.stack.indexOf(entry),wasTopmost=state.routingSuspensions.size===0&&index===state.stack.length-1;return index!==-1&&state.stack.splice(index,1),entry.registered=!1,entry.wasTopmostOnSuspend=wasTopmost,entry.deferredResourceRelease=entry.options.onUnregistered?.(state.document,deferResourceRelease),restoreStackStyle(entry),updateStackStyles(state),notifyStackObservers(state),stopStateIfIdle(state),wasTopmost}function syncEntryRegistration(entry){if(!entry.active||entry.manuallySuspended){unregisterEntry(entry);return}const state=stateFor(entry.options.host.ownerDocument);registerEntry(entry,state,entry.state===state)}function validRestoreFocusElement(value,doc){return isHtmlElement(value)&&value.ownerDocument===doc?value:null}function resolveRestoreFocusTarget(entry){const source=entry.restoreFocusTo;if(typeof source!="function")return validRestoreFocusElement(source,entry.state.document);try{return validRestoreFocusElement(source(),entry.state.document)}catch{return null}}function rebaseReturnTargets(entry){for(const candidate of entry.state.stack){if(candidate===entry||candidate.stackOrder<=entry.stackOrder)continue;const candidateTarget=typeof candidate.restoreFocusTo=="function"?null:validRestoreFocusElement(candidate.restoreFocusTo,entry.state.document);candidateTarget&&composedContains(entry.options.host,candidateTarget)&&(candidate.restoreFocusTo=entry.restoreFocusTo)}}function restoreEntryFocus(entry){if(tryFocus(resolveRestoreFocusTarget(entry)))return;const next=entry.state.stack[entry.state.stack.length-1];next&&focusEntry(next,!1)}function deactivateEntry(entry,restoreFocus,deferResourceRelease=!1){if(!entry.active)return;const host=entry.options.host;cancelDeferredFocusReturn(host);const release=deactivateActiveEntry(entry,restoreFocus,deferResourceRelease);if(restoreFocus){const pass=entry.options.deferredReturn?.();pass&&scheduleDeferredFocusReturn({...pass,host})}return release}function deactivateActiveEntry(entry,restoreFocus,deferResourceRelease){const heldFocus=panelHoldsFocus(entry);rebaseReturnTargets(entry);const wasTopmost=unregisterEntry(entry,deferResourceRelease),deferredResourceRelease=entry.deferredResourceRelease;if(entry.deferredResourceRelease=void 0,entry.active=!1,entry.manuallySuspended=!1,entry.suspendGeneration++,entry.options.onDeactivate?.(),hostEntries.get(entry.options.host)===entry&&hostEntries.delete(entry.options.host),!wasTopmost)return deferredResourceRelease;if(restoreFocus)return restoreEntryFocus(entry),deferredResourceRelease;const next=entry.state.stack[entry.state.stack.length-1];if(!next)return deferredResourceRelease;if(heldFocus)focusEntry(next);else if(next.options.trapFocus){const doc=entry.state.document,active=deepActiveElement(doc);!entry.options.host.isConnected||active&&active!==doc.body&&active!==doc.documentElement?focusEntry(next):setTimeout(()=>{next.active&&next.registered&&entry.state.stack[entry.state.stack.length-1]===next&&focusEntry(next)},0)}return deferredResourceRelease}function panelHoldsFocus(entry){const panel=entry.options.panel();return panel!==null&&entryContainsFocus(entry,panel,deepActiveElement(entry.state.document))}function activateOverlayStack(options){cancelDeferredFocusReturn(options.host);const previous=hostEntries.get(options.host),inheritedReturnTarget=previous?.active?previous.restoreFocusTo:void 0;previous?.active&&previous.handle.deactivate({restoreFocus:!1});const doc=options.host.ownerDocument;if(!doc)return createInactiveOverlayHandle();const active=deepActiveElement(doc),captured=active&&typeof active.focus=="function"?active:null,entry={};return entry.options=options,entry.restoreFocusTo=options.restoreFocusTo!==void 0?options.restoreFocusTo:inheritedReturnTarget??captured,entry.active=!0,entry.registered=!1,entry.manuallySuspended=options.initiallySuspended===!0,entry.initialFocusDecision=void 0,entry.wasTopmostOnSuspend=!1,entry.suspendGeneration=0,entry.state=stateFor(doc),entry.stackOrder=takeOverlayOrder(doc,options.orderReservation),entry.handle={focusInitial:()=>{entry.active&&entry.registered&&entry.state.routingSuspensions.size===0&&entry.state.stack[entry.state.stack.length-1]===entry&&focusEntry(entry)},focusAutofocus:()=>{if(!entry.active||!entry.registered||entry.state.routingSuspensions.size>0)return!1;const panel=entry.options.panel();if(!panel)return!1;const active2=deepActiveElement(entry.state.document);return entryContainsFocus(entry,panel,active2)?!1:focusAutofocusTarget(panel)},updateRestoreFocusTo:target=>{entry.active&&(entry.restoreFocusTo=target)},deactivate:(deactivateOptions={})=>deactivateEntry(entry,deactivateOptions.restoreFocus!==!1,deactivateOptions.deferScrollLockRelease===!0),suspend:()=>{if(!entry.active||entry.manuallySuspended)return;entry.manuallySuspended=!0,syncEntryRegistration(entry);const generation=++entry.suspendGeneration;queueMicrotask(()=>{entry.active&&!entry.registered&&entry.suspendGeneration===generation&&!entry.options.host.isConnected&&deactivateEntry(entry,!0)})},resume:()=>{!entry.active||!entry.manuallySuspended||(entry.suspendGeneration++,entry.manuallySuspended=!1,syncEntryRegistration(entry))},isTopmost:()=>entry.active&&entry.registered&&entry.state.routingSuspensions.size===0&&entry.state.stack[entry.state.stack.length-1]===entry,isActive:()=>entry.active,dismissBackdrop:()=>!entry.handle.isTopmost()||!entry.options.onBackdrop?!1:(entry.options.onBackdrop(),!0)},hostEntries.set(options.host,entry),entry.manuallySuspended||registerEntry(entry,entry.state,!0),entry.handle}export{acquireOverlayRoutingSuspension,activateOverlayStack,collectAutofocusElements,collectFocusableElements,composedContains,deepActiveElement,observeOverlayStack};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const LYRA_PACKAGE_NAME="@aceshooting/lyra-ui",LYRA_PACKAGE_VERSION="29.1
|
|
1
|
+
const LYRA_PACKAGE_NAME="@aceshooting/lyra-ui",LYRA_PACKAGE_VERSION="29.2.1";export{LYRA_PACKAGE_NAME,LYRA_PACKAGE_VERSION};
|