@rettangoli/ui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -0
- package/dist/rettangoli-iife-layout.min.js +728 -0
- package/dist/rettangoli-iife-ui.min.js +830 -0
- package/package.json +53 -0
- package/src/common/BaseElement.js +182 -0
- package/src/common.js +190 -0
- package/src/components/dialog/dialog.handlers.js +5 -0
- package/src/components/dialog/dialog.store.js +25 -0
- package/src/components/dialog/dialog.view.yaml +44 -0
- package/src/components/dropdownMenu/dropdownMenu.handlers.js +18 -0
- package/src/components/dropdownMenu/dropdownMenu.store.js +25 -0
- package/src/components/dropdownMenu/dropdownMenu.view.yaml +54 -0
- package/src/components/form/form.handlers.js +63 -0
- package/src/components/form/form.store.js +45 -0
- package/src/components/form/form.view.yaml +174 -0
- package/src/components/navbar/navbar.examples.yaml +86 -0
- package/src/components/navbar/navbar.handlers.js +10 -0
- package/src/components/navbar/navbar.store.js +46 -0
- package/src/components/navbar/navbar.view.yaml +74 -0
- package/src/components/pageOutline/pageOutline.handlers.js +69 -0
- package/src/components/pageOutline/pageOutline.store.js +40 -0
- package/src/components/pageOutline/pageOutline.view.yaml +34 -0
- package/src/components/popover/popover.handlers.js +5 -0
- package/src/components/popover/popover.store.js +12 -0
- package/src/components/popover/popover.view.yaml +57 -0
- package/src/components/select/select.handlers.js +61 -0
- package/src/components/select/select.store.js +65 -0
- package/src/components/select/select.view.yaml +50 -0
- package/src/components/sidebar/sidebar.handlers.js +36 -0
- package/src/components/sidebar/sidebar.store.js +142 -0
- package/src/components/sidebar/sidebar.view.yaml +190 -0
- package/src/components/table/table.handlers.js +55 -0
- package/src/components/table/table.store.js +72 -0
- package/src/components/table/table.view.yaml +103 -0
- package/src/entry-iife-layout.js +15 -0
- package/src/entry-iife-ui.js +22 -0
- package/src/index.js +17 -0
- package/src/lib/uhtml.js +9 -0
- package/src/primitives/button.js +306 -0
- package/src/primitives/colorPicker.js +213 -0
- package/src/primitives/image.js +234 -0
- package/src/primitives/input.js +218 -0
- package/src/primitives/slider.js +269 -0
- package/src/primitives/svg.js +95 -0
- package/src/primitives/text.js +141 -0
- package/src/primitives/textarea.js +103 -0
- package/src/primitives/view.js +217 -0
- package/src/setup.js +16 -0
- package/src/styles/anchorStyles.js +13 -0
- package/src/styles/buttonMarginStyles.js +84 -0
- package/src/styles/cursorStyles.js +12 -0
- package/src/styles/flexChildStyles.js +43 -0
- package/src/styles/flexDirectionStyles.js +74 -0
- package/src/styles/marginStyles.js +13 -0
- package/src/styles/paddingSvgStyles.js +120 -0
- package/src/styles/scrollStyles.js +22 -0
- package/src/styles/textColorStyles.js +14 -0
- package/src/styles/textStyles.js +62 -0
- package/src/styles/viewStyles.js +114 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import RettangoliButton from './primitives/button.js'
|
|
2
|
+
import RettangoliView from './primitives/view.js';
|
|
3
|
+
import RettangoliText from './primitives/text.js';
|
|
4
|
+
import RettangoliImage from './primitives/image.js';
|
|
5
|
+
import RettangoliSvg from './primitives/svg.js';
|
|
6
|
+
import RettangoliInput from './primitives/input.js';
|
|
7
|
+
import RettangoliTextArea from './primitives/textarea.js';
|
|
8
|
+
|
|
9
|
+
customElements.define("rtgl-button", RettangoliButton({}));
|
|
10
|
+
customElements.define("rtgl-view", RettangoliView({}));
|
|
11
|
+
customElements.define("rtgl-text", RettangoliText({}));
|
|
12
|
+
customElements.define("rtgl-image", RettangoliImage({}));
|
|
13
|
+
customElements.define("rtgl-svg", RettangoliSvg({}));
|
|
14
|
+
customElements.define("rtgl-input", RettangoliInput({}));
|
|
15
|
+
customElements.define("rtgl-textarea", RettangoliTextArea({}));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import RettangoliButton from './primitives/button.js'
|
|
2
|
+
import RettangoliView from './primitives/view.js';
|
|
3
|
+
import RettangoliText from './primitives/text.js';
|
|
4
|
+
import RettangoliImage from './primitives/image.js';
|
|
5
|
+
import RettangoliSvg from './primitives/svg.js';
|
|
6
|
+
import RettangoliInput from './primitives/input.js';
|
|
7
|
+
import RettangoliTextArea from './primitives/textarea.js';
|
|
8
|
+
import RettangoliColorPicker from './primitives/colorPicker.js';
|
|
9
|
+
import RettangoliSlider from './primitives/slider.js';
|
|
10
|
+
|
|
11
|
+
customElements.define("rtgl-button", RettangoliButton({}));
|
|
12
|
+
customElements.define("rtgl-view", RettangoliView({}));
|
|
13
|
+
customElements.define("rtgl-text", RettangoliText({}));
|
|
14
|
+
customElements.define("rtgl-image", RettangoliImage({}));
|
|
15
|
+
customElements.define("rtgl-svg", RettangoliSvg({}));
|
|
16
|
+
customElements.define("rtgl-input", RettangoliInput({}));
|
|
17
|
+
customElements.define("rtgl-textarea", RettangoliTextArea({}));
|
|
18
|
+
customElements.define("rtgl-color-picker", RettangoliColorPicker({}));
|
|
19
|
+
customElements.define("rtgl-slider", RettangoliSlider({}));
|
|
20
|
+
|
|
21
|
+
// built from rettangoli cli fe
|
|
22
|
+
import '../.temp/dynamicImport.js'
|
package/src/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import RettangoliButton from './primitives/button.js'
|
|
2
|
+
import RettangoliView from './primitives/view.js';
|
|
3
|
+
import RettangoliText from './primitives/text.js';
|
|
4
|
+
import RettangoliImage from './primitives/image.js';
|
|
5
|
+
import RettangoliSvg from './primitives/svg.js';
|
|
6
|
+
import RettangoliInput from './primitives/input.js';
|
|
7
|
+
import RettangoliTextArea from './primitives/textarea.js';
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
RettangoliButton,
|
|
11
|
+
RettangoliView,
|
|
12
|
+
RettangoliText,
|
|
13
|
+
RettangoliImage,
|
|
14
|
+
RettangoliSvg,
|
|
15
|
+
RettangoliInput,
|
|
16
|
+
RettangoliTextArea,
|
|
17
|
+
}
|
package/src/lib/uhtml.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skipped minification because the original files appears to be already minified.
|
|
3
|
+
* Original file: /npm/uhtml@4.7.0/keyed.js
|
|
4
|
+
*
|
|
5
|
+
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
|
|
6
|
+
*/
|
|
7
|
+
const{isArray:e}=Array,{getPrototypeOf:t,getOwnPropertyDescriptor:n}=Object,r=[],s=()=>document.createRange(),l=(e,t,n)=>(e.set(t,n),n),i=(e,t)=>t.reduceRight(o,e),o=(e,t)=>e.childNodes[t],{setPrototypeOf:c}=Object;let a;var u=(e,t,n)=>(a||(a=s()),n?a.setStartAfter(e):a.setStartBefore(e),a.setEndAfter(t),a.deleteContents(),e);const h=({firstChild:e,lastChild:t},n)=>u(e,t,n);let d=!1;const f=(e,t)=>d&&11===e.nodeType?1/t<0?t?h(e,!0):e.lastChild:t?e.valueOf():e.firstChild:e,p=e=>document.createComment(e);class g extends((e=>{function t(e){return c(e,new.target.prototype)}return t.prototype=e.prototype,t})(DocumentFragment)){#e=p("<>");#t=p("</>");#n=r;constructor(e){super(e),this.replaceChildren(this.#e,...e.childNodes,this.#t),d=!0}get firstChild(){return this.#e}get lastChild(){return this.#t}get parentNode(){return this.#e.parentNode}remove(){h(this,!1)}replaceWith(e){h(this,!0).replaceWith(e)}valueOf(){const{parentNode:e}=this;if(e===this)this.#n===r&&(this.#n=[...this.childNodes]);else{if(e){let{firstChild:e,lastChild:t}=this;for(this.#n=[e];e!==t;)this.#n.push(e=e.nextSibling)}this.replaceChildren(...this.#n)}return this}}const m=(e,t,n)=>e.setAttribute(t,n),b=(e,t)=>e.removeAttribute(t);let v;const C=(t,n,r)=>{r=r.slice(1),v||(v=new WeakMap);const s=v.get(t)||l(v,t,{});let i=s[r];return i&&i[0]&&t.removeEventListener(r,...i),i=e(n)?n:[n,!1],s[r]=i,i[0]&&t.addEventListener(r,...i),n},w=(e,t)=>{const{t:n,n:r}=e;let s=!1;switch(typeof t){case"object":if(null!==t){(r||n).replaceWith(e.n=t.valueOf());break}case"undefined":s=!0;default:n.data=s?"":t,r&&(e.n=null,r.replaceWith(n))}return t},x=(e,t,n)=>e[n]=t,$=(e,t,n)=>x(e,t,n.slice(1)),y=(e,t,n)=>null==t?(b(e,n),t):x(e,t,n),N=(e,t)=>("function"==typeof t?t(e):t.current=e,t),O=(e,t,n)=>(null==t?b(e,n):m(e,n,t),t),k=(e,t,n)=>(e.toggleAttribute(n.slice(1),t),t),A=(e,t,n)=>{const{length:s}=t;if(e.data=`[${s}]`,s)return((e,t,n,r,s)=>{const l=n.length;let i=t.length,o=l,c=0,a=0,u=null;for(;c<i||a<o;)if(i===c){const t=o<l?a?r(n[a-1],-0).nextSibling:r(n[o],0):s;for(;a<o;)e.insertBefore(r(n[a++],1),t)}else if(o===a)for(;c<i;)u&&u.has(t[c])||e.removeChild(r(t[c],-1)),c++;else if(t[c]===n[a])c++,a++;else if(t[i-1]===n[o-1])i--,o--;else if(t[c]===n[o-1]&&n[a]===t[i-1]){const s=r(t[--i],-0).nextSibling;e.insertBefore(r(n[a++],1),r(t[c++],-0).nextSibling),e.insertBefore(r(n[--o],1),s),t[i]=n[o]}else{if(!u){u=new Map;let e=a;for(;e<o;)u.set(n[e],e++)}if(u.has(t[c])){const s=u.get(t[c]);if(a<s&&s<o){let l=c,h=1;for(;++l<i&&l<o&&u.get(t[l])===s+h;)h++;if(h>s-a){const l=r(t[c],0);for(;a<s;)e.insertBefore(r(n[a++],1),l)}else e.replaceChild(r(n[a++],1),r(t[c++],-1))}else c++}else e.removeChild(r(t[c++],-1))}return n})(e.parentNode,n,t,f,e);switch(n.length){case 1:n[0].remove();case 0:break;default:u(f(n[0],0),f(n.at(-1),-0),!1)}return r},M=new Map([["aria",(e,t)=>{for(const n in t){const r=t[n],s="role"===n?n:`aria-${n}`;null==r?b(e,s):m(e,s,r)}return t}],["class",(e,t)=>y(e,t,null==t?"class":"className")],["data",(e,t)=>{const{dataset:n}=e;for(const e in t)null==t[e]?delete n[e]:n[e]=t[e];return t}],["ref",N],["style",(e,t)=>null==t?y(e,t,"style"):x(e.style,t,"cssText")]]),W=(e,r,s)=>{switch(r[0]){case".":return $;case"?":return k;case"@":return C;default:return s||"ownerSVGElement"in e?"ref"===r?N:O:M.get(r)||(r in e?r.startsWith("on")?x:((e,r)=>{let s;do{s=n(e,r)}while(!s&&(e=t(e)));return s})(e,r)?.set?y:O:O)}},S=(e,t)=>(e.textContent=null==t?"":t,t),E=(e,t,n)=>({a:e,b:t,c:n}),T=()=>E(null,null,r);var B=e=>(t,n)=>{const{a:s,b:l,c:o}=e(t,n),c=document.importNode(s,!0);let a=r;if(l!==r){a=[];for(let e,t,n=0;n<l.length;n++){const{a:s,b:o,c:p}=l[n],g=s===t?e:e=i(c,t=s);a[n]=(u=o,h=g,d=p,f=o===A?[]:o===w?T():null,{v:r,u:u,t:h,n:d,c:f})}}var u,h,d,f;return((e,t)=>({b:e,c:t}))(o?c.firstChild:new g(c),a)};const D=/^(?:plaintext|script|style|textarea|title|xmp)$/i,j=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i,L=/<([a-zA-Z0-9]+[a-zA-Z0-9:._-]*)([^>]*?)(\/?)>/g,P=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,z=/[\x01\x02]/g;let F,R,Z=document.createElement("template");var G=(e,t)=>{if(t)return F||(F=document.createElementNS("http://www.w3.org/2000/svg","svg"),R=s(),R.selectNodeContents(F)),R.createContextualFragment(e);Z.innerHTML=e;const{content:n}=Z;return Z=Z.cloneNode(!1),n};const H=e=>{const t=[];let n;for(;n=e.parentNode;)t.push(t.indexOf.call(n.childNodes,e)),e=n;return t},V=()=>document.createTextNode(""),_=(t,n,s)=>{const i=G(((e,t,n)=>{let r=0;return e.join("").trim().replace(L,((e,t,r,s)=>`<${t}${r.replace(P,"=$2$1").trimEnd()}${s?n||j.test(t)?" /":`></${t}`:""}>`)).replace(z,(e=>""===e?`\x3c!--${t+r++}--\x3e`:t+r++))})(t,I,s),s),{length:o}=t;let c=r;if(o>1){const t=[],r=document.createTreeWalker(i,129);let l=0,a=`${I}${l++}`;for(c=[];l<o;){const i=r.nextNode();if(8===i.nodeType){if(i.data===a){const r=e(n[l-1])?A:w;r===w&&t.push(i),c.push(E(H(i),r,null)),a=`${I}${l++}`}}else{let e;for(;i.hasAttribute(a);){e||(e=H(i));const t=i.getAttribute(a);c.push(E(e,W(i,t,s),t)),b(i,a),a=`${I}${l++}`}!s&&D.test(i.localName)&&i.textContent.trim()===`\x3c!--${a}--\x3e`&&(c.push(E(e||H(i),S,null)),a=`${I}${l++}`)}}for(l=0;l<t.length;l++)t[l].replaceWith(V())}const{childNodes:a}=i;let{length:u}=a;return u<1?(u=1,i.appendChild(V())):1===u&&1!==o&&1!==a[0].nodeType&&(u=0),l(q,t,E(i,c,1===u))},q=new WeakMap,I="isµ";var J=e=>(t,n)=>q.get(t)||_(t,n,e);const K=B(J(!1)),Q=B(J(!0)),U=(e,{s:t,t:n,v:r})=>{if(e.a!==n){const{b:s,c:l}=(t?Q:K)(n,r);e.a=n,e.b=s,e.c=l}for(let{c:t}=e,n=0;n<t.length;n++){const e=r[n],s=t[n];switch(s.u){case A:s.v=A(s.t,X(s.c,e),s.v);break;case w:const t=e instanceof Y?U(s.c||(s.c=T()),e):(s.c=null,e);t!==s.v&&(s.v=w(s,t));break;default:e!==s.v&&(s.v=s.u(s.t,e,s.n,s.v))}}return e.b},X=(e,t)=>{let n=0,{length:r}=t;for(r<e.length&&e.splice(r);n<r;n++){const r=t[n];r instanceof Y?t[n]=U(e[n]||(e[n]=T()),r):e[n]=null}return t};class Y{constructor(e,t,n){this.s=e,this.t=t,this.v=n}toDOM(e=T()){return U(e,this)}}
|
|
8
|
+
/*! (c) Andrea Giammarchi - MIT */const ee=e=>(t,...n)=>new Y(e,t,n),te=ee(!1),ne=ee(!0),re=new WeakMap;var se=(e,t)=>((e,t)=>{const n=re.get(e)||l(re,e,T()),{b:r}=n,s="function"==typeof t?t():t,i=s instanceof Y?s.toDOM(n):s;return r!==i&&e.replaceChildren((n.b=i).valueOf()),e})(e,t)
|
|
9
|
+
/*! (c) Andrea Giammarchi - MIT */;const le=new WeakMap,ie=e=>(t,n)=>{const r=le.get(t)||l(le,t,new Map);return r.get(n)||l(r,n,function(t,...n){return new Y(e,t,n).toDOM(this)}.bind(T()))},oe=ie(!1),ce=ie(!0);export{Y as Hole,M as attr,te as html,oe as htmlFor,se as render,ne as svg,ce as svgFor};
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { css, dimensionWithUnit } from "../common.js";
|
|
2
|
+
import flexChildStyles from "../styles/flexChildStyles.js";
|
|
3
|
+
import buttonMarginStyles from "../styles/buttonMarginStyles.js";
|
|
4
|
+
import anchorStyles from "../styles/anchorStyles.js";
|
|
5
|
+
|
|
6
|
+
// Internal implementation without uhtml
|
|
7
|
+
class RettangoliButtonElement extends HTMLElement {
|
|
8
|
+
static styleSheet = null;
|
|
9
|
+
|
|
10
|
+
static initializeStyleSheet() {
|
|
11
|
+
if (!RettangoliButtonElement.styleSheet) {
|
|
12
|
+
RettangoliButtonElement.styleSheet = new CSSStyleSheet();
|
|
13
|
+
RettangoliButtonElement.styleSheet.replaceSync(css`
|
|
14
|
+
:host {
|
|
15
|
+
display: contents;
|
|
16
|
+
}
|
|
17
|
+
slot {
|
|
18
|
+
display: contents;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
button {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: row;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
gap: var(--spacing-lg);
|
|
27
|
+
border-width: 0px;
|
|
28
|
+
border-style: solid;
|
|
29
|
+
border-color: var(--border);
|
|
30
|
+
padding: 0px;
|
|
31
|
+
height: 32px;
|
|
32
|
+
padding-left: 16px;
|
|
33
|
+
padding-right: 16px;
|
|
34
|
+
border-radius: 4px;
|
|
35
|
+
|
|
36
|
+
font-size: var(--sm-font-size);
|
|
37
|
+
font-weight: var(--sm-font-weight);
|
|
38
|
+
line-height: var(--sm-line-height);
|
|
39
|
+
letter-spacing: var(--sm-letter-spacing);
|
|
40
|
+
|
|
41
|
+
background-color: var(--primary);
|
|
42
|
+
color: var(--primary-foreground);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
button:hover {
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
background-color: color-mix(
|
|
48
|
+
in srgb,
|
|
49
|
+
var(--primary) 85%,
|
|
50
|
+
white 15%
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
button:disabled {
|
|
55
|
+
cursor: not-allowed;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
button:active {
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
background-color: color-mix(
|
|
61
|
+
in srgb,
|
|
62
|
+
var(--primary) 80%,
|
|
63
|
+
white 20%
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
:host([v="pr"]) button:hover {
|
|
68
|
+
background-color: color-mix(
|
|
69
|
+
in srgb,
|
|
70
|
+
var(--primary) 85%,
|
|
71
|
+
white 15%
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
:host([v="pr"]) button:active {
|
|
76
|
+
background-color: color-mix(
|
|
77
|
+
in srgb,
|
|
78
|
+
var(--primary) 80%,
|
|
79
|
+
white 20%
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
:host([v="se"]) button:hover {
|
|
84
|
+
background-color: color-mix(
|
|
85
|
+
in srgb,
|
|
86
|
+
var(--secondary) 85%,
|
|
87
|
+
white 15%
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
:host([v="se"]) button:active {
|
|
92
|
+
background-color: color-mix(
|
|
93
|
+
in srgb,
|
|
94
|
+
var(--secondary) 80%,
|
|
95
|
+
white 20%
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
:host([v="de"]) button:hover {
|
|
100
|
+
background-color: color-mix(
|
|
101
|
+
in srgb,
|
|
102
|
+
var(--destructive) 85%,
|
|
103
|
+
white 15%
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
:host([v="de"]) button:active {
|
|
108
|
+
background-color: color-mix(
|
|
109
|
+
in srgb,
|
|
110
|
+
var(--destructive) 80%,
|
|
111
|
+
white 20%
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
:host([v="ol"]) button:hover {
|
|
116
|
+
background-color: var(--accent);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
:host([v="gh"]) button:hover {
|
|
120
|
+
background-color: var(--accent);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
:host([v="lk"]) button:hover {
|
|
124
|
+
text-decoration: underline;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* Square button styles */
|
|
128
|
+
:host([sq]) button {
|
|
129
|
+
width: 32px;
|
|
130
|
+
height: 32px;
|
|
131
|
+
padding: 0;
|
|
132
|
+
gap: 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
:host([sq][s="sm"]) button {
|
|
136
|
+
width: 24px;
|
|
137
|
+
height: 24px;
|
|
138
|
+
padding: 0;
|
|
139
|
+
gap: 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
:host([sq][s="lg"]) button {
|
|
143
|
+
width: 40px;
|
|
144
|
+
height: 40px;
|
|
145
|
+
padding: 0;
|
|
146
|
+
gap: 0;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
${anchorStyles}
|
|
150
|
+
|
|
151
|
+
a {
|
|
152
|
+
display: contents;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
${buttonMarginStyles}
|
|
156
|
+
${flexChildStyles}
|
|
157
|
+
`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
constructor() {
|
|
162
|
+
super();
|
|
163
|
+
RettangoliButtonElement.initializeStyleSheet();
|
|
164
|
+
this.shadow = this.attachShadow({ mode: "closed" });
|
|
165
|
+
this.shadow.adoptedStyleSheets = [RettangoliButtonElement.styleSheet];
|
|
166
|
+
|
|
167
|
+
// Create initial DOM structure
|
|
168
|
+
this._containerElement = null;
|
|
169
|
+
this._buttonElement = document.createElement('button');
|
|
170
|
+
this._slotElement = document.createElement('slot');
|
|
171
|
+
this._iconElement = null;
|
|
172
|
+
|
|
173
|
+
this._buttonElement.appendChild(this._slotElement);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
static get observedAttributes() {
|
|
177
|
+
return ["key", "href", "target", "w", "t", "icon", "disabled", "v", "s", "sq", "ip"];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
connectedCallback() {
|
|
181
|
+
this._updateButton();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
185
|
+
this._updateButton();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
_updateButton() {
|
|
189
|
+
// Clear shadow DOM
|
|
190
|
+
this.shadow.innerHTML = '';
|
|
191
|
+
|
|
192
|
+
// Update icon
|
|
193
|
+
this._updateIcon();
|
|
194
|
+
|
|
195
|
+
// Update width styling (skip for square buttons)
|
|
196
|
+
if (!this.hasAttribute('sq')) {
|
|
197
|
+
this._updateWidth();
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Update disabled state
|
|
201
|
+
const isDisabled = this.hasAttribute('disabled');
|
|
202
|
+
if (isDisabled) {
|
|
203
|
+
this._buttonElement.setAttribute('disabled', '');
|
|
204
|
+
} else {
|
|
205
|
+
this._buttonElement.removeAttribute('disabled');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Handle href (link) vs button
|
|
209
|
+
const href = this.getAttribute("href");
|
|
210
|
+
if (href) {
|
|
211
|
+
// Create anchor wrapper
|
|
212
|
+
const anchorElement = document.createElement('a');
|
|
213
|
+
anchorElement.setAttribute('href', href);
|
|
214
|
+
|
|
215
|
+
const target = this.getAttribute("target");
|
|
216
|
+
if (target) {
|
|
217
|
+
anchorElement.setAttribute('target', target);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
anchorElement.appendChild(this._buttonElement);
|
|
221
|
+
this.shadow.appendChild(anchorElement);
|
|
222
|
+
this._containerElement = anchorElement;
|
|
223
|
+
} else {
|
|
224
|
+
// Direct button
|
|
225
|
+
this.shadow.appendChild(this._buttonElement);
|
|
226
|
+
this._containerElement = this._buttonElement;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
_updateIcon() {
|
|
231
|
+
// Remove existing icon if any
|
|
232
|
+
if (this._iconElement) {
|
|
233
|
+
this._iconElement.remove();
|
|
234
|
+
this._iconElement = null;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const icon = this.getAttribute("icon");
|
|
238
|
+
if (icon) {
|
|
239
|
+
const colorMap = {
|
|
240
|
+
pr: 'pr-fg',
|
|
241
|
+
se: 'ac-fg',
|
|
242
|
+
de: 'pr-fg',
|
|
243
|
+
ol: 'ac-fg',
|
|
244
|
+
gh: 'ac-fg',
|
|
245
|
+
lk: 'ac-fg'
|
|
246
|
+
};
|
|
247
|
+
const sizeMap = {
|
|
248
|
+
sm: 14,
|
|
249
|
+
md: 18,
|
|
250
|
+
lg: 22
|
|
251
|
+
};
|
|
252
|
+
const color = colorMap[this.getAttribute("v")] || 'pr-fg';
|
|
253
|
+
|
|
254
|
+
// For square buttons, use button size (s attribute), otherwise use icon size (t attribute)
|
|
255
|
+
let size = 18; // default
|
|
256
|
+
if (this.hasAttribute('sq')) {
|
|
257
|
+
const buttonSizeMap = {
|
|
258
|
+
sm: 14,
|
|
259
|
+
lg: 22
|
|
260
|
+
};
|
|
261
|
+
const buttonSize = this.getAttribute("s");
|
|
262
|
+
size = buttonSizeMap[buttonSize] || 18;
|
|
263
|
+
} else {
|
|
264
|
+
size = sizeMap[this.getAttribute("t")] || 18;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
this._iconElement = document.createElement('rtgl-svg');
|
|
268
|
+
this._iconElement.setAttribute('svg', icon);
|
|
269
|
+
this._iconElement.setAttribute('c', color);
|
|
270
|
+
this._iconElement.setAttribute('wh', size.toString());
|
|
271
|
+
|
|
272
|
+
// Insert icon based on position (default is right, 's' means start/left)
|
|
273
|
+
const iconPosition = this.getAttribute("ip");
|
|
274
|
+
if (iconPosition === 's') {
|
|
275
|
+
// Insert icon before slot (left position)
|
|
276
|
+
this._buttonElement.insertBefore(this._iconElement, this._slotElement);
|
|
277
|
+
} else {
|
|
278
|
+
// Insert icon after slot (right position - default)
|
|
279
|
+
this._buttonElement.appendChild(this._iconElement);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
_updateWidth() {
|
|
285
|
+
const width = dimensionWithUnit(this.getAttribute("w"));
|
|
286
|
+
|
|
287
|
+
if (width === "f") {
|
|
288
|
+
this._buttonElement.style.width = "var(--width-stretch)";
|
|
289
|
+
} else if (width !== undefined && width !== null) {
|
|
290
|
+
this._buttonElement.style.width = width;
|
|
291
|
+
this._buttonElement.style.minWidth = width;
|
|
292
|
+
this._buttonElement.style.maxWidth = width;
|
|
293
|
+
} else {
|
|
294
|
+
this._buttonElement.style.width = "";
|
|
295
|
+
this._buttonElement.style.minWidth = "";
|
|
296
|
+
this._buttonElement.style.maxWidth = "";
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Export factory function to maintain API compatibility
|
|
302
|
+
export default ({ render, html }) => {
|
|
303
|
+
// Note: render and html parameters are accepted but not used
|
|
304
|
+
// This maintains backward compatibility with existing code
|
|
305
|
+
return RettangoliButtonElement;
|
|
306
|
+
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import {
|
|
2
|
+
css,
|
|
3
|
+
dimensionWithUnit,
|
|
4
|
+
convertObjectToCssString,
|
|
5
|
+
styleMapKeys,
|
|
6
|
+
permutateBreakpoints,
|
|
7
|
+
} from "../common.js";
|
|
8
|
+
import cursorStyles from "../styles/cursorStyles.js";
|
|
9
|
+
import marginStyles from "../styles/marginStyles.js";
|
|
10
|
+
|
|
11
|
+
// Internal implementation without uhtml
|
|
12
|
+
class RettangoliColorPickerElement extends HTMLElement {
|
|
13
|
+
static styleSheet = null;
|
|
14
|
+
|
|
15
|
+
static initializeStyleSheet() {
|
|
16
|
+
if (!RettangoliColorPickerElement.styleSheet) {
|
|
17
|
+
RettangoliColorPickerElement.styleSheet = new CSSStyleSheet();
|
|
18
|
+
RettangoliColorPickerElement.styleSheet.replaceSync(css`
|
|
19
|
+
:host {
|
|
20
|
+
display: contents;
|
|
21
|
+
}
|
|
22
|
+
input[type="color"] {
|
|
23
|
+
background-color: var(--background);
|
|
24
|
+
border: 1px solid var(--ring);
|
|
25
|
+
border-radius: var(--border-radius-lg);
|
|
26
|
+
padding: 2px;
|
|
27
|
+
height: 32px;
|
|
28
|
+
width: 32px;
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
outline: none;
|
|
31
|
+
}
|
|
32
|
+
input[type="color"]:focus {
|
|
33
|
+
border-color: var(--foreground);
|
|
34
|
+
}
|
|
35
|
+
input[type="color"]:disabled {
|
|
36
|
+
cursor: not-allowed;
|
|
37
|
+
opacity: 0.5;
|
|
38
|
+
}
|
|
39
|
+
${marginStyles}
|
|
40
|
+
${cursorStyles}
|
|
41
|
+
`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
constructor() {
|
|
46
|
+
super();
|
|
47
|
+
RettangoliColorPickerElement.initializeStyleSheet();
|
|
48
|
+
this.shadow = this.attachShadow({ mode: "closed" });
|
|
49
|
+
this.shadow.adoptedStyleSheets = [RettangoliColorPickerElement.styleSheet];
|
|
50
|
+
|
|
51
|
+
// Initialize style tracking properties
|
|
52
|
+
this._styles = {
|
|
53
|
+
default: {},
|
|
54
|
+
sm: {},
|
|
55
|
+
md: {},
|
|
56
|
+
lg: {},
|
|
57
|
+
xl: {},
|
|
58
|
+
};
|
|
59
|
+
this._lastStyleString = "";
|
|
60
|
+
|
|
61
|
+
// Create initial DOM structure
|
|
62
|
+
this._inputElement = document.createElement('input');
|
|
63
|
+
this._inputElement.type = 'color';
|
|
64
|
+
this._styleElement = document.createElement('style');
|
|
65
|
+
|
|
66
|
+
this.shadow.appendChild(this._styleElement);
|
|
67
|
+
this.shadow.appendChild(this._inputElement);
|
|
68
|
+
|
|
69
|
+
// Bind event handlers
|
|
70
|
+
this._inputElement.addEventListener('change', this._onChange);
|
|
71
|
+
this._inputElement.addEventListener('input', this._onInput);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static get observedAttributes() {
|
|
75
|
+
return [
|
|
76
|
+
"key",
|
|
77
|
+
"value",
|
|
78
|
+
"disabled",
|
|
79
|
+
...permutateBreakpoints([
|
|
80
|
+
...styleMapKeys,
|
|
81
|
+
"wh",
|
|
82
|
+
"w",
|
|
83
|
+
"h",
|
|
84
|
+
"hidden",
|
|
85
|
+
"visible",
|
|
86
|
+
"op",
|
|
87
|
+
"z",
|
|
88
|
+
])
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get value() {
|
|
93
|
+
return this._inputElement.value;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
set value(newValue) {
|
|
97
|
+
this._inputElement.value = newValue;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
_onChange = (event) => {
|
|
101
|
+
this.dispatchEvent(new CustomEvent('colorpicker-change', {
|
|
102
|
+
detail: {
|
|
103
|
+
value: this._inputElement.value,
|
|
104
|
+
},
|
|
105
|
+
}));
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
_onInput = (event) => {
|
|
109
|
+
this.dispatchEvent(new CustomEvent('colorpicker-input', {
|
|
110
|
+
detail: {
|
|
111
|
+
value: this._inputElement.value,
|
|
112
|
+
},
|
|
113
|
+
}));
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
117
|
+
// Handle input-specific attributes first
|
|
118
|
+
if (["value", "disabled"].includes(name)) {
|
|
119
|
+
this._updateInputAttributes();
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Reset styles for fresh calculation
|
|
124
|
+
this._styles = {
|
|
125
|
+
default: {},
|
|
126
|
+
sm: {},
|
|
127
|
+
md: {},
|
|
128
|
+
lg: {},
|
|
129
|
+
xl: {},
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
["default", "sm", "md", "lg", "xl"].forEach((size) => {
|
|
133
|
+
const addSizePrefix = (tag) => {
|
|
134
|
+
return `${size === "default" ? "" : `${size}-`}${tag}`;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const wh = this.getAttribute(addSizePrefix("wh"));
|
|
138
|
+
const width = dimensionWithUnit(
|
|
139
|
+
wh === null ? this.getAttribute(addSizePrefix("w")) : wh,
|
|
140
|
+
);
|
|
141
|
+
const height = dimensionWithUnit(
|
|
142
|
+
wh === null ? this.getAttribute(addSizePrefix("h")) : wh,
|
|
143
|
+
);
|
|
144
|
+
const opacity = this.getAttribute(addSizePrefix("op"));
|
|
145
|
+
const zIndex = this.getAttribute(addSizePrefix("z"));
|
|
146
|
+
|
|
147
|
+
if (zIndex !== null) {
|
|
148
|
+
this._styles[size]["z-index"] = zIndex;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (opacity !== null) {
|
|
152
|
+
this._styles[size].opacity = opacity;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (width === "f") {
|
|
156
|
+
this._styles[size].width = "var(--width-stretch)";
|
|
157
|
+
} else if (width !== undefined) {
|
|
158
|
+
this._styles[size].width = width;
|
|
159
|
+
this._styles[size]["min-width"] = width;
|
|
160
|
+
this._styles[size]["max-width"] = width;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (height === "f") {
|
|
164
|
+
this._styles[size].height = "100%";
|
|
165
|
+
} else if (height !== undefined) {
|
|
166
|
+
this._styles[size].height = height;
|
|
167
|
+
this._styles[size]["min-height"] = height;
|
|
168
|
+
this._styles[size]["max-height"] = height;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (this.hasAttribute(addSizePrefix("hidden"))) {
|
|
172
|
+
this._styles[size].display = "none !important";
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (this.hasAttribute(addSizePrefix("visible"))) {
|
|
176
|
+
this._styles[size].display = "block !important";
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Update styles only if changed - targeting input element
|
|
181
|
+
const newStyleString = convertObjectToCssString(this._styles, 'input[type="color"]');
|
|
182
|
+
if (newStyleString !== this._lastStyleString) {
|
|
183
|
+
this._styleElement.textContent = newStyleString;
|
|
184
|
+
this._lastStyleString = newStyleString;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
_updateInputAttributes() {
|
|
189
|
+
const value = this.getAttribute("value");
|
|
190
|
+
const isDisabled = this.hasAttribute('disabled');
|
|
191
|
+
|
|
192
|
+
if (value !== null) {
|
|
193
|
+
this._inputElement.value = value;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (isDisabled) {
|
|
197
|
+
this._inputElement.setAttribute("disabled", "");
|
|
198
|
+
} else {
|
|
199
|
+
this._inputElement.removeAttribute("disabled");
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
connectedCallback() {
|
|
204
|
+
this._updateInputAttributes();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Export factory function to maintain API compatibility
|
|
209
|
+
export default ({ render, html }) => {
|
|
210
|
+
// Note: render and html parameters are accepted but not used
|
|
211
|
+
// This maintains backward compatibility with existing code
|
|
212
|
+
return RettangoliColorPickerElement;
|
|
213
|
+
};
|