@wcstack/notification 1.25.0 → 1.26.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 CHANGED
@@ -1 +1,2 @@
1
- import{bootstrapNotification}from"./index.esm.min.js";bootstrapNotification();
1
+ const t={autoTrigger:!0,triggerAttribute:"data-notifytarget",tagNames:{notify:"wcs-notify"}},e="capability-missing",s="not-allowed",i="invalid-argument",r="show-failed",n="no-service-worker",o="notify-error";class a extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"permission",event:"wcs-notify:permission-change",semantics:"state"},{name:"granted",event:"wcs-notify:permission-change",semantics:"state",getter:t=>"granted"===t.detail},{name:"denied",event:"wcs-notify:permission-change",semantics:"state",getter:t=>"denied"===t.detail},{name:"prompt",event:"wcs-notify:permission-change",semantics:"state",getter:t=>"prompt"===t.detail},{name:"unsupported",event:"wcs-notify:permission-change",semantics:"state",getter:t=>"unsupported"===t.detail},{name:"error",event:"wcs-notify:error",semantics:"state"},{name:"errorInfo",event:"wcs-notify:error-info-changed",semantics:"state"},{name:"clicked",event:"wcs-notify:click",semantics:"event",getter:t=>t.detail},{name:"closed",event:"wcs-notify:close",semantics:"event",getter:t=>t.detail},{name:"shown",event:"wcs-notify:show",semantics:"event",getter:t=>t.detail}],commands:[{name:"request",async:!0},{name:"notify"},{name:"close"},{name:"closeAll"}]};_target;_mode="auto";_permission="prompt";_error=null;_errorInfo=null;_lastClick=null;_lastClose=null;_lastShow=null;_permissionStatus=null;_permissionSubscribed=!1;_gen=0;_ready=Promise.resolve();_idSeq=0;_constructed=new Map;_swTags=new Set;_channel=null;_serviceWorker=null;_clicksSubscribed=!1;_seenIds=[];constructor(t){super(),this._target=t??this}get permission(){return this._permission}get granted(){return"granted"===this._permission}get denied(){return"denied"===this._permission}get prompt(){return"prompt"===this._permission}get unsupported(){return"unsupported"===this._permission}get error(){return this._error}get errorInfo(){return this._errorInfo}get clicked(){return this._lastClick}get closed(){return this._lastClose}get shown(){return this._lastShow}get ready(){return this._ready}_setPermission(t){this._permission!==t&&(this._permission=t,this._target.dispatchEvent(new CustomEvent("wcs-notify:permission-change",{detail:t,bubbles:!0})))}_setError(t){this._error!==t&&(this._error=t,this._commitErrorInfo(null===t?null:function(t){const{error:a,message:c}=t;switch(a){case"unsupported":return{code:e,phase:"probe",recoverable:!1,message:c};case"not-granted":return{code:s,phase:"start",recoverable:!1,message:c};case"invalid-title":return{code:i,phase:"start",recoverable:!1,message:c};case"show-failed":return{code:r,phase:"execute",recoverable:!1,message:c};case"no-service-worker":return{code:n,phase:"execute",recoverable:!1,message:c};default:return{code:o,phase:"execute",recoverable:!1,message:c}}}(t)),this._target.dispatchEvent(new CustomEvent("wcs-notify:error",{detail:t,bubbles:!0})))}_commitErrorInfo(t){this._errorInfo=t,this._target.dispatchEvent(new CustomEvent("wcs-notify:error-info-changed",{detail:t,bubbles:!0}))}_emit(t,e){"click"===t?this._lastClick=e:"close"===t?this._lastClose=e:this._lastShow=e,this._target.dispatchEvent(new CustomEvent(`wcs-notify:${t}`,{detail:e,bubbles:!0}))}observe(t="auto"){return this._mode=t,this._permissionSubscribed||(this._ready=this._initPermission(),this._subscribeClicks()),this._ready}async request(){const t=this._api();if(!t||"function"!=typeof t.requestPermission)return this._setPermission("unsupported"),this._permission;try{const e=await t.requestPermission();this._setPermission(this._normalize(e))}catch{}return this._permission}notify(t,e={}){if(!this._api())return this._setError(this._err("unsupported","Notifications API is not available in this environment.")),"";if("granted"!==this._permission)return this._setError(this._err("not-granted","Notification permission is not granted; call request() first.")),"";if("string"!=typeof t)return this._setError(this._err("invalid-title","notify() requires a string title.")),"";const s="string"==typeof e.tag&&""!==e.tag?e.tag:this._nextId(),i=e.data,r={__wcsId:s,payload:i},n={...e,tag:s,data:r};return this._setError(null),this._show(t,n,s,i),s}close(t){if("string"!=typeof t||""===t)return;const e=this._constructed.get(t);e&&(e.close(),this._constructed.delete(t)),this._swTags.has(t)&&(this._closeSw(t),this._swTags.delete(t))}closeAll(){for(const t of this._constructed.values())t.close();this._constructed.clear();for(const t of this._swTags)this._closeSw(t);this._swTags.clear()}dispose(){this._permissionSubscribed=!1,this._clicksSubscribed=!1,this._gen++,this._permissionStatus&&(this._permissionStatus.removeEventListener("change",this._onPermissionChange),this._permissionStatus=null),this._channel&&(this._channel.removeEventListener("message",this._onInbound),this._channel.close(),this._channel=null),this._serviceWorker&&(this._serviceWorker.removeEventListener("message",this._onInbound),this._serviceWorker=null)}_initPermission(){const t=this._api();if(!t)return this._setPermission("unsupported"),Promise.resolve();if(this._permissionSubscribed=!0,"undefined"!=typeof navigator&&navigator.permissions&&"function"==typeof navigator.permissions.query){const e=++this._gen;return navigator.permissions.query({name:"notifications"}).then(t=>{e===this._gen&&(this._permissionStatus=t,this._setPermission(this._normalize(t.state)),t.addEventListener("change",this._onPermissionChange))},()=>{e===this._gen&&this._setPermission(this._normalize(t.permission))})}return this._setPermission(this._normalize(t.permission)),Promise.resolve()}_onPermissionChange=t=>{const e=t.target;this._setPermission(this._normalize(e.state))};_normalize(t){return"default"===t?"prompt":"granted"===t||"denied"===t||"prompt"===t?t:"prompt"}_show(t,e,s,i){if("sw"===this._mode)return void this._showViaSw(t,e,s,i);this._showViaConstructor(t,e,s,i)||("auto"===this._mode?this._showViaSw(t,e,s,i):this._setError(this._err("show-failed",'new Notification() is not usable here and mode="constructor" disallows the Service Worker fallback.')))}_showViaConstructor(t,e,s,i){const r=this._api(),n=this._gen;let o;try{o=new r(t,e)}catch(t){return!(t instanceof TypeError)&&(this._setError(this._err("show-failed","Failed to create the notification.")),!0)}return this._constructed.set(s,o),o.onshow=()=>{n===this._gen&&this._emit("show",{tag:s,data:i,action:""})},o.onclick=()=>{n===this._gen&&this._emit("click",{tag:s,data:i,action:""})},o.onclose=()=>{this._constructed.delete(s),n===this._gen&&this._emit("close",{tag:s,data:i,action:""})},o.onerror=()=>{n===this._gen&&this._setError(this._err("show-failed","The notification failed to display."))},!0}_showViaSw(t,e,s,i){const r=navigator.serviceWorker;if(!r)return void this._setError(this._err("no-service-worker","Service Worker is required to show this notification but is unavailable."));const n=this._gen;this._swTags.add(s),r.ready.then(s=>s.showNotification(t,e)).then(()=>{n===this._gen&&this._emit("show",{tag:s,data:i,action:""})}).catch(()=>{n===this._gen&&this._setError(this._err("show-failed","ServiceWorkerRegistration.showNotification() failed."))})}_closeSw(t){const e=navigator.serviceWorker;e&&e.ready.then(e=>e.getNotifications({tag:t}).then(t=>{for(const e of t)e.close()})).catch(()=>{})}_subscribeClicks(){if(this._clicksSubscribed)return;this._clicksSubscribed=!0,"function"==typeof BroadcastChannel&&(this._channel=new BroadcastChannel("wcs-notify"),this._channel.addEventListener("message",this._onInbound));const t=navigator.serviceWorker;t&&(this._serviceWorker=t,t.addEventListener("message",this._onInbound))}_onInbound=t=>{const e=t.data;e&&!0===e.__wcsNotify&&(this._isDuplicate(e.id)||this._emit("click",{tag:e.tag,data:this._unwrap(e.data),action:e.action}))};_isDuplicate(t){return!!this._seenIds.includes(t)||(this._seenIds.push(t),this._seenIds.length>50&&this._seenIds.shift(),!1)}_unwrap(t){return null!==t&&"object"==typeof t&&"__wcsId"in t?t.payload:t}_api(){const t=globalThis;return"function"==typeof t.Notification?t.Notification:void 0}_nextId(){return"wcs-"+ ++this._idSeq}_err(t,e){return{error:t,message:e}}}let c=!1;function h(e){const s=e.target;if(!(s instanceof Element))return;let i;try{i=s.closest(`[${t.triggerAttribute}]`)}catch{return}if(!i)return;const r=i.getAttribute(t.triggerAttribute);if(!r)return;const n=customElements.get(t.tagNames.notify),o=document.getElementById(r);if(!(n&&o instanceof n))return;const a=i.getAttribute("data-notifytitle"),c=null!==a?a:i.textContent.trim(),h=i.getAttribute("data-notifybody");o.notify(c,null!==h?{body:h}:void 0)}function l(t,e){let s=Object.getPrototypeOf(t);for(;null!==s;){const t=Object.getOwnPropertyDescriptor(s,e);if(void 0!==t)return"function"==typeof t.get||"function"==typeof t.set;s=Object.getPrototypeOf(s)}return!1}class u extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...a.wcBindable,inputs:[{name:"notice"},{name:"mode",attribute:"mode"},{name:"body",attribute:"body"},{name:"icon",attribute:"icon"},{name:"badge",attribute:"badge"},{name:"tag",attribute:"tag"},{name:"lang",attribute:"lang"},{name:"dir",attribute:"dir"},{name:"requireInteraction",attribute:"require-interaction"},{name:"silent",attribute:"silent"},{name:"renotify",attribute:"renotify"},{name:"manual",attribute:"manual"}],commands:a.wcBindable.commands};_core;_notice="";_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new a(this),this._internals=this._initInternals(),this._wireStates({"wcs-notify:permission-change":t=>({granted:"granted"===t,denied:"denied"===t,prompt:"prompt"===t,unsupported:"unsupported"===t}),"wcs-notify:error":t=>({error:null!=t})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const t=this.attachInternals();return t.states.add("wcs-probe"),t.states.delete("wcs-probe"),t}catch{return null}}_wireStates(t){if(null===this._internals)return;const e=this._internals.states;for(const[s,i]of Object.entries(t))this.addEventListener(s,t=>{const s=this.hasAttribute("debug-states");for(const[r,n]of Object.entries(i(t.detail))){try{n?e.add(r):e.delete(r)}catch{}s&&this.toggleAttribute(`data-wcs-state-${r}`,n)}})}get mode(){const t=this.getAttribute("mode");return"sw"===t||"constructor"===t?t:"auto"}set mode(t){this.setAttribute("mode",t)}get body(){return this.getAttribute("body")??""}set body(t){this._reflect("body",t)}get icon(){return this.getAttribute("icon")??""}set icon(t){this._reflect("icon",t)}get badge(){return this.getAttribute("badge")??""}set badge(t){this._reflect("badge",t)}get tag(){return this.getAttribute("tag")??""}set tag(t){this._reflect("tag",t)}get lang(){return this.getAttribute("lang")??""}set lang(t){this._reflect("lang",t)}get dir(){return this.getAttribute("dir")??""}set dir(t){this._reflect("dir",t)}get requireInteraction(){return this.hasAttribute("require-interaction")}set requireInteraction(t){this._reflectBool("require-interaction",t)}get silent(){return this.hasAttribute("silent")}set silent(t){this._reflectBool("silent",t)}get renotify(){return this.hasAttribute("renotify")}set renotify(t){this._reflectBool("renotify",t)}get manual(){return this.hasAttribute("manual")}set manual(t){this._reflectBool("manual",t)}get notice(){return this._notice}set notice(t){if(null==t)return;if(this.manual)return;const e=String(t);e!==this._notice&&(this._notice=e,this.notify(e))}get permission(){return this._core.permission}get granted(){return this._core.granted}get denied(){return this._core.denied}get prompt(){return this._core.prompt}get unsupported(){return this._core.unsupported}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get clicked(){return this._core.clicked}get closed(){return this._core.closed}get shown(){return this._core.shown}get connectedCallbackPromise(){return this._connectedCallbackPromise}request(){return this._core.request()}notify(t,e){return this._core.notify(t,{...this._options(),...e??{}})}close(t){this._core.close(t)}closeAll(){this._core.closeAll()}_reflect(t,e){null==e?this.removeAttribute(t):this.setAttribute(t,String(e))}_reflectBool(t,e){e?this.setAttribute(t,""):this.removeAttribute(t)}_options(){const t={};return""!==this.body&&(t.body=this.body),""!==this.icon&&(t.icon=this.icon),""!==this.badge&&(t.badge=this.badge),""!==this.tag&&(t.tag=this.tag),""!==this.lang&&(t.lang=this.lang),"auto"!==this.dir&&"ltr"!==this.dir&&"rtl"!==this.dir||(t.dir=this.dir),this.requireInteraction&&(t.requireInteraction=!0),this.silent&&(t.silent=!0),this.renotify&&(t.renotify=!0),t}connectedCallback(){!function(t){const e=t.constructor?.wcBindable,s=e?.inputs;if(void 0!==s)for(const e of s){const s=e.name;if(!Object.prototype.hasOwnProperty.call(t,s))continue;if(!l(t,s))continue;const i=t,r=i[s];delete i[s],i[s]=r}}(this),this.style.display="none",c||(c=!0,document.addEventListener("click",h)),this._connectedCallbackPromise=this._core.observe(this.mode)}disconnectedCallback(){this._core.dispose()}}customElements.get(t.tagNames.notify)||customElements.define(t.tagNames.notify,u);
2
+ //# sourceMappingURL=auto.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto.min.js","sources":["../src/config.ts","../src/core/notificationCapabilities.ts","../src/core/NotificationCore.ts","../src/autoTrigger.ts","../src/protocol/upgradeProperties.ts","../src/components/Notify.ts","../src/registerComponents.ts"],"sourcesContent":["import { IConfig, IWritableConfig } from \"./types.js\";\n\ninterface IInternalConfig extends IConfig {\n autoTrigger: boolean;\n triggerAttribute: string;\n tagNames: {\n notify: string;\n };\n}\n\nconst _config: IInternalConfig = {\n autoTrigger: true,\n triggerAttribute: \"data-notifytarget\",\n tagNames: {\n notify: \"wcs-notify\",\n },\n};\n\nfunction deepFreeze<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") return obj;\n Object.freeze(obj);\n for (const key of Object.keys(obj)) {\n deepFreeze((obj as Record<string, unknown>)[key]);\n }\n return obj;\n}\n\nfunction deepClone<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") return obj;\n const clone: Record<string, unknown> = {};\n for (const key of Object.keys(obj)) {\n clone[key] = deepClone((obj as Record<string, unknown>)[key]);\n }\n return clone as T;\n}\n\nlet frozenConfig: IConfig | null = null;\n\n// Internal, mutable live config used by the components/autoTrigger (they read it\n// at call time so setConfig() takes effect without re-import). Typed as the\n// readonly IConfig at the export boundary — the `as IConfig` is a compile-time\n// view only and does NOT freeze the object, so this export must stay\n// package-internal (it is not re-exported from exports.ts). Public consumers get\n// the deep-frozen clone from getConfig() instead.\nexport const config: IConfig = _config as IConfig;\n\nexport function getConfig(): IConfig {\n if (!frozenConfig) {\n frozenConfig = deepFreeze(deepClone(_config));\n }\n return frozenConfig;\n}\n\nexport function setConfig(partialConfig: IWritableConfig): void {\n if (typeof partialConfig.autoTrigger === \"boolean\") {\n _config.autoTrigger = partialConfig.autoTrigger;\n }\n if (typeof partialConfig.triggerAttribute === \"string\") {\n _config.triggerAttribute = partialConfig.triggerAttribute;\n }\n if (partialConfig.tagNames) {\n Object.assign(_config.tagNames, partialConfig.tagNames);\n }\n frozenConfig = null;\n}\n","/**\n * notificationCapabilities.ts\n *\n * Notification node 固有の error code(taxonomy)と derivation。汎用の error info 型は\n * `./platformCapability.js`(/io-core/ から copy-distribution される生成ファイル)から\n * import する。notification は監視(permission)と操作(notify/close)を 1 タグに併せ持つが、\n * 競合する非同期 operation の lane は持たない(show は最新値で上書きされる momentary な\n * 送出)ため、lane は採用せず error taxonomy(errorInfo)のみを追加する。\n *\n * sensor family と異なり、NotificationCore の error detail の `.error` は既に安定コード\n * (`this._err(code, message)` が産出する `\"unsupported\"` / `\"not-granted\"` /\n * `\"invalid-title\"` / `\"show-failed\"` / `\"no-service-worker\"`)であり、Error.name ではない。\n * したがって derivation は `.error` コードを taxonomy に写すだけの純粋な map である。\n * 想定外のコードは防御的に `notify-error` へ畳む。\n */\n\nimport type { WcsIoErrorInfo } from \"./platformCapability.js\";\nimport type { WcsNotifyErrorDetail } from \"../types.js\";\n\n/** 安定した notification error code(taxonomy)。値は公開キーとして固定。 */\nexport const WCS_NOTIFY_ERROR_CODE = {\n /** Notifications API 非対応(`globalThis.Notification` 不在)。 */\n CapabilityMissing: \"capability-missing\",\n /** 権限が granted でない状態での notify()。 */\n NotAllowed: \"not-allowed\",\n /** notify() に非文字列 title が渡された。 */\n InvalidArgument: \"invalid-argument\",\n /** notification の生成 / 表示に失敗した(constructor 例外 / onerror / SW show reject)。 */\n ShowFailed: \"show-failed\",\n /** SW backend が必要だが `navigator.serviceWorker` が不在。 */\n NoServiceWorker: \"no-service-worker\",\n /** その他 / 想定外の error code に対する防御的 fallback。 */\n NotifyError: \"notify-error\",\n} as const;\n\n/**\n * notification の失敗を serializable な error taxonomy に写す。引数は\n * `wcs-notify:error` の detail(`{ error, message }`)そのもの。`.error` は\n * `NotificationCore._err()` が付与した安定コードで、Error.name ではない。\n *\n * - `\"unsupported\"` は開始前の能力欠如 → phase=\"probe\" / capability-missing。\n * - `\"not-granted\"` / `\"invalid-title\"` は show 手前の前提条件違反(権限・引数)→\n * phase=\"start\" / not-allowed・invalid-argument。\n * - `\"show-failed\"` は show 実行中の失敗 → phase=\"execute\" / show-failed。\n * - `\"no-service-worker\"` は SW backend 要求時の transport 欠如 → phase=\"execute\" /\n * no-service-worker。\n * - それ以外(未知コード)は防御的に phase=\"execute\" / notify-error。\n *\n * いずれも retry で自動回復しない(recoverable=false)。\n */\nexport function deriveNotifyErrorInfo(error: WcsNotifyErrorDetail): WcsIoErrorInfo {\n const { error: code, message } = error;\n switch (code) {\n case \"unsupported\":\n return { code: WCS_NOTIFY_ERROR_CODE.CapabilityMissing, phase: \"probe\", recoverable: false, message };\n case \"not-granted\":\n return { code: WCS_NOTIFY_ERROR_CODE.NotAllowed, phase: \"start\", recoverable: false, message };\n case \"invalid-title\":\n return { code: WCS_NOTIFY_ERROR_CODE.InvalidArgument, phase: \"start\", recoverable: false, message };\n case \"show-failed\":\n return { code: WCS_NOTIFY_ERROR_CODE.ShowFailed, phase: \"execute\", recoverable: false, message };\n case \"no-service-worker\":\n return { code: WCS_NOTIFY_ERROR_CODE.NoServiceWorker, phase: \"execute\", recoverable: false, message };\n default:\n return { code: WCS_NOTIFY_ERROR_CODE.NotifyError, phase: \"execute\", recoverable: false, message };\n }\n}\n","import {\n IWcBindable, NotifyBackend, NotifyOptions, NotificationPermissionRaw,\n PermissionStateOrUnsupported, WcsNotifyClickDetail, WcsNotifyErrorDetail,\n} from \"../types.js\";\nimport { WcsIoErrorInfo } from \"./platformCapability.js\";\nimport { deriveNotifyErrorInfo } from \"./notificationCapabilities.js\";\n\n// Wrapper stored in a notification's `data` so the Service Worker side (a\n// separate global scope with no access to this instance) can recover the\n// identity and the caller's payload. The constructor backend uses the same\n// wrapper for uniformity, and both paths unwrap it before emitting.\ninterface WcsNotifyData {\n __wcsId: string;\n payload: unknown;\n}\n\n// Message shape posted by `wireNotificationClicks()` (src/sw.ts) over both\n// BroadcastChannel and clients.postMessage. `id` is unique per click\n// (`tag#seq`), so the two transports delivering the *same* click de-dup, while\n// two genuine clicks on the same `tag` do not.\ninterface WcsNotifyInbound {\n __wcsNotify: true;\n id: string;\n tag: string;\n data: unknown;\n action: string;\n}\n\n/**\n * Headless desktop-notification primitive. A thin, framework-agnostic wrapper\n * around the Notifications API exposed through the wc-bindable protocol.\n *\n * Unlike `@wcstack/permission` (a read-only monitor — the Permissions API has no\n * `request()`), the Notifications API *does* expose `Notification.requestPermission()`,\n * so this node is self-contained: it both **requests/monitors** the permission and\n * **shows** notifications. It is the first @wcstack node where the command-token\n * (show: `notify`) and event-token (`click` / `close` / `show`) directions both\n * live in one tag.\n *\n * - **request()** asks for the `notifications` permission (`Notification.requestPermission`).\n * - **notify(title, options)** shows a notification and returns its identifying tag\n * (a caller `options.tag`, or a generated `wcs-<n>`). It picks a backend per\n * `mode`: the `Notification` constructor (desktop) or\n * `ServiceWorkerRegistration.showNotification()` (mobile). `\"auto\"` prefers the\n * constructor and falls back to the SW on a `TypeError`.\n * - **close(tag) / closeAll()** dismiss notifications by tag / all.\n * - Clicks flow back as the `wcs-notify:click` event: directly via the\n * Notification's `onclick` (constructor), or via the SW helper's\n * BroadcastChannel/postMessage relay (SW). `permission` mirrors the live grant.\n *\n * Failures never throw: they surface through `error` (and the `unsupported`\n * permission state) so they flow into the declarative state.\n */\nexport class NotificationCore extends EventTarget {\n static wcBindable: IWcBindable = {\n protocol: \"wc-bindable\",\n version: 1,\n properties: [\n { name: \"permission\", event: \"wcs-notify:permission-change\", semantics: \"state\" },\n { name: \"granted\", event: \"wcs-notify:permission-change\", semantics: \"state\", getter: (e: Event) => (e as CustomEvent).detail === \"granted\" },\n { name: \"denied\", event: \"wcs-notify:permission-change\", semantics: \"state\", getter: (e: Event) => (e as CustomEvent).detail === \"denied\" },\n { name: \"prompt\", event: \"wcs-notify:permission-change\", semantics: \"state\", getter: (e: Event) => (e as CustomEvent).detail === \"prompt\" },\n { name: \"unsupported\", event: \"wcs-notify:permission-change\", semantics: \"state\", getter: (e: Event) => (e as CustomEvent).detail === \"unsupported\" },\n { name: \"error\", event: \"wcs-notify:error\", semantics: \"state\" },\n // Serializable failure taxonomy (stable code / phase / recoverable), or null.\n // Additive bindable output derived from `error.error` (the stable code the\n // Core's `_err()` already produces); the existing `error` property/event are\n // unchanged. Fires wcs-notify:error-info-changed. No lane — show is a\n // momentary, last-value-wins send, not a competing async operation.\n { name: \"errorInfo\", event: \"wcs-notify:error-info-changed\", semantics: \"state\" },\n { name: \"clicked\", event: \"wcs-notify:click\", semantics: \"event\", getter: (e: Event) => (e as CustomEvent).detail },\n { name: \"closed\", event: \"wcs-notify:close\", semantics: \"event\", getter: (e: Event) => (e as CustomEvent).detail },\n { name: \"shown\", event: \"wcs-notify:show\", semantics: \"event\", getter: (e: Event) => (e as CustomEvent).detail },\n ],\n commands: [\n { name: \"request\", async: true },\n { name: \"notify\" },\n { name: \"close\" },\n { name: \"closeAll\" },\n ],\n };\n\n private _target: EventTarget;\n private _mode: NotifyBackend = \"auto\";\n\n private _permission: PermissionStateOrUnsupported = \"prompt\";\n private _error: WcsNotifyErrorDetail | null = null;\n private _errorInfo: WcsIoErrorInfo | null = null;\n private _lastClick: WcsNotifyClickDetail | null = null;\n private _lastClose: WcsNotifyClickDetail | null = null;\n private _lastShow: WcsNotifyClickDetail | null = null;\n\n // Live PermissionStatus (when the Permissions API can query `notifications`),\n // kept so its `change` listener can be removed on dispose().\n private _permissionStatus: PermissionStatus | null = null;\n // True once a permission subscription has been (or is being) established; reset\n // by dispose(). Guards observe() so a reconnect re-queries while a redundant\n // observe() on a live subscription does not.\n private _permissionSubscribed: boolean = false;\n\n // Monotonic id of the current lifecycle. Bumped by every observe() and by\n // dispose(). In-flight async work (permission query, SW show, inbound click)\n // captures it and bails if stale, so a query/click that resolves after a\n // disconnect — or after a rapid disconnect→reconnect — never mutates state or\n // dispatches on a torn-down element.\n private _gen: number = 0;\n\n // Resolves once the connect-time permission probe settles. The Shell exposes\n // this as connectedCallbackPromise so SSR can await it before snapshotting.\n private _ready: Promise<void> = Promise.resolve();\n\n // Counter for auto-assigned tags when the caller omits one.\n private _idSeq: number = 0;\n\n // Notifications created via the constructor backend, by tag, so close()/closeAll()\n // can dismiss them. The SW backend has no handle (showNotification returns void),\n // so its tags are tracked separately and closed via registration.getNotifications().\n private _constructed: Map<string, Notification> = new Map();\n private _swTags: Set<string> = new Set();\n\n // Click subscription handles (SW relay).\n private _channel: BroadcastChannel | null = null;\n private _serviceWorker: ServiceWorkerContainer | null = null;\n private _clicksSubscribed: boolean = false;\n // Per-click ids already handled, to de-dup the two relay transports. FIFO-capped\n // so a long session does not leak; the two transports always arrive in the same\n // tick, so a small cap is ample.\n private _seenIds: string[] = [];\n\n constructor(target?: EventTarget) {\n super();\n this._target = target ?? this;\n }\n\n get permission(): PermissionStateOrUnsupported {\n return this._permission;\n }\n\n get granted(): boolean {\n return this._permission === \"granted\";\n }\n\n get denied(): boolean {\n return this._permission === \"denied\";\n }\n\n get prompt(): boolean {\n return this._permission === \"prompt\";\n }\n\n get unsupported(): boolean {\n return this._permission === \"unsupported\";\n }\n\n get error(): WcsNotifyErrorDetail | null {\n return this._error;\n }\n\n /**\n * The last failure's serializable `WcsIoErrorInfo` (stable `code` / `phase` /\n * `recoverable`), or null. Additive wc-bindable property (event\n * `wcs-notify:error-info-changed`), derived from `error`; the existing `error`\n * property/event are unchanged.\n */\n get errorInfo(): WcsIoErrorInfo | null {\n return this._errorInfo;\n }\n\n get clicked(): WcsNotifyClickDetail | null {\n return this._lastClick;\n }\n\n get closed(): WcsNotifyClickDetail | null {\n return this._lastClose;\n }\n\n get shown(): WcsNotifyClickDetail | null {\n return this._lastShow;\n }\n\n /** Resolves once the current (or initial) permission probe settles. */\n get ready(): Promise<void> {\n return this._ready;\n }\n\n // --- State setters with event dispatch ---\n\n private _setPermission(state: PermissionStateOrUnsupported): void {\n if (this._permission === state) return;\n this._permission = state;\n this._target.dispatchEvent(new CustomEvent(\"wcs-notify:permission-change\", {\n detail: state,\n bubbles: true,\n }));\n }\n\n private _setError(error: WcsNotifyErrorDetail | null): void {\n if (this._error === error) return;\n this._error = error;\n // Keep the additive `errorInfo` taxonomy in sync with `error`: derive from the\n // stable error code (or null on clear). Fires before the `error` event so an\n // observer binding both sees the classification first, mirroring the io-node\n // family.\n this._commitErrorInfo(error === null ? null : deriveNotifyErrorInfo(error));\n this._target.dispatchEvent(new CustomEvent(\"wcs-notify:error\", {\n detail: error,\n bubbles: true,\n }));\n }\n\n // Called only from _setError (which already guards on error identity), so\n // errorInfo transitions exactly when error does — no separate guard needed here.\n private _commitErrorInfo(info: WcsIoErrorInfo | null): void {\n this._errorInfo = info;\n this._target.dispatchEvent(new CustomEvent(\"wcs-notify:error-info-changed\", {\n detail: info,\n bubbles: true,\n }));\n }\n\n private _emit(kind: \"click\" | \"close\" | \"show\", detail: WcsNotifyClickDetail): void {\n if (kind === \"click\") this._lastClick = detail;\n else if (kind === \"close\") this._lastClose = detail;\n else this._lastShow = detail;\n this._target.dispatchEvent(new CustomEvent(`wcs-notify:${kind}`, {\n detail,\n bubbles: true,\n }));\n }\n\n // --- Public API ---\n\n /**\n * Start observing the `notifications` permission and subscribing to Service\n * Worker click relays. `mode` selects the show backend (default `\"auto\"`).\n * Idempotent while already subscribed: it only updates the stored mode; to\n * restart, dispose() first. Returns a promise that resolves once the first\n * permission probe settles, for SSR.\n *\n * Headless callers must call observe() to begin; the Shell calls it from\n * connectedCallback once the element's attributes resolve.\n */\n observe(mode: NotifyBackend = \"auto\"): Promise<void> {\n this._mode = mode;\n if (!this._permissionSubscribed) {\n this._ready = this._initPermission();\n this._subscribeClicks();\n }\n return this._ready;\n }\n\n /**\n * Ask the user for the `notifications` permission. Resolves to the resulting\n * (normalized) permission state. Never throws: an unavailable API resolves to\n * `\"unsupported\"`.\n */\n async request(): Promise<PermissionStateOrUnsupported> {\n const api = this._api();\n if (!api || typeof api.requestPermission !== \"function\") {\n this._setPermission(\"unsupported\");\n return this._permission;\n }\n try {\n const result = await api.requestPermission();\n this._setPermission(this._normalize(result));\n } catch {\n // Some legacy engines may reject; keep the current state rather than throw.\n }\n return this._permission;\n }\n\n /**\n * Show a notification. Returns the identifying tag (the caller's `options.tag`,\n * or a generated `wcs-<n>` when omitted). Never throws: when the API is\n * unavailable or the permission is not granted it surfaces an `error` and\n * returns an empty string.\n */\n notify(title: string, options: NotifyOptions = {}): string {\n if (!this._api()) {\n this._setError(this._err(\"unsupported\", \"Notifications API is not available in this environment.\"));\n return \"\";\n }\n if (this._permission !== \"granted\") {\n this._setError(this._err(\"not-granted\", \"Notification permission is not granted; call request() first.\"));\n return \"\";\n }\n if (typeof title !== \"string\") {\n this._setError(this._err(\"invalid-title\", \"notify() requires a string title.\"));\n return \"\";\n }\n\n const tag = (typeof options.tag === \"string\" && options.tag !== \"\") ? options.tag : this._nextId();\n const payload = options.data;\n const data: WcsNotifyData = { __wcsId: tag, payload };\n const backendOptions: NotifyOptions = { ...options, tag, data };\n\n this._setError(null);\n this._show(title, backendOptions, tag, payload);\n return tag;\n }\n\n /** Dismiss the notification(s) with `tag` across both backends. */\n close(tag?: string): void {\n if (typeof tag !== \"string\" || tag === \"\") return;\n const n = this._constructed.get(tag);\n if (n) {\n n.close();\n this._constructed.delete(tag);\n }\n if (this._swTags.has(tag)) {\n this._closeSw(tag);\n this._swTags.delete(tag);\n }\n }\n\n /**\n * Dismiss every notification this instance has shown. Scoped to this instance's\n * own tags on both backends — the SW path closes each tracked tag individually\n * rather than enumerating the whole origin, so it never dismisses notifications\n * shown by another `<wcs-notify>` or by an unrelated code path.\n */\n closeAll(): void {\n for (const n of this._constructed.values()) {\n n.close();\n }\n this._constructed.clear();\n for (const tag of this._swTags) {\n this._closeSw(tag);\n }\n this._swTags.clear();\n }\n\n /**\n * Detach permission and click subscriptions. Open notifications are intentionally\n * **left on screen** (a notification outlives the page that posted it — that is\n * the point); use close()/closeAll() to dismiss. Call from the Shell's\n * disconnectedCallback. A later observe() resumes.\n */\n dispose(): void {\n this._permissionSubscribed = false;\n this._clicksSubscribed = false;\n this._gen++;\n if (this._permissionStatus) {\n this._permissionStatus.removeEventListener(\"change\", this._onPermissionChange);\n this._permissionStatus = null;\n }\n if (this._channel) {\n this._channel.removeEventListener(\"message\", this._onInbound);\n this._channel.close();\n this._channel = null;\n }\n if (this._serviceWorker) {\n this._serviceWorker.removeEventListener(\"message\", this._onInbound);\n this._serviceWorker = null;\n }\n }\n\n // --- Internal: permission ---\n\n private _initPermission(): Promise<void> {\n const api = this._api();\n if (!api) {\n this._setPermission(\"unsupported\");\n // Intentionally does NOT set _permissionSubscribed: there is no permission\n // listener to tear down, so a reconnect simply re-probes (idempotent — the\n // same-value guard suppresses any redundant dispatch and no listener is ever\n // attached). _subscribeClicks() is re-entered too, but its own\n // _clicksSubscribed guard short-circuits the second pass, so no transport is\n // double-subscribed. Mirrors @wcstack/permission's unsupported path.\n return Promise.resolve();\n }\n this._permissionSubscribed = true;\n // Prefer the Permissions API: it provides a live `change` event. Fall back to\n // the static `Notification.permission` when it is absent or rejects the\n // `notifications` descriptor.\n if (typeof navigator !== \"undefined\" && navigator.permissions && typeof navigator.permissions.query === \"function\") {\n const gen = ++this._gen;\n return navigator.permissions.query({ name: \"notifications\" }).then(\n (status) => {\n if (gen !== this._gen) return;\n this._permissionStatus = status;\n this._setPermission(this._normalize(status.state as NotificationPermissionRaw));\n status.addEventListener(\"change\", this._onPermissionChange);\n },\n () => {\n if (gen !== this._gen) return;\n // Permissions API rejected the `notifications` descriptor — fall back to\n // the static `Notification.permission` (api is in scope and non-null here).\n this._setPermission(this._normalize(api.permission));\n },\n );\n }\n // No Permissions API: read the static permission once (no live change events).\n this._setPermission(this._normalize(api.permission));\n return Promise.resolve();\n }\n\n private _onPermissionChange = (event: Event): void => {\n const status = event.target as PermissionStatus;\n this._setPermission(this._normalize(status.state as NotificationPermissionRaw));\n };\n\n // Normalize the Notifications API's `\"default\"` to `\"prompt\"` so this node shares\n // the four-value surface of @wcstack/permission. The Permissions API already\n // reports `\"prompt\"`, so it passes through unchanged.\n private _normalize(raw: NotificationPermissionRaw | string): PermissionStateOrUnsupported {\n if (raw === \"default\") return \"prompt\";\n if (raw === \"granted\" || raw === \"denied\" || raw === \"prompt\") return raw;\n return \"prompt\";\n }\n\n // --- Internal: showing ---\n\n private _show(title: string, options: NotifyOptions, tag: string, payload: unknown): void {\n if (this._mode === \"sw\") {\n this._showViaSw(title, options, tag, payload);\n return;\n }\n const handled = this._showViaConstructor(title, options, tag, payload);\n if (handled) return;\n // Constructor threw TypeError (e.g. mobile, where `new Notification` is illegal).\n if (this._mode === \"auto\") {\n this._showViaSw(title, options, tag, payload);\n } else {\n this._setError(this._err(\"show-failed\", \"new Notification() is not usable here and mode=\\\"constructor\\\" disallows the Service Worker fallback.\"));\n }\n }\n\n // Returns false only when the constructor threw a TypeError (the signal to fall\n // back to the SW backend); true when it showed or surfaced a non-TypeError error.\n private _showViaConstructor(title: string, options: NotifyOptions, tag: string, payload: unknown): boolean {\n const api = this._api()!;\n const gen = this._gen;\n let n: Notification;\n try {\n n = new api(title, options as NotificationOptions);\n } catch (e) {\n if (e instanceof TypeError) return false;\n this._setError(this._err(\"show-failed\", \"Failed to create the notification.\"));\n return true;\n }\n this._constructed.set(tag, n);\n n.onshow = (): void => {\n if (gen !== this._gen) return;\n this._emit(\"show\", { tag, data: payload, action: \"\" });\n };\n n.onclick = (): void => {\n if (gen !== this._gen) return;\n this._emit(\"click\", { tag, data: payload, action: \"\" });\n };\n n.onclose = (): void => {\n this._constructed.delete(tag);\n if (gen !== this._gen) return;\n this._emit(\"close\", { tag, data: payload, action: \"\" });\n };\n n.onerror = (): void => {\n if (gen !== this._gen) return;\n this._setError(this._err(\"show-failed\", \"The notification failed to display.\"));\n };\n return true;\n }\n\n private _showViaSw(title: string, options: NotifyOptions, tag: string, payload: unknown): void {\n const sw = navigator.serviceWorker as ServiceWorkerContainer | undefined;\n if (!sw) {\n this._setError(this._err(\"no-service-worker\", \"Service Worker is required to show this notification but is unavailable.\"));\n return;\n }\n const gen = this._gen;\n this._swTags.add(tag);\n // A notification deliberately outlives the page (see § dispose), so we do NOT\n // bail before showNotification on a stale gen — a notify() issued while\n // connected still shows. The stale-gen guards only suppress dispatching the\n // observable `show` / `error` back onto a torn-down element.\n sw.ready\n .then((registration) => registration.showNotification(title, options as NotificationOptions))\n .then(() => {\n if (gen !== this._gen) return;\n this._emit(\"show\", { tag, data: payload, action: \"\" });\n })\n .catch(() => {\n if (gen !== this._gen) return;\n this._setError(this._err(\"show-failed\", \"ServiceWorkerRegistration.showNotification() failed.\"));\n });\n }\n\n // Close the SW notification(s) carrying `tag`. Always scoped to a single tag —\n // both callers (close / closeAll) iterate their own tracked tags, so the whole\n // origin is never enumerated.\n private _closeSw(tag: string): void {\n const sw = navigator.serviceWorker as ServiceWorkerContainer | undefined;\n if (!sw) return;\n sw.ready.then((registration) => {\n return registration.getNotifications({ tag }).then((list) => {\n for (const n of list) n.close();\n });\n }).catch(() => {\n // Closing is best-effort; a failure to enumerate is not surfaced.\n });\n }\n\n // --- Internal: click relay (SW) ---\n\n private _subscribeClicks(): void {\n if (this._clicksSubscribed) return;\n this._clicksSubscribed = true;\n if (typeof BroadcastChannel === \"function\") {\n this._channel = new BroadcastChannel(\"wcs-notify\");\n this._channel.addEventListener(\"message\", this._onInbound);\n }\n const sw = navigator.serviceWorker as ServiceWorkerContainer | undefined;\n if (sw) {\n this._serviceWorker = sw;\n sw.addEventListener(\"message\", this._onInbound);\n }\n }\n\n private _onInbound = (event: Event): void => {\n const msg = (event as MessageEvent).data as WcsNotifyInbound | undefined;\n if (!msg || msg.__wcsNotify !== true) return;\n if (this._isDuplicate(msg.id)) return;\n this._emit(\"click\", { tag: msg.tag, data: this._unwrap(msg.data), action: msg.action });\n };\n\n private _isDuplicate(id: string): boolean {\n if (this._seenIds.includes(id)) return true;\n this._seenIds.push(id);\n if (this._seenIds.length > 50) this._seenIds.shift();\n return false;\n }\n\n private _unwrap(raw: unknown): unknown {\n if (raw !== null && typeof raw === \"object\" && \"__wcsId\" in raw) {\n return (raw as WcsNotifyData).payload;\n }\n return raw;\n }\n\n // --- Internal: misc ---\n\n // Resolve the global `Notification` constructor at call time (not cached) so\n // tests can install/remove it and so unsupported environments report correctly.\n private _api(): (typeof Notification) | undefined {\n const g = globalThis as unknown as { Notification?: typeof Notification };\n return typeof g.Notification === \"function\" ? g.Notification : undefined;\n }\n\n private _nextId(): string {\n return `wcs-${++this._idSeq}`;\n }\n\n private _err(error: string, message: string): WcsNotifyErrorDetail {\n return { error, message };\n }\n}\n","import { config } from \"./config.js\";\nimport type { WcsNotify } from \"./components/Notify.js\";\n\nlet registered = false;\n\nfunction handleClick(event: Event): void {\n const target = event.target;\n if (!(target instanceof Element)) return;\n\n // A misconfigured triggerAttribute (e.g. one with a space) makes the attribute\n // selector invalid and closest() throw SyntaxError; guard so a bad config\n // disables only this shortcut rather than killing every document click handler.\n let triggerElement: Element | null;\n try {\n triggerElement = target.closest<Element>(`[${config.triggerAttribute}]`);\n } catch {\n return;\n }\n if (!triggerElement) return;\n\n const notifyId = triggerElement.getAttribute(config.triggerAttribute);\n if (!notifyId) return;\n\n // Resolve the registered constructor at call time instead of importing Notify as\n // a value, avoiding a components/Notify.ts ⇄ autoTrigger.ts cycle\n // (Notify.connectedCallback() calls registerAutoTrigger()). instanceof against\n // the customElements registry keeps the same identity guarantee.\n const NotifyCtor = customElements.get(config.tagNames.notify);\n const notifyElement = document.getElementById(notifyId);\n if (!NotifyCtor || !(notifyElement instanceof NotifyCtor)) return;\n\n // The title comes from the trigger element: an explicit `data-notifytitle`\n // attribute wins, otherwise the element's trimmed text content. The body is an\n // optional `data-notifybody`. This keeps the click-driven shortcut declarative\n // without inventing a payload channel.\n const explicit = triggerElement.getAttribute(\"data-notifytitle\");\n // `Element.textContent` is spec-guaranteed non-null (only Document / DocumentType\n // nodes return null, never an Element), so the cast is sound and lets us avoid an\n // unreachable `?? \"\"` branch. `triggerElement` is always an Element here.\n const title = explicit !== null ? explicit : (triggerElement.textContent as string).trim();\n const body = triggerElement.getAttribute(\"data-notifybody\");\n\n (notifyElement as WcsNotify).notify(title, body !== null ? { body } : undefined);\n}\n\nexport function registerAutoTrigger(): void {\n if (registered) return;\n registered = true;\n document.addEventListener(\"click\", handleClick);\n}\n\nexport function unregisterAutoTrigger(): void {\n if (!registered) return;\n registered = false;\n document.removeEventListener(\"click\", handleClick);\n}\n","// ===========================================================================\n// AUTO-GENERATED FILE - DO NOT EDIT.\n// Generated from /protocol/upgrade-properties.ts by scripts/sync-protocol-types.mjs.\n// Run `node scripts/sync-protocol-types.mjs` after editing the source.\n// ===========================================================================\n\n// custom element の property upgrade — `static wcBindable.inputs` に宣言した入力のうち、\n// 要素が upgrade される前に代入された own データプロパティを取り込み直す。\n//\n// なぜ必要か:\n// 未定義タグの要素は素の HTMLElement なので、`el.url = \"...\"` は own データプロパティを作る。\n// upgrade 後にクラスの accessor が prototype へ入っても own プロパティが優先されるため、\n// setter は二度と呼ばれず、値は要素へ届かないまま消える(エラーも警告も出ない)。\n// 常にプロパティ代入を行う framework(Angular の `[prop]`、Lit の `.prop=`、\n// Solid の `prop:`、Vue の `.prop` 修飾子)× 遅延定義(autoloader / CDN / code-split)で\n// 常態的に起きる。docs/architecture-hardening/13-framework-adapter-binding-constraints.md §1.2。\n//\n// 安全側の判定:\n// own プロパティがあっても、prototype チェーンに accessor が無ければ「シャドウ」ではなく\n// その own プロパティ自体が正規の格納先なので触らない(public class field を壊さない)。\n//\n// SINGLE SOURCE OF TRUTH: edit only this file (/protocol/upgrade-properties.ts), then run\n// `node scripts/sync-protocol-types.mjs` to regenerate the per-package copies\n// (packages/<pkg>/src/protocol/upgradeProperties.ts). Those copies are generated — do not edit them.\nimport { IWcBindable } from \"./wcBindable.js\";\n\nfunction hasAccessorOnPrototype(target: object, name: string): boolean {\n let proto = Object.getPrototypeOf(target);\n while (proto !== null) {\n const descriptor = Object.getOwnPropertyDescriptor(proto, name);\n if (descriptor !== undefined) {\n return typeof descriptor.get === \"function\" || typeof descriptor.set === \"function\";\n }\n proto = Object.getPrototypeOf(proto);\n }\n return false;\n}\n\n/**\n * `connectedCallback` の先頭で呼ぶ。宣言済み input のうち upgrade 前の代入で\n * accessor をシャドウしている own プロパティを、delete → 再代入で setter に通し直す。\n *\n * - 冪等: 再代入は accessor を通るので own プロパティは残らず、2 回目以降は no-op。\n * - 宣言に `inputs` が無い要素、`wcBindable` を持たない要素では何もしない。\n * - 値の意味は変えない。今まで捨てられていた代入が届くようになる一方向の変化。\n */\nexport function upgradeProperties(element: object): void {\n const declaration = (element as { constructor?: { wcBindable?: IWcBindable } }).constructor?.wcBindable;\n const inputs = declaration?.inputs;\n if (inputs === undefined) return;\n for (const input of inputs) {\n const name = input.name;\n if (!Object.prototype.hasOwnProperty.call(element, name)) continue;\n if (!hasAccessorOnPrototype(element, name)) continue;\n const record = element as Record<string, unknown>;\n const value = record[name];\n delete record[name];\n record[name] = value;\n }\n}\n","import { config } from \"../config.js\";\nimport {\n IWcBindable, NotifyBackend, NotifyOptions, PermissionStateOrUnsupported,\n WcsNotifyClickDetail, WcsNotifyErrorDetail,\n} from \"../types.js\";\nimport { NotificationCore } from \"../core/NotificationCore.js\";\nimport { WcsIoErrorInfo } from \"../core/platformCapability.js\";\nimport { registerAutoTrigger } from \"../autoTrigger.js\";\nimport { upgradeProperties } from \"../protocol/upgradeProperties.js\";\n\n/**\n * `<wcs-notify>` — declarative desktop notifications. Wraps NotificationCore and\n * exposes both directions in one tag:\n *\n * - **`notice`** (reactive input): writing a *changed* value shows a notification,\n * suppressing same-value writes so it fires only when the bound source actually\n * changes. The imperative `notify` command instead shows on demand (even the\n * same text again). See `docs/notification-tag-design.md` § 2.\n * - **`request` / `notify` / `close` / `closeAll`** commands (state → element).\n * - per-notification options (`body` / `icon` / `badge` / `tag` / `lang` / `dir` /\n * `require-interaction` / `silent` / `renotify`) as mirrored attributes.\n * - `mode` selects the show backend (`auto` / `sw` / `constructor`).\n * - the Core's observable surface (permission / granted / … / error / clicked /\n * closed / shown) via delegated getters; clicked/closed/shown carry the\n * `{ tag, data, action }` payload for event-token wiring.\n */\nexport class WcsNotify extends HTMLElement {\n static hasConnectedCallbackPromise = true;\n static wcBindable: IWcBindable = {\n ...NotificationCore.wcBindable,\n // Shell-level settable surface. `notice` is a momentary reactive command-property\n // with no mirrored attribute (it carries dynamic text, not declarative config),\n // mirroring <wcs-speak>'s `say`. The rest mirror their HTML attributes idempotently.\n inputs: [\n { name: \"notice\" },\n { name: \"mode\", attribute: \"mode\" },\n { name: \"body\", attribute: \"body\" },\n { name: \"icon\", attribute: \"icon\" },\n { name: \"badge\", attribute: \"badge\" },\n { name: \"tag\", attribute: \"tag\" },\n { name: \"lang\", attribute: \"lang\" },\n { name: \"dir\", attribute: \"dir\" },\n { name: \"requireInteraction\", attribute: \"require-interaction\" },\n { name: \"silent\", attribute: \"silent\" },\n { name: \"renotify\", attribute: \"renotify\" },\n { name: \"manual\", attribute: \"manual\" },\n ],\n commands: NotificationCore.wcBindable.commands,\n };\n\n private _core: NotificationCore;\n private _notice: string = \"\";\n private _connectedCallbackPromise: Promise<void> = Promise.resolve();\n private _internals: ElementInternals | null = null;\n\n constructor() {\n super();\n this._core = new NotificationCore(this);\n this._internals = this._initInternals();\n this._wireStates({\n \"wcs-notify:permission-change\": (d) => ({\n granted: d === \"granted\", denied: d === \"denied\",\n prompt: d === \"prompt\", unsupported: d === \"unsupported\",\n }),\n \"wcs-notify:error\": (d) => ({ error: d != null }),\n });\n }\n\n // CSS state reflection (:state()) — debug-only snapshot getter. NOT part of\n // wc-bindable (not a bind target); see README \"CSS styling with :state()\".\n // MUST NOT return the live CustomStateSet (that would let callers write\n // states from outside, defeating the point of :state() being read-only).\n get debugStates(): string[] {\n return this._internals ? [...this._internals.states] : [];\n }\n\n private _initInternals(): ElementInternals | null {\n // never-throw (async-io-node-guidelines.md §3.6): attachInternals is absent\n // in happy-dom / older environments, and pre-125 Chromium rejects\n // non-dashed state names from states.add() (probed and discarded here).\n // Either case silently disables reflection — the component still works,\n // it just doesn't expose :state() selectors.\n try {\n if (typeof this.attachInternals !== \"function\") return null;\n const internals = this.attachInternals();\n internals.states.add(\"wcs-probe\");\n internals.states.delete(\"wcs-probe\");\n return internals;\n } catch {\n return null;\n }\n }\n\n private _wireStates(map: Record<string, (detail: any) => Record<string, boolean>>): void {\n if (this._internals === null) return;\n const states = this._internals.states;\n for (const [event, toStates] of Object.entries(map)) {\n this.addEventListener(event, (e) => {\n const debug = this.hasAttribute(\"debug-states\");\n for (const [name, on] of Object.entries(toStates((e as CustomEvent).detail))) {\n try {\n if (on) { states.add(name); } else { states.delete(name); }\n } catch { /* never-throw */ }\n if (debug) this.toggleAttribute(`data-wcs-state-${name}`, on);\n }\n });\n }\n }\n\n // --- Attribute accessors ---\n\n get mode(): NotifyBackend {\n const m = this.getAttribute(\"mode\");\n return (m === \"sw\" || m === \"constructor\") ? m : \"auto\";\n }\n\n set mode(value: NotifyBackend) {\n this.setAttribute(\"mode\", value);\n }\n\n get body(): string {\n return this.getAttribute(\"body\") ?? \"\";\n }\n\n set body(value: string | null) {\n this._reflect(\"body\", value);\n }\n\n get icon(): string {\n return this.getAttribute(\"icon\") ?? \"\";\n }\n\n set icon(value: string | null) {\n this._reflect(\"icon\", value);\n }\n\n get badge(): string {\n return this.getAttribute(\"badge\") ?? \"\";\n }\n\n set badge(value: string | null) {\n this._reflect(\"badge\", value);\n }\n\n get tag(): string {\n return this.getAttribute(\"tag\") ?? \"\";\n }\n\n set tag(value: string | null) {\n this._reflect(\"tag\", value);\n }\n\n // NOTE: `lang` and `dir` intentionally repurpose the standard HTMLElement IDL\n // attributes as per-notification options (forwarded to NotificationOptions).\n // This element is always display:none, so overriding their normal rendering\n // semantics has no visual effect — but be aware the values mean \"the\n // notification's language/direction\", not the host element's.\n get lang(): string {\n return this.getAttribute(\"lang\") ?? \"\";\n }\n\n set lang(value: string | null) {\n this._reflect(\"lang\", value);\n }\n\n get dir(): string {\n return this.getAttribute(\"dir\") ?? \"\";\n }\n\n set dir(value: string | null) {\n this._reflect(\"dir\", value);\n }\n\n get requireInteraction(): boolean {\n return this.hasAttribute(\"require-interaction\");\n }\n\n set requireInteraction(value: boolean) {\n this._reflectBool(\"require-interaction\", value);\n }\n\n get silent(): boolean {\n return this.hasAttribute(\"silent\");\n }\n\n set silent(value: boolean) {\n this._reflectBool(\"silent\", value);\n }\n\n get renotify(): boolean {\n return this.hasAttribute(\"renotify\");\n }\n\n set renotify(value: boolean) {\n this._reflectBool(\"renotify\", value);\n }\n\n get manual(): boolean {\n return this.hasAttribute(\"manual\");\n }\n\n set manual(value: boolean) {\n this._reflectBool(\"manual\", value);\n }\n\n // --- Reactive command-property ---\n\n get notice(): string {\n return this._notice;\n }\n\n set notice(value: string | null) {\n // Reactive: writing a new value shows it. `manual` mutes the path entirely\n // (the imperative `notify` command still works). A conforming binder never\n // delivers `undefined` (it skips the write), but a direct assignment can, so\n // normalize null/undefined to a no-op.\n if (value == null) return;\n if (this.manual) return;\n const v = String(value);\n // Same-value guard: only show when the bound source actually changes. To show\n // the same text again on demand, use the `notify` command instead. (This is\n // the only spam guard the package provides — see docs § 2-c; debounce is the\n // caller's job via a filter, e.g. `notice@x|debounce(1000)`.)\n if (v === this._notice) return;\n this._notice = v;\n this.notify(v);\n }\n\n // --- Core delegated getters ---\n\n get permission(): PermissionStateOrUnsupported {\n return this._core.permission;\n }\n\n get granted(): boolean {\n return this._core.granted;\n }\n\n get denied(): boolean {\n return this._core.denied;\n }\n\n get prompt(): boolean {\n return this._core.prompt;\n }\n\n get unsupported(): boolean {\n return this._core.unsupported;\n }\n\n get error(): WcsNotifyErrorDetail | null {\n return this._core.error;\n }\n\n get errorInfo(): WcsIoErrorInfo | null {\n return this._core.errorInfo;\n }\n\n get clicked(): WcsNotifyClickDetail | null {\n return this._core.clicked;\n }\n\n get closed(): WcsNotifyClickDetail | null {\n return this._core.closed;\n }\n\n get shown(): WcsNotifyClickDetail | null {\n return this._core.shown;\n }\n\n get connectedCallbackPromise(): Promise<void> {\n return this._connectedCallbackPromise;\n }\n\n // --- Commands ---\n\n request(): Promise<PermissionStateOrUnsupported> {\n return this._core.request();\n }\n\n notify(title: string, options?: NotifyOptions): string {\n // Explicit options (from a command-token emit) win per-key over the attribute\n // defaults, so `notify.emit(title, { body })` still picks up the element's icon.\n return this._core.notify(title, { ...this._options(), ...(options ?? {}) });\n }\n\n close(tag?: string): void {\n this._core.close(tag);\n }\n\n closeAll(): void {\n this._core.closeAll();\n }\n\n // --- Internal ---\n\n private _reflect(name: string, value: string | null): void {\n if (value == null) {\n this.removeAttribute(name);\n } else {\n this.setAttribute(name, String(value));\n }\n }\n\n private _reflectBool(name: string, value: boolean): void {\n if (value) {\n this.setAttribute(name, \"\");\n } else {\n this.removeAttribute(name);\n }\n }\n\n private _options(): NotifyOptions {\n const o: NotifyOptions = {};\n if (this.body !== \"\") o.body = this.body;\n if (this.icon !== \"\") o.icon = this.icon;\n if (this.badge !== \"\") o.badge = this.badge;\n if (this.tag !== \"\") o.tag = this.tag;\n if (this.lang !== \"\") o.lang = this.lang;\n if (this.dir === \"auto\" || this.dir === \"ltr\" || this.dir === \"rtl\") o.dir = this.dir;\n if (this.requireInteraction) o.requireInteraction = true;\n if (this.silent) o.silent = true;\n if (this.renotify) o.renotify = true;\n return o;\n }\n\n // --- Lifecycle ---\n\n connectedCallback(): void {\n // upgrade 前に代入された input を取り込み直す(doc 13 §1.2 / Phase A1)\n upgradeProperties(this);\n this.style.display = \"none\";\n if (config.autoTrigger) {\n registerAutoTrigger();\n }\n // Begin observing permission and subscribing to SW click relays (or revive\n // after a reconnect). The returned promise is held as connectedCallbackPromise\n // for SSR.\n this._connectedCallbackPromise = this._core.observe(this.mode);\n }\n\n disconnectedCallback(): void {\n // Detach subscriptions. Open notifications are left on screen (see Core docs);\n // call close()/closeAll() to dismiss.\n this._core.dispose();\n }\n}\n","import { WcsNotify } from \"./components/Notify.js\";\nimport { config } from \"./config.js\";\n\nexport function registerComponents(): void {\n if (!customElements.get(config.tagNames.notify)) {\n customElements.define(config.tagNames.notify, WcsNotify);\n }\n}\n"],"names":["config","autoTrigger","triggerAttribute","tagNames","notify","WCS_NOTIFY_ERROR_CODE","NotificationCore","EventTarget","static","protocol","version","properties","name","event","semantics","getter","e","detail","commands","async","_target","_mode","_permission","_error","_errorInfo","_lastClick","_lastClose","_lastShow","_permissionStatus","_permissionSubscribed","_gen","_ready","Promise","resolve","_idSeq","_constructed","Map","_swTags","Set","_channel","_serviceWorker","_clicksSubscribed","_seenIds","constructor","target","super","this","permission","granted","denied","prompt","unsupported","error","errorInfo","clicked","closed","shown","ready","_setPermission","state","dispatchEvent","CustomEvent","bubbles","_setError","_commitErrorInfo","code","message","phase","recoverable","deriveNotifyErrorInfo","info","_emit","kind","observe","mode","_initPermission","_subscribeClicks","request","api","_api","requestPermission","result","_normalize","title","options","_err","tag","_nextId","payload","data","__wcsId","backendOptions","_show","close","n","get","delete","has","_closeSw","closeAll","values","clear","dispose","removeEventListener","_onPermissionChange","_onInbound","navigator","permissions","query","gen","then","status","addEventListener","raw","_showViaSw","_showViaConstructor","TypeError","set","onshow","action","onclick","onclose","onerror","sw","serviceWorker","add","registration","showNotification","catch","getNotifications","list","BroadcastChannel","msg","__wcsNotify","_isDuplicate","id","_unwrap","includes","push","length","shift","g","globalThis","Notification","undefined","registered","handleClick","Element","triggerElement","closest","notifyId","getAttribute","NotifyCtor","customElements","notifyElement","document","getElementById","explicit","textContent","trim","body","hasAccessorOnPrototype","proto","Object","getPrototypeOf","descriptor","getOwnPropertyDescriptor","WcsNotify","HTMLElement","wcBindable","inputs","attribute","_core","_notice","_connectedCallbackPromise","_internals","_initInternals","_wireStates","d","debugStates","states","attachInternals","internals","map","toStates","entries","debug","hasAttribute","on","toggleAttribute","m","value","setAttribute","_reflect","icon","badge","lang","dir","requireInteraction","_reflectBool","silent","renotify","manual","notice","v","String","connectedCallbackPromise","_options","removeAttribute","o","connectedCallback","element","declaration","input","prototype","hasOwnProperty","call","record","upgradeProperties","style","display","disconnectedCallback","define"],"mappings":"AAUA,MAkCaA,EAlCoB,CAC/BC,aAAa,EACbC,iBAAkB,oBAClBC,SAAU,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Declarative desktop-notification component for Web Components. Framework-agnostic Notifications API wrapper via wc-bindable-protocol, with Service Worker support.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.esm.js",
package/dist/auto.js DELETED
@@ -1,3 +0,0 @@
1
- import { bootstrapNotification } from "./index.esm.js";
2
-
3
- bootstrapNotification();
@@ -1,2 +0,0 @@
1
- const t={autoTrigger:!0,triggerAttribute:"data-notifytarget",tagNames:{notify:"wcs-notify"}};function e(t){if(null===t||"object"!=typeof t)return t;Object.freeze(t);for(const s of Object.keys(t))e(t[s]);return t}function s(t){if(null===t||"object"!=typeof t)return t;const e={};for(const i of Object.keys(t))e[i]=s(t[i]);return e}let i=null;const r=t;function n(){return i||(i=e(s(t))),i}const o={CapabilityMissing:"capability-missing",NotAllowed:"not-allowed",InvalidArgument:"invalid-argument",ShowFailed:"show-failed",NoServiceWorker:"no-service-worker",NotifyError:"notify-error"};class a extends EventTarget{static wcBindable={protocol:"wc-bindable",version:1,properties:[{name:"permission",event:"wcs-notify:permission-change",semantics:"state"},{name:"granted",event:"wcs-notify:permission-change",semantics:"state",getter:t=>"granted"===t.detail},{name:"denied",event:"wcs-notify:permission-change",semantics:"state",getter:t=>"denied"===t.detail},{name:"prompt",event:"wcs-notify:permission-change",semantics:"state",getter:t=>"prompt"===t.detail},{name:"unsupported",event:"wcs-notify:permission-change",semantics:"state",getter:t=>"unsupported"===t.detail},{name:"error",event:"wcs-notify:error",semantics:"state"},{name:"errorInfo",event:"wcs-notify:error-info-changed",semantics:"state"},{name:"clicked",event:"wcs-notify:click",semantics:"event",getter:t=>t.detail},{name:"closed",event:"wcs-notify:close",semantics:"event",getter:t=>t.detail},{name:"shown",event:"wcs-notify:show",semantics:"event",getter:t=>t.detail}],commands:[{name:"request",async:!0},{name:"notify"},{name:"close"},{name:"closeAll"}]};_target;_mode="auto";_permission="prompt";_error=null;_errorInfo=null;_lastClick=null;_lastClose=null;_lastShow=null;_permissionStatus=null;_permissionSubscribed=!1;_gen=0;_ready=Promise.resolve();_idSeq=0;_constructed=new Map;_swTags=new Set;_channel=null;_serviceWorker=null;_clicksSubscribed=!1;_seenIds=[];constructor(t){super(),this._target=t??this}get permission(){return this._permission}get granted(){return"granted"===this._permission}get denied(){return"denied"===this._permission}get prompt(){return"prompt"===this._permission}get unsupported(){return"unsupported"===this._permission}get error(){return this._error}get errorInfo(){return this._errorInfo}get clicked(){return this._lastClick}get closed(){return this._lastClose}get shown(){return this._lastShow}get ready(){return this._ready}_setPermission(t){this._permission!==t&&(this._permission=t,this._target.dispatchEvent(new CustomEvent("wcs-notify:permission-change",{detail:t,bubbles:!0})))}_setError(t){this._error!==t&&(this._error=t,this._commitErrorInfo(null===t?null:function(t){const{error:e,message:s}=t;switch(e){case"unsupported":return{code:o.CapabilityMissing,phase:"probe",recoverable:!1,message:s};case"not-granted":return{code:o.NotAllowed,phase:"start",recoverable:!1,message:s};case"invalid-title":return{code:o.InvalidArgument,phase:"start",recoverable:!1,message:s};case"show-failed":return{code:o.ShowFailed,phase:"execute",recoverable:!1,message:s};case"no-service-worker":return{code:o.NoServiceWorker,phase:"execute",recoverable:!1,message:s};default:return{code:o.NotifyError,phase:"execute",recoverable:!1,message:s}}}(t)),this._target.dispatchEvent(new CustomEvent("wcs-notify:error",{detail:t,bubbles:!0})))}_commitErrorInfo(t){this._errorInfo=t,this._target.dispatchEvent(new CustomEvent("wcs-notify:error-info-changed",{detail:t,bubbles:!0}))}_emit(t,e){"click"===t?this._lastClick=e:"close"===t?this._lastClose=e:this._lastShow=e,this._target.dispatchEvent(new CustomEvent(`wcs-notify:${t}`,{detail:e,bubbles:!0}))}observe(t="auto"){return this._mode=t,this._permissionSubscribed||(this._ready=this._initPermission(),this._subscribeClicks()),this._ready}async request(){const t=this._api();if(!t||"function"!=typeof t.requestPermission)return this._setPermission("unsupported"),this._permission;try{const e=await t.requestPermission();this._setPermission(this._normalize(e))}catch{}return this._permission}notify(t,e={}){if(!this._api())return this._setError(this._err("unsupported","Notifications API is not available in this environment.")),"";if("granted"!==this._permission)return this._setError(this._err("not-granted","Notification permission is not granted; call request() first.")),"";if("string"!=typeof t)return this._setError(this._err("invalid-title","notify() requires a string title.")),"";const s="string"==typeof e.tag&&""!==e.tag?e.tag:this._nextId(),i=e.data,r={__wcsId:s,payload:i},n={...e,tag:s,data:r};return this._setError(null),this._show(t,n,s,i),s}close(t){if("string"!=typeof t||""===t)return;const e=this._constructed.get(t);e&&(e.close(),this._constructed.delete(t)),this._swTags.has(t)&&(this._closeSw(t),this._swTags.delete(t))}closeAll(){for(const t of this._constructed.values())t.close();this._constructed.clear();for(const t of this._swTags)this._closeSw(t);this._swTags.clear()}dispose(){this._permissionSubscribed=!1,this._clicksSubscribed=!1,this._gen++,this._permissionStatus&&(this._permissionStatus.removeEventListener("change",this._onPermissionChange),this._permissionStatus=null),this._channel&&(this._channel.removeEventListener("message",this._onInbound),this._channel.close(),this._channel=null),this._serviceWorker&&(this._serviceWorker.removeEventListener("message",this._onInbound),this._serviceWorker=null)}_initPermission(){const t=this._api();if(!t)return this._setPermission("unsupported"),Promise.resolve();if(this._permissionSubscribed=!0,"undefined"!=typeof navigator&&navigator.permissions&&"function"==typeof navigator.permissions.query){const e=++this._gen;return navigator.permissions.query({name:"notifications"}).then(t=>{e===this._gen&&(this._permissionStatus=t,this._setPermission(this._normalize(t.state)),t.addEventListener("change",this._onPermissionChange))},()=>{e===this._gen&&this._setPermission(this._normalize(t.permission))})}return this._setPermission(this._normalize(t.permission)),Promise.resolve()}_onPermissionChange=t=>{const e=t.target;this._setPermission(this._normalize(e.state))};_normalize(t){return"default"===t?"prompt":"granted"===t||"denied"===t||"prompt"===t?t:"prompt"}_show(t,e,s,i){if("sw"===this._mode)return void this._showViaSw(t,e,s,i);this._showViaConstructor(t,e,s,i)||("auto"===this._mode?this._showViaSw(t,e,s,i):this._setError(this._err("show-failed",'new Notification() is not usable here and mode="constructor" disallows the Service Worker fallback.')))}_showViaConstructor(t,e,s,i){const r=this._api(),n=this._gen;let o;try{o=new r(t,e)}catch(t){return!(t instanceof TypeError)&&(this._setError(this._err("show-failed","Failed to create the notification.")),!0)}return this._constructed.set(s,o),o.onshow=()=>{n===this._gen&&this._emit("show",{tag:s,data:i,action:""})},o.onclick=()=>{n===this._gen&&this._emit("click",{tag:s,data:i,action:""})},o.onclose=()=>{this._constructed.delete(s),n===this._gen&&this._emit("close",{tag:s,data:i,action:""})},o.onerror=()=>{n===this._gen&&this._setError(this._err("show-failed","The notification failed to display."))},!0}_showViaSw(t,e,s,i){const r=navigator.serviceWorker;if(!r)return void this._setError(this._err("no-service-worker","Service Worker is required to show this notification but is unavailable."));const n=this._gen;this._swTags.add(s),r.ready.then(s=>s.showNotification(t,e)).then(()=>{n===this._gen&&this._emit("show",{tag:s,data:i,action:""})}).catch(()=>{n===this._gen&&this._setError(this._err("show-failed","ServiceWorkerRegistration.showNotification() failed."))})}_closeSw(t){const e=navigator.serviceWorker;e&&e.ready.then(e=>e.getNotifications({tag:t}).then(t=>{for(const e of t)e.close()})).catch(()=>{})}_subscribeClicks(){if(this._clicksSubscribed)return;this._clicksSubscribed=!0,"function"==typeof BroadcastChannel&&(this._channel=new BroadcastChannel("wcs-notify"),this._channel.addEventListener("message",this._onInbound));const t=navigator.serviceWorker;t&&(this._serviceWorker=t,t.addEventListener("message",this._onInbound))}_onInbound=t=>{const e=t.data;e&&!0===e.__wcsNotify&&(this._isDuplicate(e.id)||this._emit("click",{tag:e.tag,data:this._unwrap(e.data),action:e.action}))};_isDuplicate(t){return!!this._seenIds.includes(t)||(this._seenIds.push(t),this._seenIds.length>50&&this._seenIds.shift(),!1)}_unwrap(t){return null!==t&&"object"==typeof t&&"__wcsId"in t?t.payload:t}_api(){const t=globalThis;return"function"==typeof t.Notification?t.Notification:void 0}_nextId(){return"wcs-"+ ++this._idSeq}_err(t,e){return{error:t,message:e}}}let c=!1;function h(t){const e=t.target;if(!(e instanceof Element))return;let s;try{s=e.closest(`[${r.triggerAttribute}]`)}catch{return}if(!s)return;const i=s.getAttribute(r.triggerAttribute);if(!i)return;const n=customElements.get(r.tagNames.notify),o=document.getElementById(i);if(!(n&&o instanceof n))return;const a=s.getAttribute("data-notifytitle"),c=null!==a?a:s.textContent.trim(),h=s.getAttribute("data-notifybody");o.notify(c,null!==h?{body:h}:void 0)}function l(t,e){let s=Object.getPrototypeOf(t);for(;null!==s;){const t=Object.getOwnPropertyDescriptor(s,e);if(void 0!==t)return"function"==typeof t.get||"function"==typeof t.set;s=Object.getPrototypeOf(s)}return!1}class u extends HTMLElement{static hasConnectedCallbackPromise=!0;static wcBindable={...a.wcBindable,inputs:[{name:"notice"},{name:"mode",attribute:"mode"},{name:"body",attribute:"body"},{name:"icon",attribute:"icon"},{name:"badge",attribute:"badge"},{name:"tag",attribute:"tag"},{name:"lang",attribute:"lang"},{name:"dir",attribute:"dir"},{name:"requireInteraction",attribute:"require-interaction"},{name:"silent",attribute:"silent"},{name:"renotify",attribute:"renotify"},{name:"manual",attribute:"manual"}],commands:a.wcBindable.commands};_core;_notice="";_connectedCallbackPromise=Promise.resolve();_internals=null;constructor(){super(),this._core=new a(this),this._internals=this._initInternals(),this._wireStates({"wcs-notify:permission-change":t=>({granted:"granted"===t,denied:"denied"===t,prompt:"prompt"===t,unsupported:"unsupported"===t}),"wcs-notify:error":t=>({error:null!=t})})}get debugStates(){return this._internals?[...this._internals.states]:[]}_initInternals(){try{if("function"!=typeof this.attachInternals)return null;const t=this.attachInternals();return t.states.add("wcs-probe"),t.states.delete("wcs-probe"),t}catch{return null}}_wireStates(t){if(null===this._internals)return;const e=this._internals.states;for(const[s,i]of Object.entries(t))this.addEventListener(s,t=>{const s=this.hasAttribute("debug-states");for(const[r,n]of Object.entries(i(t.detail))){try{n?e.add(r):e.delete(r)}catch{}s&&this.toggleAttribute(`data-wcs-state-${r}`,n)}})}get mode(){const t=this.getAttribute("mode");return"sw"===t||"constructor"===t?t:"auto"}set mode(t){this.setAttribute("mode",t)}get body(){return this.getAttribute("body")??""}set body(t){this._reflect("body",t)}get icon(){return this.getAttribute("icon")??""}set icon(t){this._reflect("icon",t)}get badge(){return this.getAttribute("badge")??""}set badge(t){this._reflect("badge",t)}get tag(){return this.getAttribute("tag")??""}set tag(t){this._reflect("tag",t)}get lang(){return this.getAttribute("lang")??""}set lang(t){this._reflect("lang",t)}get dir(){return this.getAttribute("dir")??""}set dir(t){this._reflect("dir",t)}get requireInteraction(){return this.hasAttribute("require-interaction")}set requireInteraction(t){this._reflectBool("require-interaction",t)}get silent(){return this.hasAttribute("silent")}set silent(t){this._reflectBool("silent",t)}get renotify(){return this.hasAttribute("renotify")}set renotify(t){this._reflectBool("renotify",t)}get manual(){return this.hasAttribute("manual")}set manual(t){this._reflectBool("manual",t)}get notice(){return this._notice}set notice(t){if(null==t)return;if(this.manual)return;const e=String(t);e!==this._notice&&(this._notice=e,this.notify(e))}get permission(){return this._core.permission}get granted(){return this._core.granted}get denied(){return this._core.denied}get prompt(){return this._core.prompt}get unsupported(){return this._core.unsupported}get error(){return this._core.error}get errorInfo(){return this._core.errorInfo}get clicked(){return this._core.clicked}get closed(){return this._core.closed}get shown(){return this._core.shown}get connectedCallbackPromise(){return this._connectedCallbackPromise}request(){return this._core.request()}notify(t,e){return this._core.notify(t,{...this._options(),...e??{}})}close(t){this._core.close(t)}closeAll(){this._core.closeAll()}_reflect(t,e){null==e?this.removeAttribute(t):this.setAttribute(t,String(e))}_reflectBool(t,e){e?this.setAttribute(t,""):this.removeAttribute(t)}_options(){const t={};return""!==this.body&&(t.body=this.body),""!==this.icon&&(t.icon=this.icon),""!==this.badge&&(t.badge=this.badge),""!==this.tag&&(t.tag=this.tag),""!==this.lang&&(t.lang=this.lang),"auto"!==this.dir&&"ltr"!==this.dir&&"rtl"!==this.dir||(t.dir=this.dir),this.requireInteraction&&(t.requireInteraction=!0),this.silent&&(t.silent=!0),this.renotify&&(t.renotify=!0),t}connectedCallback(){!function(t){const e=t.constructor?.wcBindable,s=e?.inputs;if(void 0!==s)for(const e of s){const s=e.name;if(!Object.prototype.hasOwnProperty.call(t,s))continue;if(!l(t,s))continue;const i=t,r=i[s];delete i[s],i[s]=r}}(this),this.style.display="none",r.autoTrigger&&(c||(c=!0,document.addEventListener("click",h))),this._connectedCallbackPromise=this._core.observe(this.mode)}disconnectedCallback(){this._core.dispose()}}function d(e){var s;e&&("boolean"==typeof(s=e).autoTrigger&&(t.autoTrigger=s.autoTrigger),"string"==typeof s.triggerAttribute&&(t.triggerAttribute=s.triggerAttribute),s.tagNames&&Object.assign(t.tagNames,s.tagNames),i=null),customElements.get(r.tagNames.notify)||customElements.define(r.tagNames.notify,u)}export{a as NotificationCore,o as WCS_NOTIFY_ERROR_CODE,u as WcsNotify,d as bootstrapNotification,n as getConfig};
2
- //# sourceMappingURL=index.esm.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.esm.min.js","sources":["../src/config.ts","../src/core/notificationCapabilities.ts","../src/core/NotificationCore.ts","../src/autoTrigger.ts","../src/protocol/upgradeProperties.ts","../src/components/Notify.ts","../src/bootstrapNotification.ts","../src/registerComponents.ts"],"sourcesContent":["import { IConfig, IWritableConfig } from \"./types.js\";\n\ninterface IInternalConfig extends IConfig {\n autoTrigger: boolean;\n triggerAttribute: string;\n tagNames: {\n notify: string;\n };\n}\n\nconst _config: IInternalConfig = {\n autoTrigger: true,\n triggerAttribute: \"data-notifytarget\",\n tagNames: {\n notify: \"wcs-notify\",\n },\n};\n\nfunction deepFreeze<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") return obj;\n Object.freeze(obj);\n for (const key of Object.keys(obj)) {\n deepFreeze((obj as Record<string, unknown>)[key]);\n }\n return obj;\n}\n\nfunction deepClone<T>(obj: T): T {\n if (obj === null || typeof obj !== \"object\") return obj;\n const clone: Record<string, unknown> = {};\n for (const key of Object.keys(obj)) {\n clone[key] = deepClone((obj as Record<string, unknown>)[key]);\n }\n return clone as T;\n}\n\nlet frozenConfig: IConfig | null = null;\n\n// Internal, mutable live config used by the components/autoTrigger (they read it\n// at call time so setConfig() takes effect without re-import). Typed as the\n// readonly IConfig at the export boundary — the `as IConfig` is a compile-time\n// view only and does NOT freeze the object, so this export must stay\n// package-internal (it is not re-exported from exports.ts). Public consumers get\n// the deep-frozen clone from getConfig() instead.\nexport const config: IConfig = _config as IConfig;\n\nexport function getConfig(): IConfig {\n if (!frozenConfig) {\n frozenConfig = deepFreeze(deepClone(_config));\n }\n return frozenConfig;\n}\n\nexport function setConfig(partialConfig: IWritableConfig): void {\n if (typeof partialConfig.autoTrigger === \"boolean\") {\n _config.autoTrigger = partialConfig.autoTrigger;\n }\n if (typeof partialConfig.triggerAttribute === \"string\") {\n _config.triggerAttribute = partialConfig.triggerAttribute;\n }\n if (partialConfig.tagNames) {\n Object.assign(_config.tagNames, partialConfig.tagNames);\n }\n frozenConfig = null;\n}\n","/**\n * notificationCapabilities.ts\n *\n * Notification node 固有の error code(taxonomy)と derivation。汎用の error info 型は\n * `./platformCapability.js`(/io-core/ から copy-distribution される生成ファイル)から\n * import する。notification は監視(permission)と操作(notify/close)を 1 タグに併せ持つが、\n * 競合する非同期 operation の lane は持たない(show は最新値で上書きされる momentary な\n * 送出)ため、lane は採用せず error taxonomy(errorInfo)のみを追加する。\n *\n * sensor family と異なり、NotificationCore の error detail の `.error` は既に安定コード\n * (`this._err(code, message)` が産出する `\"unsupported\"` / `\"not-granted\"` /\n * `\"invalid-title\"` / `\"show-failed\"` / `\"no-service-worker\"`)であり、Error.name ではない。\n * したがって derivation は `.error` コードを taxonomy に写すだけの純粋な map である。\n * 想定外のコードは防御的に `notify-error` へ畳む。\n */\n\nimport type { WcsIoErrorInfo } from \"./platformCapability.js\";\nimport type { WcsNotifyErrorDetail } from \"../types.js\";\n\n/** 安定した notification error code(taxonomy)。値は公開キーとして固定。 */\nexport const WCS_NOTIFY_ERROR_CODE = {\n /** Notifications API 非対応(`globalThis.Notification` 不在)。 */\n CapabilityMissing: \"capability-missing\",\n /** 権限が granted でない状態での notify()。 */\n NotAllowed: \"not-allowed\",\n /** notify() に非文字列 title が渡された。 */\n InvalidArgument: \"invalid-argument\",\n /** notification の生成 / 表示に失敗した(constructor 例外 / onerror / SW show reject)。 */\n ShowFailed: \"show-failed\",\n /** SW backend が必要だが `navigator.serviceWorker` が不在。 */\n NoServiceWorker: \"no-service-worker\",\n /** その他 / 想定外の error code に対する防御的 fallback。 */\n NotifyError: \"notify-error\",\n} as const;\n\n/**\n * notification の失敗を serializable な error taxonomy に写す。引数は\n * `wcs-notify:error` の detail(`{ error, message }`)そのもの。`.error` は\n * `NotificationCore._err()` が付与した安定コードで、Error.name ではない。\n *\n * - `\"unsupported\"` は開始前の能力欠如 → phase=\"probe\" / capability-missing。\n * - `\"not-granted\"` / `\"invalid-title\"` は show 手前の前提条件違反(権限・引数)→\n * phase=\"start\" / not-allowed・invalid-argument。\n * - `\"show-failed\"` は show 実行中の失敗 → phase=\"execute\" / show-failed。\n * - `\"no-service-worker\"` は SW backend 要求時の transport 欠如 → phase=\"execute\" /\n * no-service-worker。\n * - それ以外(未知コード)は防御的に phase=\"execute\" / notify-error。\n *\n * いずれも retry で自動回復しない(recoverable=false)。\n */\nexport function deriveNotifyErrorInfo(error: WcsNotifyErrorDetail): WcsIoErrorInfo {\n const { error: code, message } = error;\n switch (code) {\n case \"unsupported\":\n return { code: WCS_NOTIFY_ERROR_CODE.CapabilityMissing, phase: \"probe\", recoverable: false, message };\n case \"not-granted\":\n return { code: WCS_NOTIFY_ERROR_CODE.NotAllowed, phase: \"start\", recoverable: false, message };\n case \"invalid-title\":\n return { code: WCS_NOTIFY_ERROR_CODE.InvalidArgument, phase: \"start\", recoverable: false, message };\n case \"show-failed\":\n return { code: WCS_NOTIFY_ERROR_CODE.ShowFailed, phase: \"execute\", recoverable: false, message };\n case \"no-service-worker\":\n return { code: WCS_NOTIFY_ERROR_CODE.NoServiceWorker, phase: \"execute\", recoverable: false, message };\n default:\n return { code: WCS_NOTIFY_ERROR_CODE.NotifyError, phase: \"execute\", recoverable: false, message };\n }\n}\n","import {\n IWcBindable, NotifyBackend, NotifyOptions, NotificationPermissionRaw,\n PermissionStateOrUnsupported, WcsNotifyClickDetail, WcsNotifyErrorDetail,\n} from \"../types.js\";\nimport { WcsIoErrorInfo } from \"./platformCapability.js\";\nimport { deriveNotifyErrorInfo } from \"./notificationCapabilities.js\";\n\n// Wrapper stored in a notification's `data` so the Service Worker side (a\n// separate global scope with no access to this instance) can recover the\n// identity and the caller's payload. The constructor backend uses the same\n// wrapper for uniformity, and both paths unwrap it before emitting.\ninterface WcsNotifyData {\n __wcsId: string;\n payload: unknown;\n}\n\n// Message shape posted by `wireNotificationClicks()` (src/sw.ts) over both\n// BroadcastChannel and clients.postMessage. `id` is unique per click\n// (`tag#seq`), so the two transports delivering the *same* click de-dup, while\n// two genuine clicks on the same `tag` do not.\ninterface WcsNotifyInbound {\n __wcsNotify: true;\n id: string;\n tag: string;\n data: unknown;\n action: string;\n}\n\n/**\n * Headless desktop-notification primitive. A thin, framework-agnostic wrapper\n * around the Notifications API exposed through the wc-bindable protocol.\n *\n * Unlike `@wcstack/permission` (a read-only monitor — the Permissions API has no\n * `request()`), the Notifications API *does* expose `Notification.requestPermission()`,\n * so this node is self-contained: it both **requests/monitors** the permission and\n * **shows** notifications. It is the first @wcstack node where the command-token\n * (show: `notify`) and event-token (`click` / `close` / `show`) directions both\n * live in one tag.\n *\n * - **request()** asks for the `notifications` permission (`Notification.requestPermission`).\n * - **notify(title, options)** shows a notification and returns its identifying tag\n * (a caller `options.tag`, or a generated `wcs-<n>`). It picks a backend per\n * `mode`: the `Notification` constructor (desktop) or\n * `ServiceWorkerRegistration.showNotification()` (mobile). `\"auto\"` prefers the\n * constructor and falls back to the SW on a `TypeError`.\n * - **close(tag) / closeAll()** dismiss notifications by tag / all.\n * - Clicks flow back as the `wcs-notify:click` event: directly via the\n * Notification's `onclick` (constructor), or via the SW helper's\n * BroadcastChannel/postMessage relay (SW). `permission` mirrors the live grant.\n *\n * Failures never throw: they surface through `error` (and the `unsupported`\n * permission state) so they flow into the declarative state.\n */\nexport class NotificationCore extends EventTarget {\n static wcBindable: IWcBindable = {\n protocol: \"wc-bindable\",\n version: 1,\n properties: [\n { name: \"permission\", event: \"wcs-notify:permission-change\", semantics: \"state\" },\n { name: \"granted\", event: \"wcs-notify:permission-change\", semantics: \"state\", getter: (e: Event) => (e as CustomEvent).detail === \"granted\" },\n { name: \"denied\", event: \"wcs-notify:permission-change\", semantics: \"state\", getter: (e: Event) => (e as CustomEvent).detail === \"denied\" },\n { name: \"prompt\", event: \"wcs-notify:permission-change\", semantics: \"state\", getter: (e: Event) => (e as CustomEvent).detail === \"prompt\" },\n { name: \"unsupported\", event: \"wcs-notify:permission-change\", semantics: \"state\", getter: (e: Event) => (e as CustomEvent).detail === \"unsupported\" },\n { name: \"error\", event: \"wcs-notify:error\", semantics: \"state\" },\n // Serializable failure taxonomy (stable code / phase / recoverable), or null.\n // Additive bindable output derived from `error.error` (the stable code the\n // Core's `_err()` already produces); the existing `error` property/event are\n // unchanged. Fires wcs-notify:error-info-changed. No lane — show is a\n // momentary, last-value-wins send, not a competing async operation.\n { name: \"errorInfo\", event: \"wcs-notify:error-info-changed\", semantics: \"state\" },\n { name: \"clicked\", event: \"wcs-notify:click\", semantics: \"event\", getter: (e: Event) => (e as CustomEvent).detail },\n { name: \"closed\", event: \"wcs-notify:close\", semantics: \"event\", getter: (e: Event) => (e as CustomEvent).detail },\n { name: \"shown\", event: \"wcs-notify:show\", semantics: \"event\", getter: (e: Event) => (e as CustomEvent).detail },\n ],\n commands: [\n { name: \"request\", async: true },\n { name: \"notify\" },\n { name: \"close\" },\n { name: \"closeAll\" },\n ],\n };\n\n private _target: EventTarget;\n private _mode: NotifyBackend = \"auto\";\n\n private _permission: PermissionStateOrUnsupported = \"prompt\";\n private _error: WcsNotifyErrorDetail | null = null;\n private _errorInfo: WcsIoErrorInfo | null = null;\n private _lastClick: WcsNotifyClickDetail | null = null;\n private _lastClose: WcsNotifyClickDetail | null = null;\n private _lastShow: WcsNotifyClickDetail | null = null;\n\n // Live PermissionStatus (when the Permissions API can query `notifications`),\n // kept so its `change` listener can be removed on dispose().\n private _permissionStatus: PermissionStatus | null = null;\n // True once a permission subscription has been (or is being) established; reset\n // by dispose(). Guards observe() so a reconnect re-queries while a redundant\n // observe() on a live subscription does not.\n private _permissionSubscribed: boolean = false;\n\n // Monotonic id of the current lifecycle. Bumped by every observe() and by\n // dispose(). In-flight async work (permission query, SW show, inbound click)\n // captures it and bails if stale, so a query/click that resolves after a\n // disconnect — or after a rapid disconnect→reconnect — never mutates state or\n // dispatches on a torn-down element.\n private _gen: number = 0;\n\n // Resolves once the connect-time permission probe settles. The Shell exposes\n // this as connectedCallbackPromise so SSR can await it before snapshotting.\n private _ready: Promise<void> = Promise.resolve();\n\n // Counter for auto-assigned tags when the caller omits one.\n private _idSeq: number = 0;\n\n // Notifications created via the constructor backend, by tag, so close()/closeAll()\n // can dismiss them. The SW backend has no handle (showNotification returns void),\n // so its tags are tracked separately and closed via registration.getNotifications().\n private _constructed: Map<string, Notification> = new Map();\n private _swTags: Set<string> = new Set();\n\n // Click subscription handles (SW relay).\n private _channel: BroadcastChannel | null = null;\n private _serviceWorker: ServiceWorkerContainer | null = null;\n private _clicksSubscribed: boolean = false;\n // Per-click ids already handled, to de-dup the two relay transports. FIFO-capped\n // so a long session does not leak; the two transports always arrive in the same\n // tick, so a small cap is ample.\n private _seenIds: string[] = [];\n\n constructor(target?: EventTarget) {\n super();\n this._target = target ?? this;\n }\n\n get permission(): PermissionStateOrUnsupported {\n return this._permission;\n }\n\n get granted(): boolean {\n return this._permission === \"granted\";\n }\n\n get denied(): boolean {\n return this._permission === \"denied\";\n }\n\n get prompt(): boolean {\n return this._permission === \"prompt\";\n }\n\n get unsupported(): boolean {\n return this._permission === \"unsupported\";\n }\n\n get error(): WcsNotifyErrorDetail | null {\n return this._error;\n }\n\n /**\n * The last failure's serializable `WcsIoErrorInfo` (stable `code` / `phase` /\n * `recoverable`), or null. Additive wc-bindable property (event\n * `wcs-notify:error-info-changed`), derived from `error`; the existing `error`\n * property/event are unchanged.\n */\n get errorInfo(): WcsIoErrorInfo | null {\n return this._errorInfo;\n }\n\n get clicked(): WcsNotifyClickDetail | null {\n return this._lastClick;\n }\n\n get closed(): WcsNotifyClickDetail | null {\n return this._lastClose;\n }\n\n get shown(): WcsNotifyClickDetail | null {\n return this._lastShow;\n }\n\n /** Resolves once the current (or initial) permission probe settles. */\n get ready(): Promise<void> {\n return this._ready;\n }\n\n // --- State setters with event dispatch ---\n\n private _setPermission(state: PermissionStateOrUnsupported): void {\n if (this._permission === state) return;\n this._permission = state;\n this._target.dispatchEvent(new CustomEvent(\"wcs-notify:permission-change\", {\n detail: state,\n bubbles: true,\n }));\n }\n\n private _setError(error: WcsNotifyErrorDetail | null): void {\n if (this._error === error) return;\n this._error = error;\n // Keep the additive `errorInfo` taxonomy in sync with `error`: derive from the\n // stable error code (or null on clear). Fires before the `error` event so an\n // observer binding both sees the classification first, mirroring the io-node\n // family.\n this._commitErrorInfo(error === null ? null : deriveNotifyErrorInfo(error));\n this._target.dispatchEvent(new CustomEvent(\"wcs-notify:error\", {\n detail: error,\n bubbles: true,\n }));\n }\n\n // Called only from _setError (which already guards on error identity), so\n // errorInfo transitions exactly when error does — no separate guard needed here.\n private _commitErrorInfo(info: WcsIoErrorInfo | null): void {\n this._errorInfo = info;\n this._target.dispatchEvent(new CustomEvent(\"wcs-notify:error-info-changed\", {\n detail: info,\n bubbles: true,\n }));\n }\n\n private _emit(kind: \"click\" | \"close\" | \"show\", detail: WcsNotifyClickDetail): void {\n if (kind === \"click\") this._lastClick = detail;\n else if (kind === \"close\") this._lastClose = detail;\n else this._lastShow = detail;\n this._target.dispatchEvent(new CustomEvent(`wcs-notify:${kind}`, {\n detail,\n bubbles: true,\n }));\n }\n\n // --- Public API ---\n\n /**\n * Start observing the `notifications` permission and subscribing to Service\n * Worker click relays. `mode` selects the show backend (default `\"auto\"`).\n * Idempotent while already subscribed: it only updates the stored mode; to\n * restart, dispose() first. Returns a promise that resolves once the first\n * permission probe settles, for SSR.\n *\n * Headless callers must call observe() to begin; the Shell calls it from\n * connectedCallback once the element's attributes resolve.\n */\n observe(mode: NotifyBackend = \"auto\"): Promise<void> {\n this._mode = mode;\n if (!this._permissionSubscribed) {\n this._ready = this._initPermission();\n this._subscribeClicks();\n }\n return this._ready;\n }\n\n /**\n * Ask the user for the `notifications` permission. Resolves to the resulting\n * (normalized) permission state. Never throws: an unavailable API resolves to\n * `\"unsupported\"`.\n */\n async request(): Promise<PermissionStateOrUnsupported> {\n const api = this._api();\n if (!api || typeof api.requestPermission !== \"function\") {\n this._setPermission(\"unsupported\");\n return this._permission;\n }\n try {\n const result = await api.requestPermission();\n this._setPermission(this._normalize(result));\n } catch {\n // Some legacy engines may reject; keep the current state rather than throw.\n }\n return this._permission;\n }\n\n /**\n * Show a notification. Returns the identifying tag (the caller's `options.tag`,\n * or a generated `wcs-<n>` when omitted). Never throws: when the API is\n * unavailable or the permission is not granted it surfaces an `error` and\n * returns an empty string.\n */\n notify(title: string, options: NotifyOptions = {}): string {\n if (!this._api()) {\n this._setError(this._err(\"unsupported\", \"Notifications API is not available in this environment.\"));\n return \"\";\n }\n if (this._permission !== \"granted\") {\n this._setError(this._err(\"not-granted\", \"Notification permission is not granted; call request() first.\"));\n return \"\";\n }\n if (typeof title !== \"string\") {\n this._setError(this._err(\"invalid-title\", \"notify() requires a string title.\"));\n return \"\";\n }\n\n const tag = (typeof options.tag === \"string\" && options.tag !== \"\") ? options.tag : this._nextId();\n const payload = options.data;\n const data: WcsNotifyData = { __wcsId: tag, payload };\n const backendOptions: NotifyOptions = { ...options, tag, data };\n\n this._setError(null);\n this._show(title, backendOptions, tag, payload);\n return tag;\n }\n\n /** Dismiss the notification(s) with `tag` across both backends. */\n close(tag?: string): void {\n if (typeof tag !== \"string\" || tag === \"\") return;\n const n = this._constructed.get(tag);\n if (n) {\n n.close();\n this._constructed.delete(tag);\n }\n if (this._swTags.has(tag)) {\n this._closeSw(tag);\n this._swTags.delete(tag);\n }\n }\n\n /**\n * Dismiss every notification this instance has shown. Scoped to this instance's\n * own tags on both backends — the SW path closes each tracked tag individually\n * rather than enumerating the whole origin, so it never dismisses notifications\n * shown by another `<wcs-notify>` or by an unrelated code path.\n */\n closeAll(): void {\n for (const n of this._constructed.values()) {\n n.close();\n }\n this._constructed.clear();\n for (const tag of this._swTags) {\n this._closeSw(tag);\n }\n this._swTags.clear();\n }\n\n /**\n * Detach permission and click subscriptions. Open notifications are intentionally\n * **left on screen** (a notification outlives the page that posted it — that is\n * the point); use close()/closeAll() to dismiss. Call from the Shell's\n * disconnectedCallback. A later observe() resumes.\n */\n dispose(): void {\n this._permissionSubscribed = false;\n this._clicksSubscribed = false;\n this._gen++;\n if (this._permissionStatus) {\n this._permissionStatus.removeEventListener(\"change\", this._onPermissionChange);\n this._permissionStatus = null;\n }\n if (this._channel) {\n this._channel.removeEventListener(\"message\", this._onInbound);\n this._channel.close();\n this._channel = null;\n }\n if (this._serviceWorker) {\n this._serviceWorker.removeEventListener(\"message\", this._onInbound);\n this._serviceWorker = null;\n }\n }\n\n // --- Internal: permission ---\n\n private _initPermission(): Promise<void> {\n const api = this._api();\n if (!api) {\n this._setPermission(\"unsupported\");\n // Intentionally does NOT set _permissionSubscribed: there is no permission\n // listener to tear down, so a reconnect simply re-probes (idempotent — the\n // same-value guard suppresses any redundant dispatch and no listener is ever\n // attached). _subscribeClicks() is re-entered too, but its own\n // _clicksSubscribed guard short-circuits the second pass, so no transport is\n // double-subscribed. Mirrors @wcstack/permission's unsupported path.\n return Promise.resolve();\n }\n this._permissionSubscribed = true;\n // Prefer the Permissions API: it provides a live `change` event. Fall back to\n // the static `Notification.permission` when it is absent or rejects the\n // `notifications` descriptor.\n if (typeof navigator !== \"undefined\" && navigator.permissions && typeof navigator.permissions.query === \"function\") {\n const gen = ++this._gen;\n return navigator.permissions.query({ name: \"notifications\" }).then(\n (status) => {\n if (gen !== this._gen) return;\n this._permissionStatus = status;\n this._setPermission(this._normalize(status.state as NotificationPermissionRaw));\n status.addEventListener(\"change\", this._onPermissionChange);\n },\n () => {\n if (gen !== this._gen) return;\n // Permissions API rejected the `notifications` descriptor — fall back to\n // the static `Notification.permission` (api is in scope and non-null here).\n this._setPermission(this._normalize(api.permission));\n },\n );\n }\n // No Permissions API: read the static permission once (no live change events).\n this._setPermission(this._normalize(api.permission));\n return Promise.resolve();\n }\n\n private _onPermissionChange = (event: Event): void => {\n const status = event.target as PermissionStatus;\n this._setPermission(this._normalize(status.state as NotificationPermissionRaw));\n };\n\n // Normalize the Notifications API's `\"default\"` to `\"prompt\"` so this node shares\n // the four-value surface of @wcstack/permission. The Permissions API already\n // reports `\"prompt\"`, so it passes through unchanged.\n private _normalize(raw: NotificationPermissionRaw | string): PermissionStateOrUnsupported {\n if (raw === \"default\") return \"prompt\";\n if (raw === \"granted\" || raw === \"denied\" || raw === \"prompt\") return raw;\n return \"prompt\";\n }\n\n // --- Internal: showing ---\n\n private _show(title: string, options: NotifyOptions, tag: string, payload: unknown): void {\n if (this._mode === \"sw\") {\n this._showViaSw(title, options, tag, payload);\n return;\n }\n const handled = this._showViaConstructor(title, options, tag, payload);\n if (handled) return;\n // Constructor threw TypeError (e.g. mobile, where `new Notification` is illegal).\n if (this._mode === \"auto\") {\n this._showViaSw(title, options, tag, payload);\n } else {\n this._setError(this._err(\"show-failed\", \"new Notification() is not usable here and mode=\\\"constructor\\\" disallows the Service Worker fallback.\"));\n }\n }\n\n // Returns false only when the constructor threw a TypeError (the signal to fall\n // back to the SW backend); true when it showed or surfaced a non-TypeError error.\n private _showViaConstructor(title: string, options: NotifyOptions, tag: string, payload: unknown): boolean {\n const api = this._api()!;\n const gen = this._gen;\n let n: Notification;\n try {\n n = new api(title, options as NotificationOptions);\n } catch (e) {\n if (e instanceof TypeError) return false;\n this._setError(this._err(\"show-failed\", \"Failed to create the notification.\"));\n return true;\n }\n this._constructed.set(tag, n);\n n.onshow = (): void => {\n if (gen !== this._gen) return;\n this._emit(\"show\", { tag, data: payload, action: \"\" });\n };\n n.onclick = (): void => {\n if (gen !== this._gen) return;\n this._emit(\"click\", { tag, data: payload, action: \"\" });\n };\n n.onclose = (): void => {\n this._constructed.delete(tag);\n if (gen !== this._gen) return;\n this._emit(\"close\", { tag, data: payload, action: \"\" });\n };\n n.onerror = (): void => {\n if (gen !== this._gen) return;\n this._setError(this._err(\"show-failed\", \"The notification failed to display.\"));\n };\n return true;\n }\n\n private _showViaSw(title: string, options: NotifyOptions, tag: string, payload: unknown): void {\n const sw = navigator.serviceWorker as ServiceWorkerContainer | undefined;\n if (!sw) {\n this._setError(this._err(\"no-service-worker\", \"Service Worker is required to show this notification but is unavailable.\"));\n return;\n }\n const gen = this._gen;\n this._swTags.add(tag);\n // A notification deliberately outlives the page (see § dispose), so we do NOT\n // bail before showNotification on a stale gen — a notify() issued while\n // connected still shows. The stale-gen guards only suppress dispatching the\n // observable `show` / `error` back onto a torn-down element.\n sw.ready\n .then((registration) => registration.showNotification(title, options as NotificationOptions))\n .then(() => {\n if (gen !== this._gen) return;\n this._emit(\"show\", { tag, data: payload, action: \"\" });\n })\n .catch(() => {\n if (gen !== this._gen) return;\n this._setError(this._err(\"show-failed\", \"ServiceWorkerRegistration.showNotification() failed.\"));\n });\n }\n\n // Close the SW notification(s) carrying `tag`. Always scoped to a single tag —\n // both callers (close / closeAll) iterate their own tracked tags, so the whole\n // origin is never enumerated.\n private _closeSw(tag: string): void {\n const sw = navigator.serviceWorker as ServiceWorkerContainer | undefined;\n if (!sw) return;\n sw.ready.then((registration) => {\n return registration.getNotifications({ tag }).then((list) => {\n for (const n of list) n.close();\n });\n }).catch(() => {\n // Closing is best-effort; a failure to enumerate is not surfaced.\n });\n }\n\n // --- Internal: click relay (SW) ---\n\n private _subscribeClicks(): void {\n if (this._clicksSubscribed) return;\n this._clicksSubscribed = true;\n if (typeof BroadcastChannel === \"function\") {\n this._channel = new BroadcastChannel(\"wcs-notify\");\n this._channel.addEventListener(\"message\", this._onInbound);\n }\n const sw = navigator.serviceWorker as ServiceWorkerContainer | undefined;\n if (sw) {\n this._serviceWorker = sw;\n sw.addEventListener(\"message\", this._onInbound);\n }\n }\n\n private _onInbound = (event: Event): void => {\n const msg = (event as MessageEvent).data as WcsNotifyInbound | undefined;\n if (!msg || msg.__wcsNotify !== true) return;\n if (this._isDuplicate(msg.id)) return;\n this._emit(\"click\", { tag: msg.tag, data: this._unwrap(msg.data), action: msg.action });\n };\n\n private _isDuplicate(id: string): boolean {\n if (this._seenIds.includes(id)) return true;\n this._seenIds.push(id);\n if (this._seenIds.length > 50) this._seenIds.shift();\n return false;\n }\n\n private _unwrap(raw: unknown): unknown {\n if (raw !== null && typeof raw === \"object\" && \"__wcsId\" in raw) {\n return (raw as WcsNotifyData).payload;\n }\n return raw;\n }\n\n // --- Internal: misc ---\n\n // Resolve the global `Notification` constructor at call time (not cached) so\n // tests can install/remove it and so unsupported environments report correctly.\n private _api(): (typeof Notification) | undefined {\n const g = globalThis as unknown as { Notification?: typeof Notification };\n return typeof g.Notification === \"function\" ? g.Notification : undefined;\n }\n\n private _nextId(): string {\n return `wcs-${++this._idSeq}`;\n }\n\n private _err(error: string, message: string): WcsNotifyErrorDetail {\n return { error, message };\n }\n}\n","import { config } from \"./config.js\";\nimport type { WcsNotify } from \"./components/Notify.js\";\n\nlet registered = false;\n\nfunction handleClick(event: Event): void {\n const target = event.target;\n if (!(target instanceof Element)) return;\n\n // A misconfigured triggerAttribute (e.g. one with a space) makes the attribute\n // selector invalid and closest() throw SyntaxError; guard so a bad config\n // disables only this shortcut rather than killing every document click handler.\n let triggerElement: Element | null;\n try {\n triggerElement = target.closest<Element>(`[${config.triggerAttribute}]`);\n } catch {\n return;\n }\n if (!triggerElement) return;\n\n const notifyId = triggerElement.getAttribute(config.triggerAttribute);\n if (!notifyId) return;\n\n // Resolve the registered constructor at call time instead of importing Notify as\n // a value, avoiding a components/Notify.ts ⇄ autoTrigger.ts cycle\n // (Notify.connectedCallback() calls registerAutoTrigger()). instanceof against\n // the customElements registry keeps the same identity guarantee.\n const NotifyCtor = customElements.get(config.tagNames.notify);\n const notifyElement = document.getElementById(notifyId);\n if (!NotifyCtor || !(notifyElement instanceof NotifyCtor)) return;\n\n // The title comes from the trigger element: an explicit `data-notifytitle`\n // attribute wins, otherwise the element's trimmed text content. The body is an\n // optional `data-notifybody`. This keeps the click-driven shortcut declarative\n // without inventing a payload channel.\n const explicit = triggerElement.getAttribute(\"data-notifytitle\");\n // `Element.textContent` is spec-guaranteed non-null (only Document / DocumentType\n // nodes return null, never an Element), so the cast is sound and lets us avoid an\n // unreachable `?? \"\"` branch. `triggerElement` is always an Element here.\n const title = explicit !== null ? explicit : (triggerElement.textContent as string).trim();\n const body = triggerElement.getAttribute(\"data-notifybody\");\n\n (notifyElement as WcsNotify).notify(title, body !== null ? { body } : undefined);\n}\n\nexport function registerAutoTrigger(): void {\n if (registered) return;\n registered = true;\n document.addEventListener(\"click\", handleClick);\n}\n\nexport function unregisterAutoTrigger(): void {\n if (!registered) return;\n registered = false;\n document.removeEventListener(\"click\", handleClick);\n}\n","// ===========================================================================\n// AUTO-GENERATED FILE - DO NOT EDIT.\n// Generated from /protocol/upgrade-properties.ts by scripts/sync-protocol-types.mjs.\n// Run `node scripts/sync-protocol-types.mjs` after editing the source.\n// ===========================================================================\n\n// custom element の property upgrade — `static wcBindable.inputs` に宣言した入力のうち、\n// 要素が upgrade される前に代入された own データプロパティを取り込み直す。\n//\n// なぜ必要か:\n// 未定義タグの要素は素の HTMLElement なので、`el.url = \"...\"` は own データプロパティを作る。\n// upgrade 後にクラスの accessor が prototype へ入っても own プロパティが優先されるため、\n// setter は二度と呼ばれず、値は要素へ届かないまま消える(エラーも警告も出ない)。\n// 常にプロパティ代入を行う framework(Angular の `[prop]`、Lit の `.prop=`、\n// Solid の `prop:`、Vue の `.prop` 修飾子)× 遅延定義(autoloader / CDN / code-split)で\n// 常態的に起きる。docs/architecture-hardening/13-framework-adapter-binding-constraints.md §1.2。\n//\n// 安全側の判定:\n// own プロパティがあっても、prototype チェーンに accessor が無ければ「シャドウ」ではなく\n// その own プロパティ自体が正規の格納先なので触らない(public class field を壊さない)。\n//\n// SINGLE SOURCE OF TRUTH: edit only this file (/protocol/upgrade-properties.ts), then run\n// `node scripts/sync-protocol-types.mjs` to regenerate the per-package copies\n// (packages/<pkg>/src/protocol/upgradeProperties.ts). Those copies are generated — do not edit them.\nimport { IWcBindable } from \"./wcBindable.js\";\n\nfunction hasAccessorOnPrototype(target: object, name: string): boolean {\n let proto = Object.getPrototypeOf(target);\n while (proto !== null) {\n const descriptor = Object.getOwnPropertyDescriptor(proto, name);\n if (descriptor !== undefined) {\n return typeof descriptor.get === \"function\" || typeof descriptor.set === \"function\";\n }\n proto = Object.getPrototypeOf(proto);\n }\n return false;\n}\n\n/**\n * `connectedCallback` の先頭で呼ぶ。宣言済み input のうち upgrade 前の代入で\n * accessor をシャドウしている own プロパティを、delete → 再代入で setter に通し直す。\n *\n * - 冪等: 再代入は accessor を通るので own プロパティは残らず、2 回目以降は no-op。\n * - 宣言に `inputs` が無い要素、`wcBindable` を持たない要素では何もしない。\n * - 値の意味は変えない。今まで捨てられていた代入が届くようになる一方向の変化。\n */\nexport function upgradeProperties(element: object): void {\n const declaration = (element as { constructor?: { wcBindable?: IWcBindable } }).constructor?.wcBindable;\n const inputs = declaration?.inputs;\n if (inputs === undefined) return;\n for (const input of inputs) {\n const name = input.name;\n if (!Object.prototype.hasOwnProperty.call(element, name)) continue;\n if (!hasAccessorOnPrototype(element, name)) continue;\n const record = element as Record<string, unknown>;\n const value = record[name];\n delete record[name];\n record[name] = value;\n }\n}\n","import { config } from \"../config.js\";\nimport {\n IWcBindable, NotifyBackend, NotifyOptions, PermissionStateOrUnsupported,\n WcsNotifyClickDetail, WcsNotifyErrorDetail,\n} from \"../types.js\";\nimport { NotificationCore } from \"../core/NotificationCore.js\";\nimport { WcsIoErrorInfo } from \"../core/platformCapability.js\";\nimport { registerAutoTrigger } from \"../autoTrigger.js\";\nimport { upgradeProperties } from \"../protocol/upgradeProperties.js\";\n\n/**\n * `<wcs-notify>` — declarative desktop notifications. Wraps NotificationCore and\n * exposes both directions in one tag:\n *\n * - **`notice`** (reactive input): writing a *changed* value shows a notification,\n * suppressing same-value writes so it fires only when the bound source actually\n * changes. The imperative `notify` command instead shows on demand (even the\n * same text again). See `docs/notification-tag-design.md` § 2.\n * - **`request` / `notify` / `close` / `closeAll`** commands (state → element).\n * - per-notification options (`body` / `icon` / `badge` / `tag` / `lang` / `dir` /\n * `require-interaction` / `silent` / `renotify`) as mirrored attributes.\n * - `mode` selects the show backend (`auto` / `sw` / `constructor`).\n * - the Core's observable surface (permission / granted / … / error / clicked /\n * closed / shown) via delegated getters; clicked/closed/shown carry the\n * `{ tag, data, action }` payload for event-token wiring.\n */\nexport class WcsNotify extends HTMLElement {\n static hasConnectedCallbackPromise = true;\n static wcBindable: IWcBindable = {\n ...NotificationCore.wcBindable,\n // Shell-level settable surface. `notice` is a momentary reactive command-property\n // with no mirrored attribute (it carries dynamic text, not declarative config),\n // mirroring <wcs-speak>'s `say`. The rest mirror their HTML attributes idempotently.\n inputs: [\n { name: \"notice\" },\n { name: \"mode\", attribute: \"mode\" },\n { name: \"body\", attribute: \"body\" },\n { name: \"icon\", attribute: \"icon\" },\n { name: \"badge\", attribute: \"badge\" },\n { name: \"tag\", attribute: \"tag\" },\n { name: \"lang\", attribute: \"lang\" },\n { name: \"dir\", attribute: \"dir\" },\n { name: \"requireInteraction\", attribute: \"require-interaction\" },\n { name: \"silent\", attribute: \"silent\" },\n { name: \"renotify\", attribute: \"renotify\" },\n { name: \"manual\", attribute: \"manual\" },\n ],\n commands: NotificationCore.wcBindable.commands,\n };\n\n private _core: NotificationCore;\n private _notice: string = \"\";\n private _connectedCallbackPromise: Promise<void> = Promise.resolve();\n private _internals: ElementInternals | null = null;\n\n constructor() {\n super();\n this._core = new NotificationCore(this);\n this._internals = this._initInternals();\n this._wireStates({\n \"wcs-notify:permission-change\": (d) => ({\n granted: d === \"granted\", denied: d === \"denied\",\n prompt: d === \"prompt\", unsupported: d === \"unsupported\",\n }),\n \"wcs-notify:error\": (d) => ({ error: d != null }),\n });\n }\n\n // CSS state reflection (:state()) — debug-only snapshot getter. NOT part of\n // wc-bindable (not a bind target); see README \"CSS styling with :state()\".\n // MUST NOT return the live CustomStateSet (that would let callers write\n // states from outside, defeating the point of :state() being read-only).\n get debugStates(): string[] {\n return this._internals ? [...this._internals.states] : [];\n }\n\n private _initInternals(): ElementInternals | null {\n // never-throw (async-io-node-guidelines.md §3.6): attachInternals is absent\n // in happy-dom / older environments, and pre-125 Chromium rejects\n // non-dashed state names from states.add() (probed and discarded here).\n // Either case silently disables reflection — the component still works,\n // it just doesn't expose :state() selectors.\n try {\n if (typeof this.attachInternals !== \"function\") return null;\n const internals = this.attachInternals();\n internals.states.add(\"wcs-probe\");\n internals.states.delete(\"wcs-probe\");\n return internals;\n } catch {\n return null;\n }\n }\n\n private _wireStates(map: Record<string, (detail: any) => Record<string, boolean>>): void {\n if (this._internals === null) return;\n const states = this._internals.states;\n for (const [event, toStates] of Object.entries(map)) {\n this.addEventListener(event, (e) => {\n const debug = this.hasAttribute(\"debug-states\");\n for (const [name, on] of Object.entries(toStates((e as CustomEvent).detail))) {\n try {\n if (on) { states.add(name); } else { states.delete(name); }\n } catch { /* never-throw */ }\n if (debug) this.toggleAttribute(`data-wcs-state-${name}`, on);\n }\n });\n }\n }\n\n // --- Attribute accessors ---\n\n get mode(): NotifyBackend {\n const m = this.getAttribute(\"mode\");\n return (m === \"sw\" || m === \"constructor\") ? m : \"auto\";\n }\n\n set mode(value: NotifyBackend) {\n this.setAttribute(\"mode\", value);\n }\n\n get body(): string {\n return this.getAttribute(\"body\") ?? \"\";\n }\n\n set body(value: string | null) {\n this._reflect(\"body\", value);\n }\n\n get icon(): string {\n return this.getAttribute(\"icon\") ?? \"\";\n }\n\n set icon(value: string | null) {\n this._reflect(\"icon\", value);\n }\n\n get badge(): string {\n return this.getAttribute(\"badge\") ?? \"\";\n }\n\n set badge(value: string | null) {\n this._reflect(\"badge\", value);\n }\n\n get tag(): string {\n return this.getAttribute(\"tag\") ?? \"\";\n }\n\n set tag(value: string | null) {\n this._reflect(\"tag\", value);\n }\n\n // NOTE: `lang` and `dir` intentionally repurpose the standard HTMLElement IDL\n // attributes as per-notification options (forwarded to NotificationOptions).\n // This element is always display:none, so overriding their normal rendering\n // semantics has no visual effect — but be aware the values mean \"the\n // notification's language/direction\", not the host element's.\n get lang(): string {\n return this.getAttribute(\"lang\") ?? \"\";\n }\n\n set lang(value: string | null) {\n this._reflect(\"lang\", value);\n }\n\n get dir(): string {\n return this.getAttribute(\"dir\") ?? \"\";\n }\n\n set dir(value: string | null) {\n this._reflect(\"dir\", value);\n }\n\n get requireInteraction(): boolean {\n return this.hasAttribute(\"require-interaction\");\n }\n\n set requireInteraction(value: boolean) {\n this._reflectBool(\"require-interaction\", value);\n }\n\n get silent(): boolean {\n return this.hasAttribute(\"silent\");\n }\n\n set silent(value: boolean) {\n this._reflectBool(\"silent\", value);\n }\n\n get renotify(): boolean {\n return this.hasAttribute(\"renotify\");\n }\n\n set renotify(value: boolean) {\n this._reflectBool(\"renotify\", value);\n }\n\n get manual(): boolean {\n return this.hasAttribute(\"manual\");\n }\n\n set manual(value: boolean) {\n this._reflectBool(\"manual\", value);\n }\n\n // --- Reactive command-property ---\n\n get notice(): string {\n return this._notice;\n }\n\n set notice(value: string | null) {\n // Reactive: writing a new value shows it. `manual` mutes the path entirely\n // (the imperative `notify` command still works). A conforming binder never\n // delivers `undefined` (it skips the write), but a direct assignment can, so\n // normalize null/undefined to a no-op.\n if (value == null) return;\n if (this.manual) return;\n const v = String(value);\n // Same-value guard: only show when the bound source actually changes. To show\n // the same text again on demand, use the `notify` command instead. (This is\n // the only spam guard the package provides — see docs § 2-c; debounce is the\n // caller's job via a filter, e.g. `notice@x|debounce(1000)`.)\n if (v === this._notice) return;\n this._notice = v;\n this.notify(v);\n }\n\n // --- Core delegated getters ---\n\n get permission(): PermissionStateOrUnsupported {\n return this._core.permission;\n }\n\n get granted(): boolean {\n return this._core.granted;\n }\n\n get denied(): boolean {\n return this._core.denied;\n }\n\n get prompt(): boolean {\n return this._core.prompt;\n }\n\n get unsupported(): boolean {\n return this._core.unsupported;\n }\n\n get error(): WcsNotifyErrorDetail | null {\n return this._core.error;\n }\n\n get errorInfo(): WcsIoErrorInfo | null {\n return this._core.errorInfo;\n }\n\n get clicked(): WcsNotifyClickDetail | null {\n return this._core.clicked;\n }\n\n get closed(): WcsNotifyClickDetail | null {\n return this._core.closed;\n }\n\n get shown(): WcsNotifyClickDetail | null {\n return this._core.shown;\n }\n\n get connectedCallbackPromise(): Promise<void> {\n return this._connectedCallbackPromise;\n }\n\n // --- Commands ---\n\n request(): Promise<PermissionStateOrUnsupported> {\n return this._core.request();\n }\n\n notify(title: string, options?: NotifyOptions): string {\n // Explicit options (from a command-token emit) win per-key over the attribute\n // defaults, so `notify.emit(title, { body })` still picks up the element's icon.\n return this._core.notify(title, { ...this._options(), ...(options ?? {}) });\n }\n\n close(tag?: string): void {\n this._core.close(tag);\n }\n\n closeAll(): void {\n this._core.closeAll();\n }\n\n // --- Internal ---\n\n private _reflect(name: string, value: string | null): void {\n if (value == null) {\n this.removeAttribute(name);\n } else {\n this.setAttribute(name, String(value));\n }\n }\n\n private _reflectBool(name: string, value: boolean): void {\n if (value) {\n this.setAttribute(name, \"\");\n } else {\n this.removeAttribute(name);\n }\n }\n\n private _options(): NotifyOptions {\n const o: NotifyOptions = {};\n if (this.body !== \"\") o.body = this.body;\n if (this.icon !== \"\") o.icon = this.icon;\n if (this.badge !== \"\") o.badge = this.badge;\n if (this.tag !== \"\") o.tag = this.tag;\n if (this.lang !== \"\") o.lang = this.lang;\n if (this.dir === \"auto\" || this.dir === \"ltr\" || this.dir === \"rtl\") o.dir = this.dir;\n if (this.requireInteraction) o.requireInteraction = true;\n if (this.silent) o.silent = true;\n if (this.renotify) o.renotify = true;\n return o;\n }\n\n // --- Lifecycle ---\n\n connectedCallback(): void {\n // upgrade 前に代入された input を取り込み直す(doc 13 §1.2 / Phase A1)\n upgradeProperties(this);\n this.style.display = \"none\";\n if (config.autoTrigger) {\n registerAutoTrigger();\n }\n // Begin observing permission and subscribing to SW click relays (or revive\n // after a reconnect). The returned promise is held as connectedCallbackPromise\n // for SSR.\n this._connectedCallbackPromise = this._core.observe(this.mode);\n }\n\n disconnectedCallback(): void {\n // Detach subscriptions. Open notifications are left on screen (see Core docs);\n // call close()/closeAll() to dismiss.\n this._core.dispose();\n }\n}\n","import { setConfig } from \"./config.js\";\nimport { registerComponents } from \"./registerComponents.js\";\nimport { IWritableConfig } from \"./types.js\";\n\nexport function bootstrapNotification(userConfig?: IWritableConfig): void {\n if (userConfig) {\n setConfig(userConfig);\n }\n registerComponents();\n}\n","import { WcsNotify } from \"./components/Notify.js\";\nimport { config } from \"./config.js\";\n\nexport function registerComponents(): void {\n if (!customElements.get(config.tagNames.notify)) {\n customElements.define(config.tagNames.notify, WcsNotify);\n }\n}\n"],"names":["_config","autoTrigger","triggerAttribute","tagNames","notify","deepFreeze","obj","Object","freeze","key","keys","deepClone","clone","frozenConfig","config","getConfig","WCS_NOTIFY_ERROR_CODE","CapabilityMissing","NotAllowed","InvalidArgument","ShowFailed","NoServiceWorker","NotifyError","NotificationCore","EventTarget","static","protocol","version","properties","name","event","semantics","getter","e","detail","commands","async","_target","_mode","_permission","_error","_errorInfo","_lastClick","_lastClose","_lastShow","_permissionStatus","_permissionSubscribed","_gen","_ready","Promise","resolve","_idSeq","_constructed","Map","_swTags","Set","_channel","_serviceWorker","_clicksSubscribed","_seenIds","constructor","target","super","this","permission","granted","denied","prompt","unsupported","error","errorInfo","clicked","closed","shown","ready","_setPermission","state","dispatchEvent","CustomEvent","bubbles","_setError","_commitErrorInfo","code","message","phase","recoverable","deriveNotifyErrorInfo","info","_emit","kind","observe","mode","_initPermission","_subscribeClicks","request","api","_api","requestPermission","result","_normalize","title","options","_err","tag","_nextId","payload","data","__wcsId","backendOptions","_show","close","n","get","delete","has","_closeSw","closeAll","values","clear","dispose","removeEventListener","_onPermissionChange","_onInbound","navigator","permissions","query","gen","then","status","addEventListener","raw","_showViaSw","_showViaConstructor","TypeError","set","onshow","action","onclick","onclose","onerror","sw","serviceWorker","add","registration","showNotification","catch","getNotifications","list","BroadcastChannel","msg","__wcsNotify","_isDuplicate","id","_unwrap","includes","push","length","shift","g","globalThis","Notification","undefined","registered","handleClick","Element","triggerElement","closest","notifyId","getAttribute","NotifyCtor","customElements","notifyElement","document","getElementById","explicit","textContent","trim","body","hasAccessorOnPrototype","proto","getPrototypeOf","descriptor","getOwnPropertyDescriptor","WcsNotify","HTMLElement","wcBindable","inputs","attribute","_core","_notice","_connectedCallbackPromise","_internals","_initInternals","_wireStates","d","debugStates","states","attachInternals","internals","map","toStates","entries","debug","hasAttribute","on","toggleAttribute","m","value","setAttribute","_reflect","icon","badge","lang","dir","requireInteraction","_reflectBool","silent","renotify","manual","notice","v","String","connectedCallbackPromise","_options","removeAttribute","o","connectedCallback","element","declaration","input","prototype","hasOwnProperty","call","record","upgradeProperties","style","display","disconnectedCallback","bootstrapNotification","userConfig","partialConfig","assign","define"],"mappings":"AAUA,MAAMA,EAA2B,CAC/BC,aAAa,EACbC,iBAAkB,oBAClBC,SAAU,CACRC,OAAQ,eAIZ,SAASC,EAAcC,GACrB,GAAY,OAARA,GAA+B,iBAARA,EAAkB,OAAOA,EACpDC,OAAOC,OAAOF,GACd,IAAK,MAAMG,KAAOF,OAAOG,KAAKJ,GAC5BD,EAAYC,EAAgCG,IAE9C,OAAOH,CACT,CAEA,SAASK,EAAaL,GACpB,GAAY,OAARA,GAA+B,iBAARA,EAAkB,OAAOA,EACpD,MAAMM,EAAiC,CAAA,EACvC,IAAK,MAAMH,KAAOF,OAAOG,KAAKJ,GAC5BM,EAAMH,GAAOE,EAAWL,EAAgCG,IAE1D,OAAOG,CACT,CAEA,IA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