@wcstack/pointer-lock 4.32.0 → 4.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto.min.js +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.esm.js +1 -1
- package/package.json +1 -1
package/dist/auto.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={tagNames:{pointerLock:"wcs-pointer-lock"}};var t="@wcstack/pointer-lock",r="4.
|
|
1
|
+
const e={tagNames:{pointerLock:"wcs-pointer-lock"}};var t="@wcstack/pointer-lock",r="4.34.0";const n="capability-missing",o="invalid-argument",s="not-allowed",i="pointer-lock-error";function c(e,t){const r=function(e){return"string"==typeof e?.message?e.message:String(e)}(e);if("capability-missing"===t)return{code:n,phase:"probe",recoverable:!1,message:r};if("invalid-argument"===t)return{code:o,phase:"start",recoverable:!1,message:r};const c=e?.name;return"NotAllowedError"===c||"TypeError"===c?{code:s,phase:"execute",recoverable:!0,message:r}:{code:i,phase:"execute",recoverable:!1,message:r}}function a(){return new DOMException("The browser refused the pointer lock request.","NotAllowedError")}class l extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"active",event:"wcs-pointer-lock:change",semantics:"state"},{name:"error",event:"wcs-pointer-lock:error",semantics:"state"},{name:"errorInfo",event:"wcs-pointer-lock:error-info-changed",semantics:"state"},{name:"supported",event:"wcs-pointer-lock:supported-changed",semantics:"state"}],commands:[{name:"requestPointerLock",async:!0},{name:"exitPointerLock"}]};_target;_active=!1;_error=null;_errorInfo=null;_resolvedTarget=null;_subscribed=!1;_gen=0;_request=null;_supportedPublished=!1;_ready=Promise.resolve();constructor(e){super(),this._target=e??this}get ready(){return this._ready}get active(){return this._active}get error(){return this._error}get errorInfo(){return this._errorInfo}get supported(){const e=Element.prototype;return"function"==typeof e.requestPointerLock||"function"==typeof e.webkitRequestPointerLock}observe(e){return this._publishSupported(),this._resolvedTarget=e,this._subscribed||(this._subscribed=!0,document.addEventListener(this._pointerLockChangeEventName(),this._onChange),document.addEventListener(this._pointerLockErrorEventName(),this._onLockError)),this._applyActive(),this._ready}dispose(){this._gen++,this._request=null,this._subscribed&&(this._subscribed=!1,document.removeEventListener(this._pointerLockChangeEventName(),this._onChange),document.removeEventListener(this._pointerLockErrorEventName(),this._onLockError)),this._resolvedTarget=null,this._setActive(!1)}async requestPointerLock(e){const t=++this._gen;if(this._resolvedTarget=e,this._request=null,!e)return void this._setError({message:"Pointer Lock target could not be resolved."},"invalid-argument");const r=this._requestPointerLockFn(e);if(!r)return void this._setError({message:"Pointer Lock API is not supported."},"capability-missing");const n={waiting:!1,refused:!1};this._request=n;try{const e=r();if("function"==typeof e?.then){if(this._request=null,await e,t!==this._gen)return;return this._setError(null),void this._applyActive()}if(n.refused)return this._request=null,void this._setError(a());this._setError(null),this._applyActive(),n.waiting=!0}catch(e){if(t!==this._gen)return;this._request=null,this._setError(e)}}exitPointerLock(){try{if(null===this._pointerLockElement())return;const e=this._exitPointerLockFn();if(!e)return;e(),this._setError(null),this._applyActive()}catch(e){this._setError(e)}}_requestPointerLockFn(e){const t=Element.prototype,r=t.requestPointerLock;if("function"==typeof r)return r.bind(e);const n=t.webkitRequestPointerLock;return"function"==typeof n?n.bind(e):void 0}_exitPointerLockFn(){const e=document;return e.exitPointerLock?.bind(document)??e.webkitExitPointerLock?.bind(document)}_pointerLockElement(){const e=document;return e.pointerLockElement??e.webkitPointerLockElement??null}_pointerLockChangeEventName(){return"onpointerlockchange"in document?"pointerlockchange":"webkitpointerlockchange"}_pointerLockErrorEventName(){return"onpointerlockerror"in document?"pointerlockerror":"webkitpointerlockerror"}_onChange=()=>{this._applyActive(),this._active&&(this._request=null)};_onLockError=()=>{const e=this._request;null!==e&&(e.waiting?(this._request=null,this._setError(a())):e.refused=!0)};_publishSupported(){const e=this.supported;this._supportedPublished!==e&&(this._supportedPublished=e,this._target.dispatchEvent(new CustomEvent("wcs-pointer-lock:supported-changed",{detail:e,bubbles:!0})))}_applyActive(){const e=null!==this._resolvedTarget&&this._pointerLockElement()===this._resolvedTarget;this._setActive(e)}_setActive(e){this._active!==e&&(this._active=e,this._target.dispatchEvent(new CustomEvent("wcs-pointer-lock:change",{detail:e,bubbles:!0})))}_setError(e,t){this._error!==e&&(this._error=e,this._commitErrorInfo(null===e?null:c(e,t)),this._target.dispatchEvent(new CustomEvent("wcs-pointer-lock:error",{detail:e,bubbles:!0})))}_commitErrorInfo(e){this._errorInfo=e,this._target.dispatchEvent(new CustomEvent("wcs-pointer-lock:error-info-changed",{detail:e,bubbles:!0}))}}function u(e,t){let r=Object.getPrototypeOf(e);for(;null!==r;){const e=Object.getOwnPropertyDescriptor(r,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;r=Object.getPrototypeOf(r)}return!1}const h=new WeakSet;function d(e,t,r){if(h.has(e))return;h.add(e);const n=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${n}> has the attribute ${t}="${r}": an object was written as an attribute, so the element did not receive it. A framework does that when the property is set before the element's definition loads (React 19), or when told to (Vue's .attr). Load the definition before rendering, or assign the property through a ref (Vue: .prop). (Said once per element.)`,e)}const p=new WeakMap;function _(e,t,r){const n=function(e,t){let r=p.get(e);return void 0===r&&(r=new Map,p.set(e,r)),r.has(t)||r.set(t,e.getAttribute(t)),r.get(t)}(e,t);!function(e,t,r){null===r?e.removeAttribute(t):e.setAttribute(t,r)}(e,t,void 0===r?n:null===r?null:String(r))}class g extends HTMLElement{static hasConnectedCallbackPromise=!0;static observedAttributes=["target"];static wcBindable={...l.wcBindable,inputs:[{name:"target",attribute:"target"}],commands:l.wcBindable.commands};_core;_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new l(this),this._internals=this._initInternals(),this._wireStates({"wcs-pointer-lock:change":e=>({active:!0===e})})}get connectedCallbackPromise(){return this._connectedCallbackPromise}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const e=this.attachInternals();return e.states.add("wcs-probe"),e.states.delete("wcs-probe"),e}catch{return null}}_wireStates(e){if(null===this._internals)return;const t=this._internals.states;for(const[r,n]of Object.entries(e))this.addEventListener(r,e=>{const r=this.hasAttribute("debug-states");for(const[o,s]of Object.entries(n(e.detail))){try{s?t.add(o):t.delete(o)}catch{}r&&this.toggleAttribute(`data-wcs-state-${o}`,s)}})}get target(){return this.getAttribute("target")??""}set target(e){_(this,"target",e)}get active(){return this._core.active}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get supported(){return this._core.supported}async requestPointerLock(){const{element:e}=this._resolveTarget();await this._core.requestPointerLock(e)}exitPointerLock(){this._core.exitPointerLock()}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,r=t?.inputs;if(void 0===r)return;const n=e.getAttribute;for(const t of r){const r=t.name,o="function"==typeof n?n.call(e,r.toLowerCase()):null;if(null!==o&&o.startsWith("[object ")&&d(e,r,o),!Object.prototype.hasOwnProperty.call(e,r))continue;if(!u(e,r))continue;const s=e,i=s[r];delete s[r],s[r]=i}}(this),this._applyDisplayAndObserve()}disconnectedCallback(){this._core.dispose()}attributeChangedCallback(e){"target"===e&&this.isConnected&&this._applyDisplayAndObserve()}_applyDisplayAndObserve(){const{element:e,display:t}=this._resolveTarget();this.style.display=t,this._connectedCallbackPromise=this._core.observe(e)}_resolveTarget(){const e=this.target;if("self"===e)return{element:this,display:"block"};if(""!==e){const t=this.getRootNode();return{element:this._safeQuery(t,e),display:"none"}}const t=this.firstElementChild;return t?{element:t,display:"contents"}:{element:this,display:"block"}}_safeQuery(e,t){try{return e.querySelector(t)}catch{return null}}}const b=Symbol.for("wcstack.package"),f=new WeakSet;function m(e,t){Object.defineProperty(e,b,{value:t,configurable:!0})}function v(e,t,r,n,o){if(void 0!==n&&(r===n||r.prototype instanceof n))return;const s=r[b];if(s===o||f.has(e))return;f.add(e);const i=o.slice(0,o.lastIndexOf("@"));console.warn(`[${i}] [wcs/package-twice] <${t}> is already defined by ${s??`another copy of ${i} that does not name its version`}; this copy, ${o}, does nothing. Load each package once.`)}function k(n=customElements){!function(e,t,r){for(const[n,o]of r){const r=e.get(n);void 0===r?(m(o,t),e.define(n,o)):v(e,n,r,o,t)}}(n,`${t}@${r}`,[[e.tagNames.pointerLock,g]])}var y;k(y);
|
|
2
2
|
//# sourceMappingURL=auto.min.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,15 @@ interface IWcBindableInput {
|
|
|
38
38
|
interface IWcBindableCommand {
|
|
39
39
|
readonly name: string;
|
|
40
40
|
readonly async?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* The declared members — entries of `properties` or of `inputs` — whose current value must be
|
|
43
|
+
* truthy for the command to be carried out (wc-bindable 0.11, SPEC-extensions § The `requires`
|
|
44
|
+
* hint). A declaration for tooling, documentation and diagnostics: the element still settles a
|
|
45
|
+
* call made anyway as it documents, and an applier must not skip or drop a call because of it.
|
|
46
|
+
* Do not list a member whose legitimate values include a falsy one (`0`, `""`, `false`), and
|
|
47
|
+
* keep an input listed here readable.
|
|
48
|
+
*/
|
|
49
|
+
readonly requires?: readonly string[];
|
|
41
50
|
}
|
|
42
51
|
interface IWcBindable {
|
|
43
52
|
readonly protocol: "wc-bindable";
|
package/dist/index.esm.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wcstack/pointer-lock",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.34.0",
|
|
4
4
|
"description": "Declarative Pointer Lock component for Web Components. Framework-agnostic Pointer Lock API control via wc-bindable-protocol.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.esm.js",
|