### React Production Build Setup Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Sets up the production build of React, including error message generation and core API definitions. ```javascript var Ev;function J6(){if(Ev)return At;Ev=1;var l=Gd();function a(m){var v="https://react.dev/errors/"+m;if(1l.bindAttribLocation(s,m,h));{let h=o;h&&(h.attribs&&(h=h.attribs),Array.isArray(h)||(h=Object.keys(h)),l.transformFeedbackVaryings(s,h,d||o9))}return l.linkProgram(s),s} ``` -------------------------------- ### React useTransition Hook Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Returns a function to start a transition and a boolean indicating if a transition is in progress. ```javascript ge.useTransition=function(){return K.H.useTransition()} ``` -------------------------------- ### Manage User Settings and Synchronization Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Handles user configuration state, including precision settings and hardware acceleration, with backend synchronization. ```javascript const Re=Yd({oklchHlDecimalPrecision:1,useSimplifiedChroma:!1,oklchInputOrder:"lch",useHardwareAcceleration:!0}),xS=xe(Re,"setUserSettings",(l,a)=>{l.set(a)}),SS={syncUserSettingsWithBackend:!0},pd=xe(Re,"setUserSettingsWithSideEffects",(l,a)=>{const{key:i,newValue:u,sideEffects:o}=a,s=JSON.parse(JSON.stringify(SS));if(qt(s,o),l.setKey(i,u),s.syncUserSettingsWithBackend&&on({type:"SyncUserSettings",data:{newUserSettings:{...Re.get(),[i]:u}}}),i==="oklchHlDecimalPrecision"){if(W.get()!=="oklch"||Rt.get().show)return;yt({newColorHxya:{h:Q($.get().h,ke().h),x:Q($.get().x,ke().x),y:Q($.get().y,ke().y)}})}});se.includes("Store updates")&&et({userSettings:Re}); ``` -------------------------------- ### Get Current Event Priority Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Retrieves the current event priority. Defaults to 32 if no event is available. ```javascript function q1(){var e=V.p;return e!==0?e:(e=window.event,e===void 0?32:vv(e.type))} ``` -------------------------------- ### Initialize Color Store Management Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Sets up OkColor's store management for a given store, enabling features like mount, unmount, action, and change tracking. This is typically used when integrating OkColor with a state management system. ```javascript function T7(l,a,i,u={}){let o=u.ignoreActions||[],s=u.messages||{},d=[];return(s.mount!==!1||s.unmount!==!1)&&d.push(x7(l,a,s,i)),s.change!==!1&&d.push(S7(l,a,s,o,i)),s.action!==!1&&d.push(C7(l,a,o,i)),()=>{for(let h of d)h()}} ``` -------------------------------- ### State Management Initialization Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Initializes application state stores for Figma editor type and settings screen visibility. ```javascript const E1=Pe(null),bC=xe(E1,"setFigmaEditorType",(l,a)=>{l.set(a)});se.includes("Store updates")&&et({figmaEditorType:E1});const Ia=Pe(!1),O1=xe(Ia,"setIsSettingsScreenOpen",(l,a)=>{l.set(a)});se.includes("Store updates")&&et({isSettingsScreenOpen:Ia}); ``` -------------------------------- ### Get Current Context Value Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Retrieves the current context value, returning the provided default if no context is found. ```javascript function dv(e){return e?(e=ga,e):ga} ``` -------------------------------- ### React Initialization Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Initializes React's exports, including the core API and production-ready code. ```javascript function Gd(){return Rv||(Rv=1,Zs.exports=I6()),Zs.exports} ``` -------------------------------- ### Get Fiber by Tag Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Retrieves a Fiber node if its tag matches specific types (e.g., HostComponent, Text). ```javascript function ta(e){var t=e.tag;if(t===5||t===6||t===13||t===26||t===27||t===3)return e.stateNode;return null} ``` -------------------------------- ### Initialize Module Preload Utility Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html This IIFE sets up a MutationObserver to automatically handle modulepreload links in the document. ```javascript (function(){const a=document.createElement("link").relList;if(a&&a.supports&&a.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))u(o);new MutationObserver(o=>{for(const s of o)if(s.type==="childList")for(const d of s.addedNodes)d.tagName==="LINK"&&d.rel==="modulepreload"&&u(d)}).observe(document,{childList:!0,subtree:!0});function i(o){const s={};return o.integrity&&(s.integrity=o.integrity),o.referrerPolicy&&(s.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?s.credentials="include":o.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function u(o){if(o.ep)return;o.ep=!0;const s=i(o);fetch(o.href,s)}})(); ``` -------------------------------- ### Get Active Element Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Retrieves the currently active element in the document. Returns null if the document is not available or an error occurs. ```javascript function xi(e){if(e=e||(typeof document<"u"?document:void 0),typeof e>"u")return null;try{return e.activeElement||e.body}catch{return e.body}} ``` -------------------------------- ### Contrast Logic Utilities Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Functions for handling contrast input validation, keyboard navigation, and state updates. ```javascript function nC(l,a){const i=l.target,u=()=>{i.value=String(vn.get()),a.current=""},o=R1(i.value);if(o===null)return u();const s=An.get()==="apca"?Q(o):o,d=zt(s,Xa().negative.max,Xa().positive.max);if(d===vn.get()||a.current==="Escape"||!Ka.get()&&!["Enter","Tab"].includes(a.current))return u();a.current="",pb({newContrast:d})} ``` ```javascript function lC(l,a){let i;const u=mn.get().includes("shift"),o=An.get();let s;o==="apca"?s=u?5:1:s=u?1:.1;const d=Xa();return l==="ArrowUp"?a===d.negative.min?i=o==="apca"?0:1:i=a+s:l==="ArrowDown"&&(a===d.positive.min?i=o==="apca"?0:-1:i=a-s),Q(i,1)} ``` ```javascript function aC(l,a,i){const u=l.key,o=l.target;if(["Enter","Tab","Escape"].includes(u))a.current=u,l.target.blur();else if(["ArrowUp","ArrowDown"].includes(u)){const s=An.get()==="apca"?parseInt(o.value):parseFloat(o.value);l.preventDefault(),i.current=!0;const d=lC(u,s),h=zt(d,Xa().negative.max,Xa().positive.max);pb({newContrast:h})}} ``` ```javascript const O3=()=>{yb({newLockContrast:!$e.get()})},rC=l=>{const a=l.target.value;lS({newCurrentContrastMethod:a});const i=yl({fg:He.get().fill,bg:He.get().parentFill});T1(i)}; ``` -------------------------------- ### Get DOM Node from Fiber Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Returns the DOM node associated with a Fiber. Throws an error if the Fiber is not a host component. ```javascript function tr(e){var t=e.tag;if(t===5||t===26||t===27||t===6)return e.stateNode;throw Error(u(33))} ``` -------------------------------- ### Create Program with Shaders Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Creates a WebGL program from an array of shader sources. Handles shader compilation, linking, and attribute location binding. Supports loading shaders from strings or URLs. ```javascript const s8=(l=0)=>new Promise(a=>setTimeout(a,l));function f8(l,a,i){const u=l.createProgram();const {attribLocations:o,transformFeedbackVaryings:s,transformFeedbackMode:d}=l1(i);for(let h=0;h{for(let s of u[o])s();delete u[o],h2()},error:({actionId:o,actionName:s,error:d})=>{u[o].push(()=>Xl({message:[["bold",a],[ "regular","store handled error in action"],["bold",s]],type:"error",value:{message:d.message}}))},start:({actionId:o,actionName:s,args:d})=>{u[o]=[];let h=[["bold",a],[ "regular","store was changed by action"],["bold",s]];u[o].push(()=>d2({logo:!0,message:h,type:"action"})),d.length>0&&(h.push(["regular","with arguments" ]),u[o].push(()=>Xl({type:"arguments",value:d})))}},change:({actionId:o,changed:s,newValue:d,oldValue:h,valueMessage:m})=>{let v={logo:typeof o>"u",message:[["bold",a],[ "regular","store was changed"]],type:"change"};s&&v.message.push(["regular","in the"],["bold",s],[ "regular","key"]);let y=()=>{d2(v),m&&Xl({message:m,type:"value"}),d&&Xl({type:"new",value:d}),h&&Xl({type:"old",value:h}),h2()};o?u[o].push(y):y()}},mount:()=>{Xl({logo:!0,message:[["bold",a],[ "regular","store was mounted"]],type:"mount"})},unmount:()=>{Xl({logo:!0,message:[["bold",a],[ "regular","store was unmounted"]],type:"unmount"})}},i)} ``` -------------------------------- ### Check for WebGL Reserved Prefixes Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Determines if a variable name starts with a WebGL reserved prefix like 'gl_' or 'webgl_'. ```javascript function yy(l){const a=l.name;return a.startsWith("gl_")||a.startsWith("webgl_")} ``` -------------------------------- ### Path Initialization Helper `g4` Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Ensures that a property exists at a given path, creating it as an object or array if necessary. ```javascript function g4(l,a,i){if(a in l)return;let u=parseInt(i?? ``` -------------------------------- ### Get Transform Feedback Varyings Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Retrieves information about transform feedback varyings for a WebGL program, including their index, type, and size. ```javascript function _8(l,a){const i={},u=l.getProgramParameter(a,f9);for(let o=0;oM7(o,u,a));return()=>{for(let u of i)u()}} ``` -------------------------------- ### Get Uniform Setters Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Retrieves uniform setters for a given WebGL program. It iterates through active uniforms and creates functions to set their values. ```javascript function b8(l,a){let i=0;function u(h,m,v){const y=m.name.endsWith("[0]"),C=m.type,O=fe[C];if(!O)throw new Error(`unknown type: 0x${C.toString(16)}`);let H;if(O.bindPoint){const L=i;i+=m.size,y?H=O.arraySetter(l,C,L,v,m.size):H=O.setter(l,C,L,v,m.size)}else O.arraySetter&&y?H=O.arraySetter(l,v):H=O.setter(l,v);return H.location=v,H}const o={},s={},d=l.getProgramParameter(a,F3);for(let h=0;h>>1,_=k[I];if(0>>1;Io(Y,U))J<_&&0>o(ye,Y)?(k[I]=ye,k[J]=U,I=J):(k[I]=Y,k[Z]=U,I=Z);else if(J<_&&0>o(ye,U))k[I]=ye,k[J]=U,I=J;else break e}}return V}function o(k,V){var U=k.sortIndex-V.sortIndex;return U!==0?U:k.id-V.id}if(l.unstable_now=void 0,typeof performance=="object"&&typeof performance.now=="function"){var s=performance;l.unstable_now=function(){return s.now()}}else{var d=Date,h=d.now();l.unstable_now=function(){return d.now()-h}}var m=[],v=[],y=1,C=null,O=3,H=!1,L=!1,te=!1,j=!1,P=typeof setTimeout=="function"?setTimeout:null,G=typeof clearTimeout=="function"?clearTimeout:null,le=typeof setImmediate<"u"?setImmediate:null;function Ce(k){for(var V=i(v);V!==null;){if(V.callback===null)u(v);else if(V.startTime<=k)u(v),V.sortIndex=V.expirationTime,a(m,V);else break;V=i(v)}}function K(k){if(te=!1,Ce(k),!L)if(i(m)!==null)L=!0,me||(me=!0,Me());else{var V=i(v);V!==null&&Ie(K,V.startTime-k)}}var me=!1,de=-1,he=5,Be=-1;function Se(){return j?!0:!(l.unstable_now()-Bek&&Se());){var I=C.callback;if(typeof I=="function"){C.callback=null,O=C.priorityLevel;var _=I(C.expirationTime<=k);if(k=l.unstable_now(),typeof _=="function"){C.callback=_,Ce(k),V=!0;break t}C===i(m)&&u(m),Ce(k)}else u(m);C=i(m)}if(C!==null)V=!0;else{var D=i(v);D!==null&&Ie(K,D.startTime-k),V=!1}}break e}finally{C=null,O=U,H=!1}V=void 0}}finally{V?Me():me=!1}}}var Me;if(typeof le=="function")Me=function(){le(ne)};else if(typeof MessageChannel<"u"){var Ve=new MessageChannel,bt=Ve.port2;Ve.port1.onmessage=ne,Me=function(){bt.postMessage(null)}}else Me=function(){P(ne,0)};function Ie(k,V){de=P(function(){k(l.unstable_now())},V)}l.unstable_IdlePriority=5,l.unstable_ImmediatePriority=1,l.unstable_LowPriority=4,l.unstable_NormalPriority=3,l.unstable_Profiling=null,l.unstable_UserBlockingPriority=2,l.unstable_cancelCallback=function(k){k.callback=null},l.unstable_forceFrameRate=function(k){0>k||125{const I=GS({position:U});le.current.style.transform=`translate(${I.x}px, ${I.y}px)`},he=({position:U=Oe.get()==="triangle"?0:100}={})=>{if(at.get()==="rgb"||Oe.get()==="square"&&U<80)return;const I=document.documentElement.classList.contains("figma-dark")?75:57,_=Et({valueToMap:U,originalRange:{min:0,max:100},targetRange:{min:.01,max:.114}}),D=Et({valueToMap:U,originalRange:{min:0,max:100},targetRange:{min:I,max:60}});j.current.style.color=`oklch(${D}% ${_} ${$.get().h})`},Be=({position:U=Oe.get()==="triangle"?0:100}={})=>{W.get()==="oklch"&&at.get()==="p3"?Ce.current.setAttribute("d",qS({position:U})):Ce.current.setAttribute("d","")},Se=({position:U=Oe.get()==="triangle"?0:100}={})=>{W.get()==="oklch"&&Ye.get()?K.current.setAttribute("d",LS({position:U})):K.current.setAttribute("d","")},ne=({position:U=Oe.get()==="triangle"?0:100}={})=>{W.get()==="oklch"&&$e.get()&&He.get().parentFill&&He.get().fill?me.current.setAttribute("d",HS({position:U})):me.current.setAttribute("d","")},Me=({useHardwareAcceleration:U=Re.get().useHardwareAcceleration}={})=>{x3(!0);const I=U?M3:Cd;let _=Oe.get()==="square"?0:100;I.putImageData(yd({h:$.get().h,position:_}),0,0),U&&(P.current.classList.add("u-visibility-hidden"),G.current.classList.remove("u-visibility-hidden"));const D=30;let Z=performance.now(),Y=!1;j.current.style.transitionDuration="0.5s";const J=()=>{const ye=performance.now();if(ye-Z>=D&&(Z=ye,de({position: _}),Be({position: _}),Se({pos ``` -------------------------------- ### Get Program Linking Errors Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Retrieves and logs any errors encountered during WebGL program linking. Also attempts to retrieve information about attached shaders. ```javascript function g8(l,a,i){if(i=i||Wd,!l.getProgramParameter(a,i9)){const o=l.getProgramInfoLog(a);i(\`Error in program linking: ${o}\");const d=l.getAttachedShaders(a).map(h=>i8(l,l.getShaderParameter(h,l.SHADER_TYPE),h,i));return`${o} ${d.filter(h=>h).join(\` \`)}\`}} ``` -------------------------------- ### Initialize Fiber Node by Type Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Determines the appropriate Fiber tag and initializes a node based on the provided element type. ```javascript function Ni(e,t,n,r,c,f){var g=0;if(r=e,typeof e=="function")ro(e)&&(g=1);else if(typeof e=="string")g=z6(e,n,J.current)?26:e==="html"||e==="head"||e==="body"?27:5;else e:switch(e){case Be:return e=Qt(31,n,t,c),e.elementType=Be,e.lanes=f,e;case L:return wl(n.children,c,f,t);case te:g=8,c|=24;break;case j:return e=Qt(12,n,t,c|2),e.elementType=j,e.lanes=f,e;case K:return e=Qt(13,n,t,c),e.elementType=K,e.lanes=f,e;case me:return e=Qt(19,n,t,c),e.elementType=me,e.lanes=f,e;default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case P:case le:g=10;break e;case G:g=9;break e;case Ce:g=11;break e;case de:g=14;break e;case he:g=16,r=null;break e}g=29,n=Error(u(130,e===null?"null":typeof e,"")),r=null}return t=Qt(g,n,t,c),t.elementType=e,t.type=r,t.lanes=f,t} ``` -------------------------------- ### Create a function to get the last element of an array Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Returns a function that, when given an array, returns its last element. If the input is not an array or is empty, it returns undefined. ```javascript function l(a,i){for(var ``` -------------------------------- ### Manage Color State with nanostores Source: https://context7.com/dokozero/okcolor/llms.txt Manages reactive color state using nanostores, enabling updates with optional side effects for syncing with Figma shapes, contrast calculations, and relative chroma updates. Use this for managing dynamic color properties in an application. ```typescript import { map, action } from 'nanostores' import type { ColorHxya } from './types' // Color state store const $colorHxya = map({ h: 0, x: 0, y: 0, a: 1 }) // Update color with automatic side effects const setColorHxyaWithSideEffects = action( $colorHxya, 'setColorHxyaWithSideEffects', (colorHxya, props: { newColorHxya: Partial sideEffects?: { colorsRgba?: { syncColorsRgba?: boolean; syncContrast?: boolean } syncRelativeChroma?: boolean } lockRelativeChroma?: boolean lockContrast?: boolean }) => { const { newColorHxya, sideEffects, lockRelativeChroma, lockContrast } = props // Filter and validate new color values const filteredNewColorHxya = filterNewColorHxya({ newColorHxya, lockRelativeChroma, lockContrast }) // Update store colorHxya.set(filteredNewColorHxya) // Sync with Figma shape if (sideEffects?.colorsRgba?.syncColorsRgba !== false) { const newColorRgb = convertHxyToRgb({ colorHxy: filteredNewColorHxya }) setColorsRgbaWithSideEffects({ newColorsRgba: { fill: { ...newColorRgb, a: filteredNewColorHxya.a } } }) } // Update relative chroma if not locked if (sideEffects?.syncRelativeChroma !== false && !lockRelativeChroma) { setRelativeChroma(convertAbsoluteChromaToRelative({ colorHxy: filteredNewColorHxya })) } } ) // Usage example setColorHxyaWithSideEffects({ newColorHxya: { h: 180, x: 0.2, y: 65, a: 1 }, sideEffects: { colorsRgba: { syncColorsRgba: true, syncContrast: true }, syncRelativeChroma: true }, lockRelativeChroma: false, lockContrast: false }) ``` -------------------------------- ### Get all own enumerable property names Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Combines different methods to retrieve all own enumerable property names from an object, including symbols. This is a comprehensive approach for property enumeration. ```javascript function u(o){return i(o)?l(o,!0):a(o)} ``` -------------------------------- ### React Version Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html The current version of React. ```javascript ge.version="19.1.0" ``` -------------------------------- ### React Fiber: Get Pending Work (jm) Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Determines the pending work lanes for a given Fiber node. This function calculates which lanes need to be processed. ```javascript function jm(e,t){for(var n=e.suspendedLanes,r=e.pingedLanes,c=e.expirationTimes,f=e.pendingLanes&-62914561;0[s,d.location])),attribLocations:Object.fromEntries(Object.entries(u).map(([s,d])=>[s,d.location]))};return Jd(l)&&(o.uniformBlockSpec=x8(l,a),o.transformFeedbackInfo=_8(l,a)),o} ``` -------------------------------- ### Get own enumerable property names of an object Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Retrieves an array of an object's own enumerable property names. Handles various object types, including arrays and strings. ```javascript function m(v,y){var C=i(v),O=!C&&a(v),H=!C&&!O&&u(v),L=!C&&!O&&!H&&s(v),te=C||O||H||L,j=te?l(v.length,String):[];var P=j.length;for(var G in v)(y||h.call(v,G))&&!(te&&(G=="length"||H&&(G=="offset"||G=="parent")||L&&(G=="buffer"||G=="byteLength"||G=="byteOffset")||o(G,P)))&&j.push(G);return j} ``` -------------------------------- ### React Hook for External Store with `ue` Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html A React hook that subscribes to an external store using `useSyncExternalStore`. Requires a `get` function and optionally `keys` for selective subscriptions. ```javascript function ue(l,{keys:a,deps:i=[l,a]}={}){let u=q.useRef();u.current=l.get();let o=q.useCallback(d=>(Fs(u,d)(l.value),(a==null?void 0:a.length)>0?v4(l,a,Fs(u,d)):l.listen(Fs(u,d))),i),s=()=>u.current;return q.useSyncExternalStore(o,s,s)} ``` -------------------------------- ### Handle Stylesheet Instance Creation Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Handles the creation or retrieval of a stylesheet instance. It manages the 'hoistableStyles' cache and ensures a stylesheet element is correctly configured and added to the DOM if necessary. ```javascript function uv(e,t,n){if(t.count++,t.instance===null)switch(t.type){case"style":var r=e.querySelector('style\[data-href~="'+Pt(n.href)+'" 4 ``` -------------------------------- ### React Element Creation Utility Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Creates a React element with specified properties. Used internally for creating transitional elements. ```javascript function de(_,$1,Z,Y,J,ye){return Z=ye.ref,$$typeof:l,type:_,key:$1,ref:Z!==void 0?Z:null,props:ye} ``` -------------------------------- ### Get Uniform Block and Data Information Source: https://github.com/dokozero/okcolor/blob/main/dist/index.html Retrieves detailed information about uniform blocks and individual uniforms within a WebGL program, including block parameters and uniform data. ```javascript function x8(l,a){const i=l.getProgramParameter(a,F3),u=[];const o=l.getProgramParameter(a,d9);for(let h=0;h{kS({newCurrentColorModel:l.target.value})};function FS(){se.includes("Component renders")&&console.log("Component render — ColorModelSelect");const l=ue(W);return x.jsx("div",{className:"select-wrapper u-flex-no-shrink u-flex-basis-62",children:x.jsxs("select",{onChange:$S,name:"color_model",id:"color_model",children:[ x.jsx("option",{value:"oklch",selected:l==="oklch",children:"OkLCH"}), x.jsx("option",{value:"okhsl",selected:l==="okhsl",children:"OkHSL"}), x.jsx("option",{value:"okhsv",selected:l==="okhsv",children:"OkHSV"}) ] }) })} ```