@wcstack/media-query 4.19.0 → 4.20.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/README.ja.md CHANGED
@@ -34,7 +34,7 @@
34
34
  npm install @wcstack/media-query
35
35
  ```
36
36
 
37
- CDN(バージョン固定): `https://esm.run/@wcstack/media-query@4.19.0/auto`
37
+ CDN(バージョン固定): `https://esm.run/@wcstack/media-query@4.20.0/auto`
38
38
 
39
39
  ## クイックスタート
40
40
 
package/README.md CHANGED
@@ -34,7 +34,7 @@ A media query that only changes *styling* belongs in a stylesheet. This node is
34
34
  npm install @wcstack/media-query
35
35
  ```
36
36
 
37
- CDN (pinned): `https://esm.run/@wcstack/media-query@4.19.0/auto`
37
+ CDN (pinned): `https://esm.run/@wcstack/media-query@4.20.0/auto`
38
38
 
39
39
  ## Quick Start
40
40
 
package/dist/auto.min.js CHANGED
@@ -1,2 +1,2 @@
1
- const e={tagNames:{mediaQuery:"wcs-media-query"}};var t="@wcstack/media-query",s="4.19.0";const n=Object.freeze({matched:!1,media:"",supported:!1}),r=Object.freeze({matched:!1,media:"",supported:!0});class i extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"matched",event:"wcs-media-query:change",semantics:"state",getter:e=>e.detail.matched},{name:"media",event:"wcs-media-query:change",semantics:"state",getter:e=>e.detail.media},{name:"supported",event:"wcs-media-query:change",semantics:"state",getter:e=>e.detail.supported}],commands:[]};_target;_snapshot=n;_query="";_unsubscribe=null;_subscribed=!1;_gen=0;_injectedMatchMedia;_ready=Promise.resolve();constructor(e,t){super(),this._target=e??this,this._injectedMatchMedia=t?.matchMedia??null}get ready(){return this._ready}get query(){return this._query}get matched(){return this._snapshot.matched}get media(){return this._snapshot.media}get supported(){return this._snapshot.supported}observe(e=this._query){return this._subscribed&&e===this._query||(this._teardown(),this._query=e,this._subscribed=!0,this._subscribe(e)),this._ready}dispose(){this._subscribed=!1,this._teardown()}_resolveMatchMedia(){if(null!==this._injectedMatchMedia)return this._injectedMatchMedia;const e=globalThis;return"function"==typeof e.matchMedia?t=>e.matchMedia(t):null}_subscribe(e){const t=++this._gen,s=this._resolveMatchMedia();if(null===s)return void this._apply(n);if(""===e)return void this._apply(r);let i=null;try{i=s(e);const n=()=>{t===this._gen&&this._apply(this._read(i))};this._unsubscribe=function(e,t){if("function"==typeof e.addEventListener&&"function"==typeof e.removeEventListener)return e.addEventListener("change",t),()=>e.removeEventListener("change",t);if("function"==typeof e.addListener&&"function"==typeof e.removeListener)return e.addListener(t),()=>e.removeListener(t);return()=>{}}(i,n)}catch{i=null,this._unsubscribe=null}this._apply(null===i?r:this._read(i))}_teardown(){if(this._gen++,null!==this._unsubscribe){const e=this._unsubscribe;this._unsubscribe=null;try{e()}catch{}}}_read(e){return{matched:!0===e.matches,media:"string"==typeof e.media?e.media:"",supported:!0}}_apply(e){const t=this._snapshot;t.matched===e.matched&&t.media===e.media&&t.supported===e.supported||(this._snapshot=e,this._target.dispatchEvent(new CustomEvent("wcs-media-query:change",{detail:e,bubbles:!0})))}}function a(e,t){let s=Object.getPrototypeOf(e);for(;null!==s;){const e=Object.getOwnPropertyDescriptor(s,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;s=Object.getPrototypeOf(s)}return!1}const o=new WeakSet;function c(e,t,s){if(o.has(e))return;o.add(e);const n=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${n}> has the attribute ${t}="${s}": 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 u=new WeakMap;function d(e,t,s){const n=function(e,t){let s=u.get(e);return void 0===s&&(s=new Map,u.set(e,s)),s.has(t)||s.set(t,e.getAttribute(t)),s.get(t)}(e,t);!function(e,t,s){null===s?e.removeAttribute(t):e.setAttribute(t,s)}(e,t,void 0===s?n:null===s?null:String(s))}class h extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...i.wcBindable,inputs:[{name:"query",attribute:"query"}],commands:i.wcBindable.commands};static get observedAttributes(){return["query"]}_core;_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new i(this),this._internals=this._initInternals(),this._wireStates({"wcs-media-query:change":e=>({matched:!0===e.matched,supported:!0===e.supported})})}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[s,n]of Object.entries(e))this.addEventListener(s,e=>{const s=this.hasAttribute("debug-states");for(const[r,i]of Object.entries(n(e.detail))){try{i?t.add(r):t.delete(r)}catch{}s&&this.toggleAttribute(`data-wcs-state-${r}`,i)}})}get query(){return this.getAttribute("query")??""}set query(e){d(this,"query",e)}get matched(){return this._core.matched}get media(){return this._core.media}get supported(){return this._core.supported}get connectedCallbackPromise(){return this._connectedCallbackPromise}attributeChangedCallback(e,t,s){"query"===e&&this.isConnected&&this._core.observe(s??"")}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,s=t?.inputs;if(void 0===s)return;const n=e.getAttribute;for(const t of s){const s=t.name,r="function"==typeof n?n.call(e,s.toLowerCase()):null;if(null!==r&&r.startsWith("[object ")&&c(e,s,r),!Object.prototype.hasOwnProperty.call(e,s))continue;if(!a(e,s))continue;const i=e,o=i[s];delete i[s],i[s]=o}}(this),this.style.display="none",this._connectedCallbackPromise=this._core.observe(this.query)}disconnectedCallback(){this._core.dispose()}}const l=Symbol.for("wcstack.package"),p=new WeakSet;function b(e,t){Object.defineProperty(e,l,{value:t,configurable:!0})}function m(e,t,s,n,r){if(void 0!==n&&(s===n||s.prototype instanceof n))return;const i=s[l];if(i===r||p.has(e))return;p.add(e);const a=r.slice(0,r.lastIndexOf("@"));console.warn(`[${a}] [wcs/package-twice] <${t}> is already defined by ${i??`another copy of ${a} that does not name its version`}; this copy, ${r}, does nothing. Load each package once.`)}function f(n=customElements){!function(e,t,s){for(const[n,r]of s){const s=e.get(n);void 0===s?(b(r,t),e.define(n,r)):m(e,n,s,r,t)}}(n,`${t}@${s}`,[[e.tagNames.mediaQuery,h]])}var _;f(_);
1
+ const e={tagNames:{mediaQuery:"wcs-media-query"}};var t="@wcstack/media-query",s="4.20.0";const n=Object.freeze({matched:!1,media:"",supported:!1}),r=Object.freeze({matched:!1,media:"",supported:!0});class i extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"matched",event:"wcs-media-query:change",semantics:"state",getter:e=>e.detail.matched},{name:"media",event:"wcs-media-query:change",semantics:"state",getter:e=>e.detail.media},{name:"supported",event:"wcs-media-query:change",semantics:"state",getter:e=>e.detail.supported}],commands:[]};_target;_snapshot=n;_query="";_unsubscribe=null;_subscribed=!1;_gen=0;_injectedMatchMedia;_ready=Promise.resolve();constructor(e,t){super(),this._target=e??this,this._injectedMatchMedia=t?.matchMedia??null}get ready(){return this._ready}get query(){return this._query}get matched(){return this._snapshot.matched}get media(){return this._snapshot.media}get supported(){return this._snapshot.supported}observe(e=this._query){return this._subscribed&&e===this._query||(this._teardown(),this._query=e,this._subscribed=!0,this._subscribe(e)),this._ready}dispose(){this._subscribed=!1,this._teardown()}_resolveMatchMedia(){if(null!==this._injectedMatchMedia)return this._injectedMatchMedia;const e=globalThis;return"function"==typeof e.matchMedia?t=>e.matchMedia(t):null}_subscribe(e){const t=++this._gen,s=this._resolveMatchMedia();if(null===s)return void this._apply(n);if(""===e)return void this._apply(r);let i=null;try{i=s(e);const n=()=>{t===this._gen&&this._apply(this._read(i))};this._unsubscribe=function(e,t){if("function"==typeof e.addEventListener&&"function"==typeof e.removeEventListener)return e.addEventListener("change",t),()=>e.removeEventListener("change",t);if("function"==typeof e.addListener&&"function"==typeof e.removeListener)return e.addListener(t),()=>e.removeListener(t);return()=>{}}(i,n)}catch{i=null,this._unsubscribe=null}this._apply(null===i?r:this._read(i))}_teardown(){if(this._gen++,null!==this._unsubscribe){const e=this._unsubscribe;this._unsubscribe=null;try{e()}catch{}}}_read(e){return{matched:!0===e.matches,media:"string"==typeof e.media?e.media:"",supported:!0}}_apply(e){const t=this._snapshot;t.matched===e.matched&&t.media===e.media&&t.supported===e.supported||(this._snapshot=e,this._target.dispatchEvent(new CustomEvent("wcs-media-query:change",{detail:e,bubbles:!0})))}}function a(e,t){let s=Object.getPrototypeOf(e);for(;null!==s;){const e=Object.getOwnPropertyDescriptor(s,t);if(void 0!==e)return"function"==typeof e.get||"function"==typeof e.set;s=Object.getPrototypeOf(s)}return!1}const o=new WeakSet;function c(e,t,s){if(o.has(e))return;o.add(e);const n=e.localName??"element";console.warn(`[wcs/input-as-attribute] <${n}> has the attribute ${t}="${s}": 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 u=new WeakMap;function d(e,t,s){const n=function(e,t){let s=u.get(e);return void 0===s&&(s=new Map,u.set(e,s)),s.has(t)||s.set(t,e.getAttribute(t)),s.get(t)}(e,t);!function(e,t,s){null===s?e.removeAttribute(t):e.setAttribute(t,s)}(e,t,void 0===s?n:null===s?null:String(s))}class h extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...i.wcBindable,inputs:[{name:"query",attribute:"query"}],commands:i.wcBindable.commands};static get observedAttributes(){return["query"]}_core;_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new i(this),this._internals=this._initInternals(),this._wireStates({"wcs-media-query:change":e=>({matched:!0===e.matched,supported:!0===e.supported})})}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[s,n]of Object.entries(e))this.addEventListener(s,e=>{const s=this.hasAttribute("debug-states");for(const[r,i]of Object.entries(n(e.detail))){try{i?t.add(r):t.delete(r)}catch{}s&&this.toggleAttribute(`data-wcs-state-${r}`,i)}})}get query(){return this.getAttribute("query")??""}set query(e){d(this,"query",e)}get matched(){return this._core.matched}get media(){return this._core.media}get supported(){return this._core.supported}get connectedCallbackPromise(){return this._connectedCallbackPromise}attributeChangedCallback(e,t,s){"query"===e&&this.isConnected&&this._core.observe(s??"")}connectedCallback(){!function(e){const t=e.constructor?.wcBindable,s=t?.inputs;if(void 0===s)return;const n=e.getAttribute;for(const t of s){const s=t.name,r="function"==typeof n?n.call(e,s.toLowerCase()):null;if(null!==r&&r.startsWith("[object ")&&c(e,s,r),!Object.prototype.hasOwnProperty.call(e,s))continue;if(!a(e,s))continue;const i=e,o=i[s];delete i[s],i[s]=o}}(this),this.style.display="none",this._connectedCallbackPromise=this._core.observe(this.query)}disconnectedCallback(){this._core.dispose()}}const l=Symbol.for("wcstack.package"),p=new WeakSet;function b(e,t){Object.defineProperty(e,l,{value:t,configurable:!0})}function m(e,t,s,n,r){if(void 0!==n&&(s===n||s.prototype instanceof n))return;const i=s[l];if(i===r||p.has(e))return;p.add(e);const a=r.slice(0,r.lastIndexOf("@"));console.warn(`[${a}] [wcs/package-twice] <${t}> is already defined by ${i??`another copy of ${a} that does not name its version`}; this copy, ${r}, does nothing. Load each package once.`)}function f(n=customElements){!function(e,t,s){for(const[n,r]of s){const s=e.get(n);void 0===s?(b(r,t),e.define(n,r)):m(e,n,s,r,t)}}(n,`${t}@${s}`,[[e.tagNames.mediaQuery,h]])}var _;f(_);
2
2
  //# sourceMappingURL=auto.min.js.map
package/dist/index.esm.js CHANGED
@@ -58,7 +58,7 @@ function setConfig(partialConfig) {
58
58
  frozenConfig = null;
59
59
  }
60
60
 
61
- var pkg = {"name":"@wcstack/media-query","version":"4.19.0"};
61
+ var pkg = {"name":"@wcstack/media-query","version":"4.20.0"};
62
62
 
63
63
  const UNSUPPORTED_SNAPSHOT = Object.freeze({
64
64
  matched: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/media-query",
3
- "version": "4.19.0",
3
+ "version": "4.20.0",
4
4
  "description": "Declarative matchMedia component for Web Components. Framework-agnostic media-query monitor (prefers-color-scheme, prefers-reduced-motion, viewport width) via wc-bindable-protocol.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.esm.js",