@vibe-flags/core 0.1.2 → 0.1.3
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/vibe-flags.cdn.js +1 -1
- package/dist/vibe-flags.cdn.mjs +3 -3
- package/dist/vibe-flags.js +31 -31
- package/package.json +1 -1
package/dist/vibe-flags.cdn.js
CHANGED
|
@@ -28,7 +28,7 @@ var VibeFlags=(function(l){"use strict";/**
|
|
|
28
28
|
* @license
|
|
29
29
|
* Copyright 2017 Google LLC
|
|
30
30
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
31
|
-
*/function $(r){return S({...r,state:!0,attribute:!1})}var De=Object.getOwnPropertyDescriptor,ze=(r,e,t,s)=>{for(var i=s>1?void 0:s?De(e,t):e,o=r.length-1,n;o>=0;o--)(n=r[o])&&(i=n(i)||i);return i};l.VibeFlags=class extends v{render(){return g`<slot></slot>`}},l.VibeFlags=ze([U("vibe-flags")],l.VibeFlags);const N="vibe-flags:";function Q(r){return r.type==="boolean"?!1:r.options[0]||""}class Le extends EventTarget{constructor(){super(...arguments),this.configs=new Map,this.state={},this.listening=!1,this.onStorageEvent=e=>{if(!e.key?.startsWith(N))return;const t=e.key.slice(N.length),s=this.configs.get(t);if(s)try{const i=e.newValue?JSON.parse(e.newValue):Q(s);this.state[t]=i,this.dispatch(t)}catch{}}}register(e){this.configs.set(e.key,e);const t=this.readFromStorage(e.key);this.state[e.key]=t??Q(e),this.listening||(this.listening=!0,typeof window<"u"&&window.addEventListener("storage",this.onStorageEvent)),this.dispatch(e.key)}unregister(e){this.configs.delete(e),delete this.state[e],this.dispatch()}get(e){return this.state[e]}set(e,t){const s=this.configs.get(e);s&&(s.type==="boolean"&&typeof t!="boolean"||s.type==="select"&&(typeof t!="string"||!s.options.includes(t))||(this.state[e]=t,this.writeToStorage(e,t),this.dispatch(e)))}getAll(){return{...this.state}}getConfig(){return Array.from(this.configs.values())}getConfigForKey(e){return this.configs.get(e)}reset(){for(const[e,t]of this.configs)this.state[e]=Q(t),this.removeFromStorage(e);this.dispatch()}readFromStorage(e){if(typeof window>"u")return null;try{const t=localStorage.getItem(N+e);return t===null?null:JSON.parse(t)}catch{return null}}writeToStorage(e,t){if(!(typeof window>"u"))try{localStorage.setItem(N+e,JSON.stringify(t))}catch{}}removeFromStorage(e){if(!(typeof window>"u"))try{localStorage.removeItem(N+e)}catch{}}dispatch(e){const t={key:e,state:this.getAll()},s=new CustomEvent("vibe-flags-changed",{detail:t,bubbles:!0});this.dispatchEvent(s),typeof window<"u"&&window.dispatchEvent(new CustomEvent("vibe-flags-changed",{detail:t}))}}const u=new Le;var qe=Object.defineProperty,We=Object.getOwnPropertyDescriptor,k=(r,e,t,s)=>{for(var i=s>1?void 0:s?We(e,t):e,o=r.length-1,n;o>=0;o--)(n=r[o])&&(i=(s?n(e,t,i):n(i))||i);return s&&i&&qe(e,t,i),i};if(typeof document<"u"&&!document.getElementById("vibe-flag-fouc")){const r=document.createElement("style");r.id="vibe-flag-fouc",r.textContent="vibe-flag-boolean:not(:defined),vibe-flag-boolean:defined,vibe-flag-select:not(:defined),vibe-flag-select:defined,vibe-flag-option:not(:defined),vibe-flag-option:defined{
|
|
31
|
+
*/function $(r){return S({...r,state:!0,attribute:!1})}var De=Object.getOwnPropertyDescriptor,ze=(r,e,t,s)=>{for(var i=s>1?void 0:s?De(e,t):e,o=r.length-1,n;o>=0;o--)(n=r[o])&&(i=n(i)||i);return i};l.VibeFlags=class extends v{render(){return g`<slot></slot>`}},l.VibeFlags=ze([U("vibe-flags")],l.VibeFlags);const N="vibe-flags:";function Q(r){return r.type==="boolean"?!1:r.options[0]||""}class Le extends EventTarget{constructor(){super(...arguments),this.configs=new Map,this.state={},this.listening=!1,this.onStorageEvent=e=>{if(!e.key?.startsWith(N))return;const t=e.key.slice(N.length),s=this.configs.get(t);if(s)try{const i=e.newValue?JSON.parse(e.newValue):Q(s);this.state[t]=i,this.dispatch(t)}catch{}}}register(e){this.configs.set(e.key,e);const t=this.readFromStorage(e.key);this.state[e.key]=t??Q(e),this.listening||(this.listening=!0,typeof window<"u"&&window.addEventListener("storage",this.onStorageEvent)),this.dispatch(e.key)}unregister(e){this.configs.delete(e),delete this.state[e],this.dispatch()}get(e){return this.state[e]}set(e,t){const s=this.configs.get(e);s&&(s.type==="boolean"&&typeof t!="boolean"||s.type==="select"&&(typeof t!="string"||!s.options.includes(t))||(this.state[e]=t,this.writeToStorage(e,t),this.dispatch(e)))}getAll(){return{...this.state}}getConfig(){return Array.from(this.configs.values())}getConfigForKey(e){return this.configs.get(e)}reset(){for(const[e,t]of this.configs)this.state[e]=Q(t),this.removeFromStorage(e);this.dispatch()}readFromStorage(e){if(typeof window>"u")return null;try{const t=localStorage.getItem(N+e);return t===null?null:JSON.parse(t)}catch{return null}}writeToStorage(e,t){if(!(typeof window>"u"))try{localStorage.setItem(N+e,JSON.stringify(t))}catch{}}removeFromStorage(e){if(!(typeof window>"u"))try{localStorage.removeItem(N+e)}catch{}}dispatch(e){const t={key:e,state:this.getAll()},s=new CustomEvent("vibe-flags-changed",{detail:t,bubbles:!0});this.dispatchEvent(s),typeof window<"u"&&window.dispatchEvent(new CustomEvent("vibe-flags-changed",{detail:t}))}}const u=new Le;var qe=Object.defineProperty,We=Object.getOwnPropertyDescriptor,k=(r,e,t,s)=>{for(var i=s>1?void 0:s?We(e,t):e,o=r.length-1,n;o>=0;o--)(n=r[o])&&(i=(s?n(e,t,i):n(i))||i);return s&&i&&qe(e,t,i),i};if(typeof document<"u"&&!document.getElementById("vibe-flag-fouc")){const r=document.createElement("style");r.id="vibe-flag-fouc",r.textContent="vibe-flag-boolean:not(:defined),vibe-flag-boolean:defined,vibe-flag-select:not(:defined),vibe-flag-select:defined,vibe-flag-option:not(:defined),vibe-flag-option:defined{display:none}",document.head.appendChild(r)}l.VibeFlagBoolean=class extends v{constructor(){super(...arguments),this.name="",this.description="",this.value="",this.isMatch=!1,this.ready=!1,this.onFlagChange=()=>{this.evaluate()}}connectedCallback(){super.connectedCallback(),window.addEventListener("vibe-flags-changed",this.onFlagChange),this.registerFlag()}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("vibe-flags-changed",this.onFlagChange)}willUpdate(e){(e.has("name")||e.has("description"))&&this.registerFlag()}registerFlag(){this.name&&(u.getConfigForKey(this.name)||u.register({key:this.name,type:"boolean",label:this.description||void 0}),this.evaluate())}evaluate(){const e=u.get(this.name);e===void 0?this.isMatch=!1:this.value===""?this.isMatch=!0:this.isMatch=String(e)===this.value,this.ready||(this.ready=!0,this.style.display="contents")}render(){return this.isMatch?g`<slot></slot>`:d}},k([S({type:String})],l.VibeFlagBoolean.prototype,"name",2),k([S({type:String})],l.VibeFlagBoolean.prototype,"description",2),k([S({type:String})],l.VibeFlagBoolean.prototype,"value",2),k([$()],l.VibeFlagBoolean.prototype,"isMatch",2),k([$()],l.VibeFlagBoolean.prototype,"ready",2),l.VibeFlagBoolean=k([U("vibe-flag-boolean")],l.VibeFlagBoolean);var Ke=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,z=(r,e,t,s)=>{for(var i=s>1?void 0:s?Je(e,t):e,o=r.length-1,n;o>=0;o--)(n=r[o])&&(i=(s?n(e,t,i):n(i))||i);return s&&i&&Ke(e,t,i),i};l.VibeFlagSelect=class extends v{constructor(){super(...arguments),this.name="",this.description="",this.ready=!1,this.onFlagChange=()=>{this.syncOptions()}}connectedCallback(){super.connectedCallback(),window.addEventListener("vibe-flags-changed",this.onFlagChange),queueMicrotask(()=>this.registerFlag())}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("vibe-flags-changed",this.onFlagChange)}willUpdate(e){(e.has("name")||e.has("description"))&&this.registerFlag()}getOptions(){return Array.from(this.querySelectorAll("vibe-flag-option"))}registerFlag(){if(!this.name)return;const e=this.getOptions().map(t=>t.value).filter(Boolean);e.length!==0&&(u.getConfigForKey(this.name)||u.register({key:this.name,type:"select",options:e,label:this.description||void 0}),this.syncOptions())}syncOptions(){const e=u.get(this.name);for(const t of this.getOptions())t.active=t.value===e;this.ready||(this.ready=!0,this.style.display="contents")}render(){return g`<slot></slot>`}},z([S({type:String})],l.VibeFlagSelect.prototype,"name",2),z([S({type:String})],l.VibeFlagSelect.prototype,"description",2),z([$()],l.VibeFlagSelect.prototype,"ready",2),l.VibeFlagSelect=z([U("vibe-flag-select")],l.VibeFlagSelect);var Xe=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,ee=(r,e,t,s)=>{for(var i=s>1?void 0:s?Ye(e,t):e,o=r.length-1,n;o>=0;o--)(n=r[o])&&(i=(s?n(e,t,i):n(i))||i);return s&&i&&Xe(e,t,i),i};l.VibeFlagOption=class extends v{constructor(){super(...arguments),this.value="",this.active=!1}render(){return this.active?g`<slot></slot>`:d}},ee([S({type:String})],l.VibeFlagOption.prototype,"value",2),ee([$()],l.VibeFlagOption.prototype,"active",2),l.VibeFlagOption=ee([U("vibe-flag-option")],l.VibeFlagOption);const Ze=K`
|
|
32
32
|
:host {
|
|
33
33
|
--vf-bg: #0a0a0a;
|
|
34
34
|
--vf-bg-muted: #171717;
|
package/dist/vibe-flags.cdn.mjs
CHANGED
|
@@ -667,7 +667,7 @@ var Xe = Object.defineProperty, Ye = Object.getOwnPropertyDescriptor, P = (i, e,
|
|
|
667
667
|
};
|
|
668
668
|
if (typeof document < "u" && !document.getElementById("vibe-flag-fouc")) {
|
|
669
669
|
const i = document.createElement("style");
|
|
670
|
-
i.id = "vibe-flag-fouc", i.textContent = "vibe-flag-boolean:not(:defined),vibe-flag-boolean:defined,vibe-flag-select:not(:defined),vibe-flag-select:defined,vibe-flag-option:not(:defined),vibe-flag-option:defined{
|
|
670
|
+
i.id = "vibe-flag-fouc", i.textContent = "vibe-flag-boolean:not(:defined),vibe-flag-boolean:defined,vibe-flag-select:not(:defined),vibe-flag-select:defined,vibe-flag-option:not(:defined),vibe-flag-option:defined{display:none}", document.head.appendChild(i);
|
|
671
671
|
}
|
|
672
672
|
let A = class extends v {
|
|
673
673
|
constructor() {
|
|
@@ -693,7 +693,7 @@ let A = class extends v {
|
|
|
693
693
|
}
|
|
694
694
|
evaluate() {
|
|
695
695
|
const i = u.get(this.name);
|
|
696
|
-
i === void 0 ? this.isMatch = !1 : this.value === "" ? this.isMatch = !0 : this.isMatch = String(i) === this.value, this.ready || (this.ready = !0, this.style.
|
|
696
|
+
i === void 0 ? this.isMatch = !1 : this.value === "" ? this.isMatch = !0 : this.isMatch = String(i) === this.value, this.ready || (this.ready = !0, this.style.display = "contents");
|
|
697
697
|
}
|
|
698
698
|
render() {
|
|
699
699
|
return this.isMatch ? f`<slot></slot>` : c;
|
|
@@ -754,7 +754,7 @@ let H = class extends v {
|
|
|
754
754
|
const i = u.get(this.name);
|
|
755
755
|
for (const e of this.getOptions())
|
|
756
756
|
e.active = e.value === i;
|
|
757
|
-
this.ready || (this.ready = !0, this.style.
|
|
757
|
+
this.ready || (this.ready = !0, this.style.display = "contents");
|
|
758
758
|
}
|
|
759
759
|
render() {
|
|
760
760
|
return f`<slot></slot>`;
|
package/dist/vibe-flags.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { LitElement as u, html as a, nothing as y, css as S } from "lit";
|
|
2
2
|
import { customElement as b, property as f, state as c } from "lit/decorators.js";
|
|
3
|
-
var O = Object.getOwnPropertyDescriptor, _ = (t, e, r,
|
|
4
|
-
for (var
|
|
5
|
-
(
|
|
6
|
-
return
|
|
3
|
+
var O = Object.getOwnPropertyDescriptor, _ = (t, e, r, s) => {
|
|
4
|
+
for (var o = s > 1 ? void 0 : s ? O(e, r) : e, n = t.length - 1, i; n >= 0; n--)
|
|
5
|
+
(i = t[n]) && (o = i(o) || o);
|
|
6
|
+
return o;
|
|
7
7
|
};
|
|
8
8
|
let F = class extends u {
|
|
9
9
|
render() {
|
|
@@ -21,11 +21,11 @@ class M extends EventTarget {
|
|
|
21
21
|
constructor() {
|
|
22
22
|
super(...arguments), this.configs = /* @__PURE__ */ new Map(), this.state = {}, this.listening = !1, this.onStorageEvent = (e) => {
|
|
23
23
|
if (!e.key?.startsWith(h)) return;
|
|
24
|
-
const r = e.key.slice(h.length),
|
|
25
|
-
if (
|
|
24
|
+
const r = e.key.slice(h.length), s = this.configs.get(r);
|
|
25
|
+
if (s)
|
|
26
26
|
try {
|
|
27
|
-
const
|
|
28
|
-
this.state[r] =
|
|
27
|
+
const o = e.newValue ? JSON.parse(e.newValue) : k(s);
|
|
28
|
+
this.state[r] = o, this.dispatch(r);
|
|
29
29
|
} catch {
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -42,8 +42,8 @@ class M extends EventTarget {
|
|
|
42
42
|
return this.state[e];
|
|
43
43
|
}
|
|
44
44
|
set(e, r) {
|
|
45
|
-
const
|
|
46
|
-
|
|
45
|
+
const s = this.configs.get(e);
|
|
46
|
+
s && (s.type === "boolean" && typeof r != "boolean" || s.type === "select" && (typeof r != "string" || !s.options.includes(r)) || (this.state[e] = r, this.writeToStorage(e, r), this.dispatch(e)));
|
|
47
47
|
}
|
|
48
48
|
getAll() {
|
|
49
49
|
return { ...this.state };
|
|
@@ -83,22 +83,22 @@ class M extends EventTarget {
|
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
dispatch(e) {
|
|
86
|
-
const r = { key: e, state: this.getAll() },
|
|
86
|
+
const r = { key: e, state: this.getAll() }, s = new CustomEvent("vibe-flags-changed", {
|
|
87
87
|
detail: r,
|
|
88
88
|
bubbles: !0
|
|
89
89
|
});
|
|
90
|
-
this.dispatchEvent(
|
|
90
|
+
this.dispatchEvent(s), typeof window < "u" && window.dispatchEvent(new CustomEvent("vibe-flags-changed", { detail: r }));
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
const l = new M();
|
|
94
|
-
var E = Object.defineProperty, P = Object.getOwnPropertyDescriptor, g = (t, e, r,
|
|
95
|
-
for (var
|
|
96
|
-
(
|
|
97
|
-
return
|
|
94
|
+
var E = Object.defineProperty, P = Object.getOwnPropertyDescriptor, g = (t, e, r, s) => {
|
|
95
|
+
for (var o = s > 1 ? void 0 : s ? P(e, r) : e, n = t.length - 1, i; n >= 0; n--)
|
|
96
|
+
(i = t[n]) && (o = (s ? i(e, r, o) : i(o)) || o);
|
|
97
|
+
return s && o && E(e, r, o), o;
|
|
98
98
|
};
|
|
99
99
|
if (typeof document < "u" && !document.getElementById("vibe-flag-fouc")) {
|
|
100
100
|
const t = document.createElement("style");
|
|
101
|
-
t.id = "vibe-flag-fouc", t.textContent = "vibe-flag-boolean:not(:defined),vibe-flag-boolean:defined,vibe-flag-select:not(:defined),vibe-flag-select:defined,vibe-flag-option:not(:defined),vibe-flag-option:defined{
|
|
101
|
+
t.id = "vibe-flag-fouc", t.textContent = "vibe-flag-boolean:not(:defined),vibe-flag-boolean:defined,vibe-flag-select:not(:defined),vibe-flag-select:defined,vibe-flag-option:not(:defined),vibe-flag-option:defined{display:none}", document.head.appendChild(t);
|
|
102
102
|
}
|
|
103
103
|
let p = class extends u {
|
|
104
104
|
constructor() {
|
|
@@ -124,7 +124,7 @@ let p = class extends u {
|
|
|
124
124
|
}
|
|
125
125
|
evaluate() {
|
|
126
126
|
const t = l.get(this.name);
|
|
127
|
-
t === void 0 ? this.isMatch = !1 : this.value === "" ? this.isMatch = !0 : this.isMatch = String(t) === this.value, this.ready || (this.ready = !0, this.style.
|
|
127
|
+
t === void 0 ? this.isMatch = !1 : this.value === "" ? this.isMatch = !0 : this.isMatch = String(t) === this.value, this.ready || (this.ready = !0, this.style.display = "contents");
|
|
128
128
|
}
|
|
129
129
|
render() {
|
|
130
130
|
return this.isMatch ? a`<slot></slot>` : y;
|
|
@@ -148,10 +148,10 @@ g([
|
|
|
148
148
|
p = g([
|
|
149
149
|
b("vibe-flag-boolean")
|
|
150
150
|
], p);
|
|
151
|
-
var T = Object.defineProperty, j = Object.getOwnPropertyDescriptor, w = (t, e, r,
|
|
152
|
-
for (var
|
|
153
|
-
(
|
|
154
|
-
return
|
|
151
|
+
var T = Object.defineProperty, j = Object.getOwnPropertyDescriptor, w = (t, e, r, s) => {
|
|
152
|
+
for (var o = s > 1 ? void 0 : s ? j(e, r) : e, n = t.length - 1, i; n >= 0; n--)
|
|
153
|
+
(i = t[n]) && (o = (s ? i(e, r, o) : i(o)) || o);
|
|
154
|
+
return s && o && T(e, r, o), o;
|
|
155
155
|
};
|
|
156
156
|
let v = class extends u {
|
|
157
157
|
constructor() {
|
|
@@ -185,7 +185,7 @@ let v = class extends u {
|
|
|
185
185
|
const t = l.get(this.name);
|
|
186
186
|
for (const e of this.getOptions())
|
|
187
187
|
e.active = e.value === t;
|
|
188
|
-
this.ready || (this.ready = !0, this.style.
|
|
188
|
+
this.ready || (this.ready = !0, this.style.display = "contents");
|
|
189
189
|
}
|
|
190
190
|
render() {
|
|
191
191
|
return a`<slot></slot>`;
|
|
@@ -203,10 +203,10 @@ w([
|
|
|
203
203
|
v = w([
|
|
204
204
|
b("vibe-flag-select")
|
|
205
205
|
], v);
|
|
206
|
-
var I = Object.defineProperty, z = Object.getOwnPropertyDescriptor, C = (t, e, r,
|
|
207
|
-
for (var
|
|
208
|
-
(
|
|
209
|
-
return
|
|
206
|
+
var I = Object.defineProperty, z = Object.getOwnPropertyDescriptor, C = (t, e, r, s) => {
|
|
207
|
+
for (var o = s > 1 ? void 0 : s ? z(e, r) : e, n = t.length - 1, i; n >= 0; n--)
|
|
208
|
+
(i = t[n]) && (o = (s ? i(e, r, o) : i(o)) || o);
|
|
209
|
+
return s && o && I(e, r, o), o;
|
|
210
210
|
};
|
|
211
211
|
let m = class extends u {
|
|
212
212
|
constructor() {
|
|
@@ -274,10 +274,10 @@ const D = S`
|
|
|
274
274
|
0 8px 10px -6px rgba(0, 0, 0, 0.1);
|
|
275
275
|
}
|
|
276
276
|
`;
|
|
277
|
-
var A = Object.defineProperty, V = Object.getOwnPropertyDescriptor, x = (t, e, r,
|
|
278
|
-
for (var
|
|
279
|
-
(
|
|
280
|
-
return
|
|
277
|
+
var A = Object.defineProperty, V = Object.getOwnPropertyDescriptor, x = (t, e, r, s) => {
|
|
278
|
+
for (var o = s > 1 ? void 0 : s ? V(e, r) : e, n = t.length - 1, i; n >= 0; n--)
|
|
279
|
+
(i = t[n]) && (o = (s ? i(e, r, o) : i(o)) || o);
|
|
280
|
+
return s && o && A(e, r, o), o;
|
|
281
281
|
};
|
|
282
282
|
const $ = "vibeFlagsTheme";
|
|
283
283
|
let d = class extends u {
|