@previewcn/devtools 0.1.0-alpha.6 → 0.1.0-alpha.8
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/index.cjs +3 -3
- package/dist/index.js +3 -3
- package/dist/styles.css +0 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var
|
|
2
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var ce=Object.defineProperty;var d=(e,o)=>()=>(e&&(o=e(e=0)),o);var de=(e,o)=>{for(var r in o)ce(e,r,{get:o[r],enumerable:true});};var $,U=d(()=>{$=[{name:"neutral",label:"Neutral",primary:{light:"oklch(0.556 0 0)",dark:"oklch(0.708 0 0)"},primaryForeground:{light:"oklch(0.985 0 0)",dark:"oklch(0.205 0 0)"}},{name:"red",label:"Red",primary:{light:"oklch(0.577 0.245 27.325)",dark:"oklch(0.637 0.237 25.331)"},primaryForeground:{light:"oklch(0.971 0.013 17.38)",dark:"oklch(0.971 0.013 17.38)"},destructive:{light:"oklch(0.505 0.213 27.518)"}},{name:"orange",label:"Orange",primary:{light:"oklch(0.646 0.222 41.116)",dark:"oklch(0.705 0.213 47.604)"},primaryForeground:{light:"oklch(0.98 0.016 73.684)",dark:"oklch(0.98 0.016 73.684)"}},{name:"amber",label:"Amber",primary:{light:"oklch(0.67 0.16 58)",dark:"oklch(0.77 0.16 70)"},primaryForeground:{light:"oklch(0.99 0.02 95)",dark:"oklch(0.28 0.07 46)"}},{name:"yellow",label:"Yellow",primary:{light:"oklch(0.852 0.199 91.936)",dark:"oklch(0.795 0.184 86.047)"},primaryForeground:{light:"oklch(0.421 0.095 57.708)",dark:"oklch(0.421 0.095 57.708)"}},{name:"lime",label:"Lime",primary:{light:"oklch(0.65 0.18 132)",dark:"oklch(0.77 0.20 131)"},primaryForeground:{light:"oklch(0.99 0.03 121)",dark:"oklch(0.27 0.07 132)"}},{name:"green",label:"Green",primary:{light:"oklch(0.648 0.2 131.684)",dark:"oklch(0.648 0.2 131.684)"},primaryForeground:{light:"oklch(0.986 0.031 120.757)",dark:"oklch(0.986 0.031 120.757)"}},{name:"emerald",label:"Emerald",primary:{light:"oklch(0.60 0.13 163)",dark:"oklch(0.70 0.15 162)"},primaryForeground:{light:"oklch(0.98 0.02 166)",dark:"oklch(0.26 0.05 173)"}},{name:"teal",label:"Teal",primary:{light:"oklch(0.60 0.10 185)",dark:"oklch(0.70 0.12 183)"},primaryForeground:{light:"oklch(0.98 0.01 181)",dark:"oklch(0.28 0.04 193)"}},{name:"cyan",label:"Cyan",primary:{light:"oklch(0.61 0.11 222)",dark:"oklch(0.71 0.13 215)"},primaryForeground:{light:"oklch(0.98 0.02 201)",dark:"oklch(0.30 0.05 230)"}},{name:"sky",label:"Sky",primary:{light:"oklch(0.59 0.14 242)",dark:"oklch(0.68 0.15 237)"},primaryForeground:{light:"oklch(0.98 0.01 237)",dark:"oklch(0.29 0.06 243)"}},{name:"blue",label:"Blue",primary:{light:"oklch(0.488 0.243 264.376)",dark:"oklch(0.42 0.18 266)"},primaryForeground:{light:"oklch(0.97 0.014 254.604)",dark:"oklch(0.97 0.014 254.604)"}},{name:"indigo",label:"Indigo",primary:{light:"oklch(0.51 0.23 277)",dark:"oklch(0.59 0.20 277)"},primaryForeground:{light:"oklch(0.96 0.02 272)",dark:"oklch(0.96 0.02 272)"}},{name:"violet",label:"Violet",primary:{light:"oklch(0.541 0.281 293.009)",dark:"oklch(0.606 0.25 292.717)"},primaryForeground:{light:"oklch(0.969 0.016 293.756)",dark:"oklch(0.969 0.016 293.756)"}},{name:"purple",label:"Purple",primary:{light:"oklch(0.56 0.25 302)",dark:"oklch(0.63 0.23 304)"},primaryForeground:{light:"oklch(0.98 0.01 308)",dark:"oklch(0.98 0.01 308)"}},{name:"fuchsia",label:"Fuchsia",primary:{light:"oklch(0.59 0.26 323)",dark:"oklch(0.67 0.26 322)"},primaryForeground:{light:"oklch(0.98 0.02 320)",dark:"oklch(0.98 0.02 320)"}},{name:"pink",label:"Pink",primary:{light:"oklch(0.59 0.22 1)",dark:"oklch(0.66 0.21 354)"},primaryForeground:{light:"oklch(0.97 0.01 343)",dark:"oklch(0.97 0.01 343)"}},{name:"rose",label:"Rose",primary:{light:"oklch(0.586 0.253 17.585)",dark:"oklch(0.645 0.246 16.439)"},primaryForeground:{light:"oklch(0.969 0.015 12.422)",dark:"oklch(0.969 0.015 12.422)"}}];});function ue(e){return {name:e.name,label:e.label,colors:{light:{..._.light,primary:e.primary.light,"primary-foreground":e.primaryForeground?.light??H.light,destructive:e.destructive?.light??W.light},dark:{..._.dark,primary:e.primary.dark,"primary-foreground":e.primaryForeground?.dark??H.dark,destructive:e.destructive?.dark??W.dark}}}}function J(e){return N.find(o=>o.name===e)}var _,W,H,N,T=d(()=>{U();_={light:{background:"oklch(1 0 0)",foreground:"oklch(0.145 0 0)",card:"oklch(1 0 0)","card-foreground":"oklch(0.145 0 0)",popover:"oklch(1 0 0)","popover-foreground":"oklch(0.145 0 0)",secondary:"oklch(0.97 0 0)","secondary-foreground":"oklch(0.205 0 0)",muted:"oklch(0.97 0 0)","muted-foreground":"oklch(0.556 0 0)",accent:"oklch(0.97 0 0)","accent-foreground":"oklch(0.205 0 0)",border:"oklch(0.922 0 0)",input:"oklch(0.922 0 0)",ring:"oklch(0.708 0 0)"},dark:{background:"oklch(0.145 0 0)",foreground:"oklch(0.985 0 0)",card:"oklch(0.205 0 0)","card-foreground":"oklch(0.985 0 0)",popover:"oklch(0.205 0 0)","popover-foreground":"oklch(0.985 0 0)",secondary:"oklch(0.269 0 0)","secondary-foreground":"oklch(0.985 0 0)",muted:"oklch(0.269 0 0)","muted-foreground":"oklch(0.708 0 0)",accent:"oklch(0.269 0 0)","accent-foreground":"oklch(0.985 0 0)",border:"oklch(1 0 0 / 10%)",input:"oklch(1 0 0 / 15%)",ring:"oklch(0.556 0 0)"}},W={light:"oklch(0.577 0.245 27.325)",dark:"oklch(0.704 0.191 22.216)"},H={light:"oklch(0.985 0 0)",dark:"oklch(0.985 0 0)"};N=$.map(ue);});function V(e){return v.find(o=>o.value===e)}var v,E=d(()=>{v=[{label:"Inter",value:"inter",fontFamily:'"Inter", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"},{label:"Noto Sans",value:"noto-sans",fontFamily:'"Noto Sans", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;500;600;700&display=swap"},{label:"Nunito Sans",value:"nunito-sans",fontFamily:'"Nunito Sans", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@400;500;600;700&display=swap"},{label:"Figtree",value:"figtree",fontFamily:'"Figtree", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700&display=swap"},{label:"Roboto",value:"roboto",fontFamily:'"Roboto", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap"},{label:"Raleway",value:"raleway",fontFamily:'"Raleway", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600;700&display=swap"},{label:"DM Sans",value:"dm-sans",fontFamily:'"DM Sans", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap"},{label:"Public Sans",value:"public-sans",fontFamily:'"Public Sans", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Public+Sans:wght@400;500;600;700&display=swap"},{label:"Outfit",value:"outfit",fontFamily:'"Outfit", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&display=swap"},{label:"JetBrains Mono",value:"jetbrains-mono",fontFamily:'"JetBrains Mono", monospace',googleFontsUrl:"https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap"}];});function ge(){let e=document.getElementById(M);if(e instanceof HTMLStyleElement)return e;e&&e.remove();let o=document.createElement("style");return o.id=M,document.head.appendChild(o),o}function Y(e){return Object.entries(e).map(([o,r])=>`--${o}: ${r};`).join(" ")}function y(e){let o=document.documentElement;e?(o.classList.remove("light"),o.classList.add("dark")):(o.classList.remove("dark"),o.classList.add("light")),o.style.colorScheme=e?"dark":"light";}function w(e){document.documentElement.style.setProperty("--radius",e);}function b(e){let o=J(e);if(!o)return;let r=ge(),l=Y(o.colors.light),s=Y(o.colors.dark);r.textContent=`:root { ${l} } .dark { ${s} }`;}function he(){let e=document.getElementById(R);if(e instanceof HTMLStyleElement)return e;e&&e.remove();let o=document.createElement("style");return o.id=R,document.head.appendChild(o),o}function C(e){let o=V(e);if(!o)return;let{fontFamily:r,googleFontsUrl:l}=o;if(!l.startsWith("https://fonts.googleapis.com/")){console.warn("[PreviewCN] Invalid font URL");return}let s=`previewcn-font-${e}`;if(!document.getElementById(s)){let n=document.createElement("link");n.id=s,n.rel="stylesheet",n.href=l,document.head.appendChild(n);}let p=he();p.textContent=`
|
|
3
3
|
:root {
|
|
4
4
|
--font-sans: ${r} !important;
|
|
5
5
|
--font-sans-override: ${r} !important;
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
html, body, .font-sans {
|
|
9
9
|
font-family: ${r} !important;
|
|
10
10
|
}
|
|
11
|
-
`;}function
|
|
12
|
-
exports.PreviewcnDevtools=
|
|
11
|
+
`;}function L(e){e.colorPreset!==null&&b(e.colorPreset),e.radius!==null&&w(e.radius),e.darkMode!==null&&y(e.darkMode),e.font!==null&&C(e.font);}function z(){let e=document.getElementById(M);e&&e.remove();let o=document.getElementById(R);o&&o.remove();let r=document.documentElement;r.style.removeProperty("--radius"),r.style.removeProperty("color-scheme"),r.classList.remove("light","dark");}var M,R,P=d(()=>{T();E();M="previewcn-devtools-theme-colors",R="previewcn-devtools-theme-font";});function fe(){if(typeof window>"u")return {};try{let e=localStorage.getItem(I);if(e)return JSON.parse(e)}catch{}return {}}function F(e){if(!(typeof window>"u"))try{localStorage.setItem(I,JSON.stringify(e));}catch{}}function G(){let[e,o]=react.useState(()=>({...A,...fe()})),r=react.useCallback(i=>{o(m=>{let c={...m,colorPreset:i};return F(c),c}),b(i);},[]),l=react.useCallback(i=>{o(m=>{let c={...m,radius:i};return F(c),c}),w(i);},[]),s=react.useCallback(i=>{o(m=>{let c={...m,darkMode:i};return F(c),c}),y(i);},[]),p=react.useCallback(i=>{o(m=>{let c={...m,font:i};return F(c),c}),C(i);},[]),n=react.useCallback(()=>{typeof window<"u"&&localStorage.removeItem(I),z(),o(A);},[]);return {config:e,setColorPreset:r,setRadius:l,setDarkMode:s,setFont:p,resetTheme:n}}var I,A,j=d(()=>{"use client";P();I="previewcn-devtools-theme";A={colorPreset:null,radius:null,darkMode:null,font:null};});function K({value:e,onChange:o}){return jsxRuntime.jsxs("div",{className:"previewcn-section",children:[jsxRuntime.jsx("label",{className:"previewcn-label",children:"Color"}),jsxRuntime.jsx("div",{className:"previewcn-color-grid",children:N.map(r=>{let l=e===r.name,s=r.colors.light.primary;return jsxRuntime.jsx("button",{onClick:()=>o(r.name),className:`previewcn-color-swatch ${l?"previewcn-color-swatch--selected":""}`,style:{backgroundColor:s},"aria-label":r.label,title:r.label},r.name)})})]})}var X=d(()=>{"use client";T();});function we(){return jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"m6 9 6 6 6-6"})})}function Z({value:e,onChange:o}){let[r,l]=react.useState(false),p=v.find(n=>n.value===e)?.label??"Select font...";return jsxRuntime.jsxs("div",{className:"previewcn-section",children:[jsxRuntime.jsx("label",{className:"previewcn-label",children:"Font"}),jsxRuntime.jsxs("div",{className:"previewcn-select-wrapper",children:[jsxRuntime.jsxs("button",{onClick:()=>l(!r),className:"previewcn-select-trigger","aria-expanded":r,children:[jsxRuntime.jsx("span",{children:p}),jsxRuntime.jsx(we,{})]}),r&&jsxRuntime.jsx("div",{className:"previewcn-select-dropdown",children:v.map(n=>jsxRuntime.jsx("button",{onClick:()=>{o(n.value),l(false);},className:`previewcn-select-option ${e===n.value?"previewcn-select-option--selected":""}`,children:n.label},n.value))})]})]})}var q=d(()=>{"use client";E();});function be(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("circle",{cx:"12",cy:"12",r:"4"}),jsxRuntime.jsx("path",{d:"M12 2v2"}),jsxRuntime.jsx("path",{d:"M12 20v2"}),jsxRuntime.jsx("path",{d:"m4.93 4.93 1.41 1.41"}),jsxRuntime.jsx("path",{d:"m17.66 17.66 1.41 1.41"}),jsxRuntime.jsx("path",{d:"M2 12h2"}),jsxRuntime.jsx("path",{d:"M20 12h2"}),jsxRuntime.jsx("path",{d:"m6.34 17.66-1.41 1.41"}),jsxRuntime.jsx("path",{d:"m19.07 4.93-1.41 1.41"})]})}function Ce(){return jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})}function Q({value:e,onChange:o}){let r=e??false;return jsxRuntime.jsxs("div",{className:"previewcn-section",children:[jsxRuntime.jsx("label",{className:"previewcn-label",children:"Mode"}),jsxRuntime.jsxs("div",{className:"previewcn-mode-toggle",children:[jsxRuntime.jsxs("button",{onClick:()=>o(false),className:`previewcn-mode-btn ${r?"":"previewcn-mode-btn--selected"}`,"aria-label":"Light mode",children:[jsxRuntime.jsx(be,{}),jsxRuntime.jsx("span",{children:"Light"})]}),jsxRuntime.jsxs("button",{onClick:()=>o(true),className:`previewcn-mode-btn ${r?"previewcn-mode-btn--selected":""}`,"aria-label":"Dark mode",children:[jsxRuntime.jsx(Ce,{}),jsxRuntime.jsx("span",{children:"Dark"})]})]})]})}var ee=d(()=>{"use client";});var oe,re=d(()=>{oe=[{name:"none",label:"None",value:"0rem"},{name:"sm",label:"SM",value:"0.3rem"},{name:"md",label:"MD",value:"0.5rem"},{name:"lg",label:"LG",value:"0.625rem"},{name:"xl",label:"XL",value:"0.75rem"},{name:"full",label:"Full",value:"1rem"}];});function le({value:e,onChange:o}){return jsxRuntime.jsxs("div",{className:"previewcn-section",children:[jsxRuntime.jsx("label",{className:"previewcn-label",children:"Radius"}),jsxRuntime.jsx("div",{className:"previewcn-radius-grid",children:oe.map(r=>{let l=e===r.value;return jsxRuntime.jsxs("button",{onClick:()=>o(r.value),className:`previewcn-radius-btn ${l?"previewcn-radius-btn--selected":""}`,title:r.label,children:[jsxRuntime.jsx("span",{className:"previewcn-radius-preview",style:{borderRadius:r.value}}),jsxRuntime.jsx("span",{className:"previewcn-radius-label",children:r.label})]},r.name)})})]})}var ne=d(()=>{"use client";re();});var ie={};de(ie,{default:()=>ae});function Se(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M18 6 6 18"}),jsxRuntime.jsx("path",{d:"m6 6 12 12"})]})}function xe(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),jsxRuntime.jsx("path",{d:"M3 3v5h5"})]})}function ae({onClose:e}){let{config:o,setColorPreset:r,setRadius:l,setDarkMode:s,setFont:p,resetTheme:n}=G(),i=react.useRef(false);return react.useEffect(()=>{i.current||(i.current=true,L(o));},[o]),jsxRuntime.jsxs("div",{className:"previewcn-panel",children:[jsxRuntime.jsxs("div",{className:"previewcn-header",children:[jsxRuntime.jsxs("div",{className:"previewcn-title",children:[jsxRuntime.jsx("span",{className:"previewcn-logo",children:"PreviewCN"}),jsxRuntime.jsx("span",{className:"previewcn-badge",children:"DEV"})]}),jsxRuntime.jsx("button",{onClick:e,className:"previewcn-close-btn","aria-label":"Close",children:jsxRuntime.jsx(Se,{})})]}),jsxRuntime.jsxs("div",{className:"previewcn-content",children:[jsxRuntime.jsx(K,{value:o.colorPreset,onChange:r}),jsxRuntime.jsx(le,{value:o.radius,onChange:l}),jsxRuntime.jsx(Z,{value:o.font,onChange:p}),jsxRuntime.jsx(Q,{value:o.darkMode,onChange:s})]}),jsxRuntime.jsx("div",{className:"previewcn-footer",children:jsxRuntime.jsxs("button",{onClick:n,className:"previewcn-reset-btn",children:[jsxRuntime.jsx(xe,{}),jsxRuntime.jsx("span",{children:"Reset"})]})})]})}var se=d(()=>{"use client";j();P();X();q();ee();ne();});function pe(){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor"}),jsxRuntime.jsx("circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor"}),jsxRuntime.jsx("circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor"}),jsxRuntime.jsx("circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor"}),jsxRuntime.jsx("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.555C21.965 6.012 17.461 2 12 2z"})]})}function B({onClick:e}){return jsxRuntime.jsx("button",{onClick:e,className:"previewcn-trigger","aria-label":"Open PreviewCN theme editor",title:"PreviewCN Theme Editor",children:jsxRuntime.jsx(pe,{})})}var Me=react.lazy(()=>Promise.resolve().then(()=>(se(),ie))),Re=process.env.NODE_ENV==="development";function Le(){let[e,o]=react.useState(false);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!e&&jsxRuntime.jsx(B,{onClick:()=>o(true)}),e&&jsxRuntime.jsx(react.Suspense,{fallback:null,children:jsxRuntime.jsx(Me,{onClose:()=>o(false)})})]})}function Ie(){return Re?jsxRuntime.jsx(Le,{}):null}P();
|
|
12
|
+
exports.PreviewcnDevtools=Ie;exports.applyColors=b;exports.applyDarkMode=y;exports.applyFont=C;exports.applyRadius=w;exports.applyTheme=L;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {lazy,useRef,useEffect,useCallback,
|
|
2
|
+
import {lazy,useRef,useEffect,useState,useCallback,Suspense}from'react';import {jsxs,jsx,Fragment}from'react/jsx-runtime';var ce=Object.defineProperty;var d=(e,o)=>()=>(e&&(o=e(e=0)),o);var de=(e,o)=>{for(var r in o)ce(e,r,{get:o[r],enumerable:true});};var $,U=d(()=>{$=[{name:"neutral",label:"Neutral",primary:{light:"oklch(0.556 0 0)",dark:"oklch(0.708 0 0)"},primaryForeground:{light:"oklch(0.985 0 0)",dark:"oklch(0.205 0 0)"}},{name:"red",label:"Red",primary:{light:"oklch(0.577 0.245 27.325)",dark:"oklch(0.637 0.237 25.331)"},primaryForeground:{light:"oklch(0.971 0.013 17.38)",dark:"oklch(0.971 0.013 17.38)"},destructive:{light:"oklch(0.505 0.213 27.518)"}},{name:"orange",label:"Orange",primary:{light:"oklch(0.646 0.222 41.116)",dark:"oklch(0.705 0.213 47.604)"},primaryForeground:{light:"oklch(0.98 0.016 73.684)",dark:"oklch(0.98 0.016 73.684)"}},{name:"amber",label:"Amber",primary:{light:"oklch(0.67 0.16 58)",dark:"oklch(0.77 0.16 70)"},primaryForeground:{light:"oklch(0.99 0.02 95)",dark:"oklch(0.28 0.07 46)"}},{name:"yellow",label:"Yellow",primary:{light:"oklch(0.852 0.199 91.936)",dark:"oklch(0.795 0.184 86.047)"},primaryForeground:{light:"oklch(0.421 0.095 57.708)",dark:"oklch(0.421 0.095 57.708)"}},{name:"lime",label:"Lime",primary:{light:"oklch(0.65 0.18 132)",dark:"oklch(0.77 0.20 131)"},primaryForeground:{light:"oklch(0.99 0.03 121)",dark:"oklch(0.27 0.07 132)"}},{name:"green",label:"Green",primary:{light:"oklch(0.648 0.2 131.684)",dark:"oklch(0.648 0.2 131.684)"},primaryForeground:{light:"oklch(0.986 0.031 120.757)",dark:"oklch(0.986 0.031 120.757)"}},{name:"emerald",label:"Emerald",primary:{light:"oklch(0.60 0.13 163)",dark:"oklch(0.70 0.15 162)"},primaryForeground:{light:"oklch(0.98 0.02 166)",dark:"oklch(0.26 0.05 173)"}},{name:"teal",label:"Teal",primary:{light:"oklch(0.60 0.10 185)",dark:"oklch(0.70 0.12 183)"},primaryForeground:{light:"oklch(0.98 0.01 181)",dark:"oklch(0.28 0.04 193)"}},{name:"cyan",label:"Cyan",primary:{light:"oklch(0.61 0.11 222)",dark:"oklch(0.71 0.13 215)"},primaryForeground:{light:"oklch(0.98 0.02 201)",dark:"oklch(0.30 0.05 230)"}},{name:"sky",label:"Sky",primary:{light:"oklch(0.59 0.14 242)",dark:"oklch(0.68 0.15 237)"},primaryForeground:{light:"oklch(0.98 0.01 237)",dark:"oklch(0.29 0.06 243)"}},{name:"blue",label:"Blue",primary:{light:"oklch(0.488 0.243 264.376)",dark:"oklch(0.42 0.18 266)"},primaryForeground:{light:"oklch(0.97 0.014 254.604)",dark:"oklch(0.97 0.014 254.604)"}},{name:"indigo",label:"Indigo",primary:{light:"oklch(0.51 0.23 277)",dark:"oklch(0.59 0.20 277)"},primaryForeground:{light:"oklch(0.96 0.02 272)",dark:"oklch(0.96 0.02 272)"}},{name:"violet",label:"Violet",primary:{light:"oklch(0.541 0.281 293.009)",dark:"oklch(0.606 0.25 292.717)"},primaryForeground:{light:"oklch(0.969 0.016 293.756)",dark:"oklch(0.969 0.016 293.756)"}},{name:"purple",label:"Purple",primary:{light:"oklch(0.56 0.25 302)",dark:"oklch(0.63 0.23 304)"},primaryForeground:{light:"oklch(0.98 0.01 308)",dark:"oklch(0.98 0.01 308)"}},{name:"fuchsia",label:"Fuchsia",primary:{light:"oklch(0.59 0.26 323)",dark:"oklch(0.67 0.26 322)"},primaryForeground:{light:"oklch(0.98 0.02 320)",dark:"oklch(0.98 0.02 320)"}},{name:"pink",label:"Pink",primary:{light:"oklch(0.59 0.22 1)",dark:"oklch(0.66 0.21 354)"},primaryForeground:{light:"oklch(0.97 0.01 343)",dark:"oklch(0.97 0.01 343)"}},{name:"rose",label:"Rose",primary:{light:"oklch(0.586 0.253 17.585)",dark:"oklch(0.645 0.246 16.439)"},primaryForeground:{light:"oklch(0.969 0.015 12.422)",dark:"oklch(0.969 0.015 12.422)"}}];});function ue(e){return {name:e.name,label:e.label,colors:{light:{..._.light,primary:e.primary.light,"primary-foreground":e.primaryForeground?.light??H.light,destructive:e.destructive?.light??W.light},dark:{..._.dark,primary:e.primary.dark,"primary-foreground":e.primaryForeground?.dark??H.dark,destructive:e.destructive?.dark??W.dark}}}}function J(e){return N.find(o=>o.name===e)}var _,W,H,N,T=d(()=>{U();_={light:{background:"oklch(1 0 0)",foreground:"oklch(0.145 0 0)",card:"oklch(1 0 0)","card-foreground":"oklch(0.145 0 0)",popover:"oklch(1 0 0)","popover-foreground":"oklch(0.145 0 0)",secondary:"oklch(0.97 0 0)","secondary-foreground":"oklch(0.205 0 0)",muted:"oklch(0.97 0 0)","muted-foreground":"oklch(0.556 0 0)",accent:"oklch(0.97 0 0)","accent-foreground":"oklch(0.205 0 0)",border:"oklch(0.922 0 0)",input:"oklch(0.922 0 0)",ring:"oklch(0.708 0 0)"},dark:{background:"oklch(0.145 0 0)",foreground:"oklch(0.985 0 0)",card:"oklch(0.205 0 0)","card-foreground":"oklch(0.985 0 0)",popover:"oklch(0.205 0 0)","popover-foreground":"oklch(0.985 0 0)",secondary:"oklch(0.269 0 0)","secondary-foreground":"oklch(0.985 0 0)",muted:"oklch(0.269 0 0)","muted-foreground":"oklch(0.708 0 0)",accent:"oklch(0.269 0 0)","accent-foreground":"oklch(0.985 0 0)",border:"oklch(1 0 0 / 10%)",input:"oklch(1 0 0 / 15%)",ring:"oklch(0.556 0 0)"}},W={light:"oklch(0.577 0.245 27.325)",dark:"oklch(0.704 0.191 22.216)"},H={light:"oklch(0.985 0 0)",dark:"oklch(0.985 0 0)"};N=$.map(ue);});function V(e){return v.find(o=>o.value===e)}var v,E=d(()=>{v=[{label:"Inter",value:"inter",fontFamily:'"Inter", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"},{label:"Noto Sans",value:"noto-sans",fontFamily:'"Noto Sans", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;500;600;700&display=swap"},{label:"Nunito Sans",value:"nunito-sans",fontFamily:'"Nunito Sans", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@400;500;600;700&display=swap"},{label:"Figtree",value:"figtree",fontFamily:'"Figtree", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700&display=swap"},{label:"Roboto",value:"roboto",fontFamily:'"Roboto", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap"},{label:"Raleway",value:"raleway",fontFamily:'"Raleway", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Raleway:wght@400;500;600;700&display=swap"},{label:"DM Sans",value:"dm-sans",fontFamily:'"DM Sans", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap"},{label:"Public Sans",value:"public-sans",fontFamily:'"Public Sans", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Public+Sans:wght@400;500;600;700&display=swap"},{label:"Outfit",value:"outfit",fontFamily:'"Outfit", sans-serif',googleFontsUrl:"https://fonts.googleapis.com/css2?family=Outfit:wght@400;500;600;700&display=swap"},{label:"JetBrains Mono",value:"jetbrains-mono",fontFamily:'"JetBrains Mono", monospace',googleFontsUrl:"https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap"}];});function ge(){let e=document.getElementById(M);if(e instanceof HTMLStyleElement)return e;e&&e.remove();let o=document.createElement("style");return o.id=M,document.head.appendChild(o),o}function Y(e){return Object.entries(e).map(([o,r])=>`--${o}: ${r};`).join(" ")}function y(e){let o=document.documentElement;e?(o.classList.remove("light"),o.classList.add("dark")):(o.classList.remove("dark"),o.classList.add("light")),o.style.colorScheme=e?"dark":"light";}function w(e){document.documentElement.style.setProperty("--radius",e);}function b(e){let o=J(e);if(!o)return;let r=ge(),l=Y(o.colors.light),s=Y(o.colors.dark);r.textContent=`:root { ${l} } .dark { ${s} }`;}function he(){let e=document.getElementById(R);if(e instanceof HTMLStyleElement)return e;e&&e.remove();let o=document.createElement("style");return o.id=R,document.head.appendChild(o),o}function C(e){let o=V(e);if(!o)return;let{fontFamily:r,googleFontsUrl:l}=o;if(!l.startsWith("https://fonts.googleapis.com/")){console.warn("[PreviewCN] Invalid font URL");return}let s=`previewcn-font-${e}`;if(!document.getElementById(s)){let n=document.createElement("link");n.id=s,n.rel="stylesheet",n.href=l,document.head.appendChild(n);}let p=he();p.textContent=`
|
|
3
3
|
:root {
|
|
4
4
|
--font-sans: ${r} !important;
|
|
5
5
|
--font-sans-override: ${r} !important;
|
|
@@ -8,5 +8,5 @@ import {lazy,useRef,useEffect,useCallback,useState,Suspense}from'react';import {
|
|
|
8
8
|
html, body, .font-sans {
|
|
9
9
|
font-family: ${r} !important;
|
|
10
10
|
}
|
|
11
|
-
`;}function
|
|
12
|
-
export{
|
|
11
|
+
`;}function L(e){e.colorPreset!==null&&b(e.colorPreset),e.radius!==null&&w(e.radius),e.darkMode!==null&&y(e.darkMode),e.font!==null&&C(e.font);}function z(){let e=document.getElementById(M);e&&e.remove();let o=document.getElementById(R);o&&o.remove();let r=document.documentElement;r.style.removeProperty("--radius"),r.style.removeProperty("color-scheme"),r.classList.remove("light","dark");}var M,R,P=d(()=>{T();E();M="previewcn-devtools-theme-colors",R="previewcn-devtools-theme-font";});function fe(){if(typeof window>"u")return {};try{let e=localStorage.getItem(I);if(e)return JSON.parse(e)}catch{}return {}}function F(e){if(!(typeof window>"u"))try{localStorage.setItem(I,JSON.stringify(e));}catch{}}function G(){let[e,o]=useState(()=>({...A,...fe()})),r=useCallback(i=>{o(m=>{let c={...m,colorPreset:i};return F(c),c}),b(i);},[]),l=useCallback(i=>{o(m=>{let c={...m,radius:i};return F(c),c}),w(i);},[]),s=useCallback(i=>{o(m=>{let c={...m,darkMode:i};return F(c),c}),y(i);},[]),p=useCallback(i=>{o(m=>{let c={...m,font:i};return F(c),c}),C(i);},[]),n=useCallback(()=>{typeof window<"u"&&localStorage.removeItem(I),z(),o(A);},[]);return {config:e,setColorPreset:r,setRadius:l,setDarkMode:s,setFont:p,resetTheme:n}}var I,A,j=d(()=>{"use client";P();I="previewcn-devtools-theme";A={colorPreset:null,radius:null,darkMode:null,font:null};});function K({value:e,onChange:o}){return jsxs("div",{className:"previewcn-section",children:[jsx("label",{className:"previewcn-label",children:"Color"}),jsx("div",{className:"previewcn-color-grid",children:N.map(r=>{let l=e===r.name,s=r.colors.light.primary;return jsx("button",{onClick:()=>o(r.name),className:`previewcn-color-swatch ${l?"previewcn-color-swatch--selected":""}`,style:{backgroundColor:s},"aria-label":r.label,title:r.label},r.name)})})]})}var X=d(()=>{"use client";T();});function we(){return jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"m6 9 6 6 6-6"})})}function Z({value:e,onChange:o}){let[r,l]=useState(false),p=v.find(n=>n.value===e)?.label??"Select font...";return jsxs("div",{className:"previewcn-section",children:[jsx("label",{className:"previewcn-label",children:"Font"}),jsxs("div",{className:"previewcn-select-wrapper",children:[jsxs("button",{onClick:()=>l(!r),className:"previewcn-select-trigger","aria-expanded":r,children:[jsx("span",{children:p}),jsx(we,{})]}),r&&jsx("div",{className:"previewcn-select-dropdown",children:v.map(n=>jsx("button",{onClick:()=>{o(n.value),l(false);},className:`previewcn-select-option ${e===n.value?"previewcn-select-option--selected":""}`,children:n.label},n.value))})]})]})}var q=d(()=>{"use client";E();});function be(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("circle",{cx:"12",cy:"12",r:"4"}),jsx("path",{d:"M12 2v2"}),jsx("path",{d:"M12 20v2"}),jsx("path",{d:"m4.93 4.93 1.41 1.41"}),jsx("path",{d:"m17.66 17.66 1.41 1.41"}),jsx("path",{d:"M2 12h2"}),jsx("path",{d:"M20 12h2"}),jsx("path",{d:"m6.34 17.66-1.41 1.41"}),jsx("path",{d:"m19.07 4.93-1.41 1.41"})]})}function Ce(){return jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"})})}function Q({value:e,onChange:o}){let r=e??false;return jsxs("div",{className:"previewcn-section",children:[jsx("label",{className:"previewcn-label",children:"Mode"}),jsxs("div",{className:"previewcn-mode-toggle",children:[jsxs("button",{onClick:()=>o(false),className:`previewcn-mode-btn ${r?"":"previewcn-mode-btn--selected"}`,"aria-label":"Light mode",children:[jsx(be,{}),jsx("span",{children:"Light"})]}),jsxs("button",{onClick:()=>o(true),className:`previewcn-mode-btn ${r?"previewcn-mode-btn--selected":""}`,"aria-label":"Dark mode",children:[jsx(Ce,{}),jsx("span",{children:"Dark"})]})]})]})}var ee=d(()=>{"use client";});var oe,re=d(()=>{oe=[{name:"none",label:"None",value:"0rem"},{name:"sm",label:"SM",value:"0.3rem"},{name:"md",label:"MD",value:"0.5rem"},{name:"lg",label:"LG",value:"0.625rem"},{name:"xl",label:"XL",value:"0.75rem"},{name:"full",label:"Full",value:"1rem"}];});function le({value:e,onChange:o}){return jsxs("div",{className:"previewcn-section",children:[jsx("label",{className:"previewcn-label",children:"Radius"}),jsx("div",{className:"previewcn-radius-grid",children:oe.map(r=>{let l=e===r.value;return jsxs("button",{onClick:()=>o(r.value),className:`previewcn-radius-btn ${l?"previewcn-radius-btn--selected":""}`,title:r.label,children:[jsx("span",{className:"previewcn-radius-preview",style:{borderRadius:r.value}}),jsx("span",{className:"previewcn-radius-label",children:r.label})]},r.name)})})]})}var ne=d(()=>{"use client";re();});var ie={};de(ie,{default:()=>ae});function Se(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M18 6 6 18"}),jsx("path",{d:"m6 6 12 12"})]})}function xe(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),jsx("path",{d:"M3 3v5h5"})]})}function ae({onClose:e}){let{config:o,setColorPreset:r,setRadius:l,setDarkMode:s,setFont:p,resetTheme:n}=G(),i=useRef(false);return useEffect(()=>{i.current||(i.current=true,L(o));},[o]),jsxs("div",{className:"previewcn-panel",children:[jsxs("div",{className:"previewcn-header",children:[jsxs("div",{className:"previewcn-title",children:[jsx("span",{className:"previewcn-logo",children:"PreviewCN"}),jsx("span",{className:"previewcn-badge",children:"DEV"})]}),jsx("button",{onClick:e,className:"previewcn-close-btn","aria-label":"Close",children:jsx(Se,{})})]}),jsxs("div",{className:"previewcn-content",children:[jsx(K,{value:o.colorPreset,onChange:r}),jsx(le,{value:o.radius,onChange:l}),jsx(Z,{value:o.font,onChange:p}),jsx(Q,{value:o.darkMode,onChange:s})]}),jsx("div",{className:"previewcn-footer",children:jsxs("button",{onClick:n,className:"previewcn-reset-btn",children:[jsx(xe,{}),jsx("span",{children:"Reset"})]})})]})}var se=d(()=>{"use client";j();P();X();q();ee();ne();});function pe(){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor"}),jsx("circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor"}),jsx("circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor"}),jsx("circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor"}),jsx("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.555C21.965 6.012 17.461 2 12 2z"})]})}function B({onClick:e}){return jsx("button",{onClick:e,className:"previewcn-trigger","aria-label":"Open PreviewCN theme editor",title:"PreviewCN Theme Editor",children:jsx(pe,{})})}var Me=lazy(()=>Promise.resolve().then(()=>(se(),ie))),Re=process.env.NODE_ENV==="development";function Le(){let[e,o]=useState(false);return jsxs(Fragment,{children:[!e&&jsx(B,{onClick:()=>o(true)}),e&&jsx(Suspense,{fallback:null,children:jsx(Me,{onClose:()=>o(false)})})]})}function Ie(){return Re?jsx(Le,{}):null}P();
|
|
12
|
+
export{Ie as PreviewcnDevtools,b as applyColors,y as applyDarkMode,C as applyFont,w as applyRadius,L as applyTheme};
|
package/dist/styles.css
CHANGED
|
@@ -229,11 +229,6 @@
|
|
|
229
229
|
outline: 2px solid oklch(0.7 0.12 260);
|
|
230
230
|
outline-offset: 2px;
|
|
231
231
|
}
|
|
232
|
-
.previewcn-backdrop {
|
|
233
|
-
position: fixed;
|
|
234
|
-
inset: calc(var(--spacing) * 0);
|
|
235
|
-
z-index: 99998;
|
|
236
|
-
}
|
|
237
232
|
.previewcn-panel {
|
|
238
233
|
position: fixed;
|
|
239
234
|
top: calc(var(--spacing) * 0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@previewcn/devtools",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.8",
|
|
4
4
|
"description": "Embedded devtools for PreviewCN - real-time shadcn/ui theme preview inside your app",
|
|
5
5
|
"keywords": ["shadcn", "shadcn-ui", "theme", "preview", "devtools", "react", "tailwind"],
|
|
6
6
|
"license": "MIT",
|