{"version":3,"file":"LibraryShuffle.HC8GhAAF.mjs","names":["useSyncExternalStore","useContext","useState"],"sources":["https:/framerusercontent.com/modules/EGuzKly2SAjSdZyYh6Z9/osLt9VqL8nfgwBHm4mzO/LibraryShuffle.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{addPropertyControls,ControlType}from\"framer\";import{createContext,useContext,useEffect,useState,useSyncExternalStore}from\"react\";// Library grid behaviour:\n// - shuffles the grid on every page load and reveals it 25 at a time\n// - companies added in the last 24 hours (\"Added On\") get a NEW tag and are\n//   placed first, right after the pinned Editor's Picks\n// - a text override shows \"+N new companies added today\"\n// Nothing reads the DOM: items share state through this module and React context.\nconst PAGE_SIZE=25;const NEW_WINDOW_MS=24*60*60*1e3;const store={keys:new Map,newTags:new Set,allCompanies:new Set,allNew:new Set,visible:PAGE_SIZE,version:0,listeners:new Set};function emit(){store.version++;store.listeners.forEach(listener=>listener());}function subscribe(listener){store.listeners.add(listener);return()=>{store.listeners.delete(listener);};}const getVersion=()=>store.version;const getServerVersion=()=>0;function useStore(){return useSyncExternalStore(subscribe,getVersion,getServerVersion);}let nextId=0;/** Lets a NEW tag inside a grid item tell that item it is new. */const ItemContext=/*#__PURE__*/createContext(null);function isWithinWindow(addedOn){if(!addedOn)return false;const time=Date.parse(addedOn);if(Number.isNaN(time))return false;const age=Date.now()-time;return age>=-NEW_WINDOW_MS&&age<NEW_WINDOW_MS;}/** Apply to the repeated item inside the Library's CMS grid. */export function withShuffledItem(Component){return props=>{useStore();const[id]=useState(()=>nextId++);const[key,setKey]=useState(null);const[isNew,setIsNew]=useState(false);useEffect(()=>{setKey(Math.random());return()=>{store.keys.delete(id);emit();};},[id]);// New companies sort before everyone else (keys below 0).\nuseEffect(()=>{if(key===null)return;store.keys.set(id,isNew?key-1:key);emit();},[id,key,isNew]);if(key===null){return /*#__PURE__*/_jsx(ItemContext.Provider,{value:setIsNew,children:/*#__PURE__*/_jsx(Component,{...props,style:{...props.style,opacity:0}})});}const own=isNew?key-1:key;let rank=0;store.keys.forEach((other,otherId)=>{if(other<own||other===own&&otherId<id)rank++;});return /*#__PURE__*/_jsx(ItemContext.Provider,{value:setIsNew,children:/*#__PURE__*/_jsx(Component,{...props,style:{...props.style,order:rank,display:rank<store.visible?props.style?.display:\"none\",opacity:1,transition:\"opacity 0.3s ease\"}})});};}/** Apply to the \"Load more companies\" button under the grid. */export function withLoadMore(Component){return props=>{useStore();const[mounted,setMounted]=useState(false);useEffect(()=>setMounted(true),[]);const remaining=store.keys.size-store.visible;const hidden=mounted&&remaining<=0;const loadMore=()=>{store.visible+=PAGE_SIZE;emit();};return /*#__PURE__*/_jsx(Component,{...props,onClick:loadMore,onTap:loadMore,style:{...props.style,display:hidden?\"none\":props.style?.display}});};}/** Apply to a text layer: shows \"+N new companies added today\", hidden when 0. */export function withNewCount(Component){return props=>{useStore();const count=store.allNew.size;const text=`+${count} new ${count===1?\"company\":\"companies\"} added today`;return /*#__PURE__*/_jsx(Component,{...props,text:text,style:{...props.style,display:count>0?props.style?.display:\"none\"}});};}/**\n * Apply to the \"Companies Listed\" stat card (number counter component).\n * Fills the number from the live count and adds \"+N added today\" as its note.\n */export function withCompanyStats(Component){return props=>{useStore();const total=store.allCompanies.size;const fresh=store.allNew.size;return /*#__PURE__*/_jsx(Component,{...props,...total>0?{counter:String(total)}:{},note:fresh>0?`+${fresh} added today`:\"\"});};}let nextTagId=0;/**\n * NEW tag for company cards. Shows only within 24 hours of \"Added On\".\n *\n * @framerSupportedLayoutWidth auto\n * @framerSupportedLayoutHeight auto\n */export default function NewTag(props){const{addedOn,label,role,style}=props;const report=useContext(ItemContext);const isCounter=role===\"Counter\";const[tagId]=useState(()=>nextTagId++);const[isNew,setIsNew]=useState(false);useEffect(()=>{const fresh=isWithinWindow(addedOn);// Counter mode: sits in a hidden, unfiltered list of every company\n// and only feeds the totals.\nif(isCounter){store.allCompanies.add(tagId);if(fresh)store.allNew.add(tagId);emit();return()=>{store.allCompanies.delete(tagId);store.allNew.delete(tagId);emit();};}setIsNew(fresh);report?.(fresh);if(!fresh)return;store.newTags.add(tagId);emit();return()=>{store.newTags.delete(tagId);report?.(false);emit();};},[addedOn,tagId,report,isCounter]);if(isCounter||!isNew)return null;return /*#__PURE__*/_jsxs(\"span\",{style:{...style,position:\"relative\",display:\"inline-flex\",alignItems:\"center\",gap:6,padding:\"5px 8px\",borderRadius:4,background:\"#FCE564\",color:\"#1C1C1C\",fontFamily:`\"JetBrains Mono\", ui-monospace, monospace`,fontWeight:700,fontSize:11,letterSpacing:\"0.06em\",textTransform:\"uppercase\",whiteSpace:\"nowrap\",width:\"max-content\"},children:[/*#__PURE__*/_jsx(\"span\",{\"aria-hidden\":\"true\",style:{width:6,height:6,borderRadius:999,background:\"#FE4706\"}}),label]});}addPropertyControls(NewTag,{addedOn:{type:ControlType.Date,title:\"Added On\"},label:{type:ControlType.String,title:\"Label\",defaultValue:\"New\"},role:{type:ControlType.Enum,title:\"Role\",options:[\"Tag\",\"Counter\"],defaultValue:\"Tag\",displaySegmentedControl:true}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"NewTag\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"auto\"}},\"withLoadMore\":{\"type\":\"reactHoc\",\"name\":\"withLoadMore\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withNewCount\":{\"type\":\"reactHoc\",\"name\":\"withNewCount\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withShuffledItem\":{\"type\":\"reactHoc\",\"name\":\"withShuffledItem\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withCompanyStats\":{\"type\":\"reactHoc\",\"name\":\"withCompanyStats\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./LibraryShuffle.map"],"mappings":"wMAMiL,SAA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