{ "version": 3, "sources": ["../javascript/vanilla/cal_heatmap.js", "../javascript/vanilla/load_scripts_and_styles.js", "../javascript/vanilla/main.js"], "sourcesContent": ["export function createCalHeatmap(countsByDay, containerId = \"cal-heatmap\") {\n // Check if a heatmap already exists in the container\n if (document.querySelector(`#${containerId} > svg`)) {\n console.log(\"Heatmap already exists. Skipping creation.\");\n return; // Exit early if a heatmap is already present\n }\n\n // Import necessary dependencies (assume they are already loaded globally)\n // Usage example\n let filesToLoad = [\n { src: \"https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js\", type: \"js\" },\n { src: \"https://d3js.org/d3.v7.min.js\", type: \"js\" },\n {\n src: \"https://unpkg.com/cal-heatmap/dist/cal-heatmap.min.js\",\n type: \"js\",\n },\n {\n src: \"https://unpkg.com/cal-heatmap/dist/cal-heatmap.css\",\n type: \"style\",\n },\n {\n src: \"https://unpkg.com/cal-heatmap/dist/plugins/Legend.min.js\",\n type: \"js\",\n },\n { src: \"https://unpkg.com/@popperjs/core@2\", type: \"js\" },\n {\n src: \"https://unpkg.com/cal-heatmap/dist/plugins/Tooltip.min.js\",\n type: \"js\",\n },\n {\n src: \"https://unpkg.com/cal-heatmap/dist/plugins/CalendarLabel.min.js\",\n type: \"js\",\n },\n ];\n\n function loadScriptsAndStyles(files) {\n let promises = [];\n\n function createPromise(file) {\n return new Promise((resolve, reject) => {\n let element;\n\n if (file.type === \"js\") {\n element = document.createElement(\"script\");\n element.src = file.src;\n element.onload = resolve;\n element.onerror = reject;\n document.head.appendChild(element);\n } else if (file.type === \"style\") {\n element = document.createElement(\"link\");\n element.rel = \"stylesheet\";\n element.href = file.src;\n element.onload = resolve;\n element.onerror = reject;\n document.head.appendChild(element);\n } else {\n reject(new Error(`Unsupported file type: ${file.type}`));\n }\n });\n }\n\n files.forEach((file) => {\n promises.push(createPromise(file));\n });\n\n return Promise.all(promises);\n }\n\n // Usage example\n loadScriptsAndStyles(filesToLoad)\n .then(() => {\n console.log(\"All files loaded successfully\");\n // Call your function here\n createHeatmap(countsByDay, containerId);\n })\n .catch((error) => {\n console.error(\"Error loading files:\", error);\n });\n}\n\nfunction createHeatmap(countsByDay, containerId = \"cal-heatmap\") {\n // Import necessary dependencies (assume they are already loaded globally)\n\n // Clean up countsByDay data\n function cleanUpCountsByDay(counts) {\n return counts.map((item) => ({\n date: dayjs(item.date).format(\"YYYY-MM-DD\"),\n value: item.value,\n }));\n }\n\n countsByDay = cleanUpCountsByDay(countsByDay);\n\n // Determine screen size\n function getScreenSize() {\n const breakpoints = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n };\n const width = window.innerWidth;\n\n if (width < breakpoints.sm) {\n return \"small\";\n } else if (width < breakpoints.md) {\n return \"medium\";\n } else if (width < breakpoints.lg) {\n return \"large\";\n } else {\n return \"extralarge\";\n }\n }\n\n let screenSize = getScreenSize();\n let size = {\n small: {\n subtract: 3,\n range: 4,\n },\n medium: {\n subtract: 4,\n range: 5,\n },\n large: {\n subtract: 5,\n range: 6,\n },\n extralarge: {\n subtract: 6,\n range: 7,\n },\n };\n let currentSize = size[screenSize];\n\n let start = dayjs().subtract(currentSize.subtract, \"month\");\n\n // Define the upToTodayTemplate function\n const upToTodayTemplate = function (DateHelper) {\n return {\n name: \"ghDayUpToToday\",\n parent: \"ghDay\",\n\n mapping: (startTimestamp, endTimestamp) => {\n let weekNumber = 0;\n let x = -1;\n\n return DateHelper.intervals(\n \"day\",\n startTimestamp,\n DateHelper.date(endTimestamp)\n )\n .map((ts) => {\n const date = DateHelper.date(ts);\n\n let today = new Date();\n if (date > today) {\n return null;\n }\n\n if (weekNumber !== date.week()) {\n weekNumber = date.week();\n x += 1;\n }\n\n return {\n t: ts,\n x,\n y: date.day(),\n };\n })\n .filter((n) => n !== null);\n },\n };\n };\n\n // Create CalHeatmap instance\n const cal = new CalHeatmap();\n cal.addTemplates(upToTodayTemplate);\n\n // Function to paint the heatmap\n function paintHeatmap(theme) {\n cal.paint({\n data: { source: countsByDay, x: \"date\", y: \"value\" },\n range: currentSize.range,\n date: { start: start, max: new Date() },\n domain: {\n type: \"month\",\n gutter: 10,\n dynamicDimension: true,\n label: { position: \"top\" },\n },\n subDomain: {\n type: \"ghDayUpToToday\",\n radius: 3,\n width: 15,\n height: 15,\n gutter: 4,\n },\n scale: {\n color: {\n type: \"linear\",\n scheme: \"Greens\",\n domain: [0, 3],\n },\n },\n theme: theme,\n });\n }\n\n // Initialize the heatmap\n paintHeatmap(getLightOrDarkTheme());\n\n // Function to get light or dark theme based on data-theme attribute\n function getLightOrDarkTheme() {\n let siteTheme = document.documentElement.getAttribute(\"data-theme\");\n if (siteTheme == \"lightmode\") {\n return \"light\";\n } else {\n return \"dark\";\n }\n }\n\n // Mutation observer to detect changes in data-theme attribute\n const observer = new MutationObserver((mutations) => {\n mutations.forEach((mutation) => {\n if (\n mutation.type === \"attributes\" &&\n mutation.attributeName === \"data-theme\"\n ) {\n // Update the data-theme attribute on the first svg child of the heatmap div\n const svgElement = document.querySelector(`#${containerId} > svg`);\n if (svgElement) {\n svgElement.setAttribute(\"data-theme\", getLightOrDarkTheme());\n }\n }\n });\n });\n\n // Observe changes in data-theme attribute\n observer.observe(document.documentElement, {\n attributes: true,\n });\n\n // Return the observer so it can be disconnected externally if needed\n return observer;\n}\n", "export function loadScriptsAndStyles(files) {\n // Promise array to track loading status\n let promises = [];\n\n // Helper function to create a promise for each file\n function createPromise(file) {\n return new Promise((resolve, reject) => {\n let element;\n\n if (file.endsWith(\".js\")) {\n // Create script element for JavaScript file\n element = document.createElement(\"script\");\n element.src = file;\n element.onload = resolve;\n element.onerror = reject;\n document.head.appendChild(element);\n } else if (file.endsWith(\".css\")) {\n // Create link element for CSS file\n element = document.createElement(\"link\");\n element.rel = \"stylesheet\";\n element.href = file;\n element.onload = resolve;\n element.onerror = reject;\n document.head.appendChild(element);\n } else {\n reject(new Error(`Unsupported file type: ${file}`));\n }\n });\n }\n\n // Create promises for each file and push them to the promises array\n files.forEach((file) => {\n promises.push(createPromise(file));\n });\n\n // Return a promise that resolves when all promises are resolved\n return Promise.all(promises);\n}\n", "import { createCalHeatmap } from \"./cal_heatmap\";\nimport { loadScriptsAndStyles } from \"./load_scripts_and_styles\";\n\nwindow.initializeJS = function initializeApp(targetElement) {\n console.log(\"initialize js\");\n // Control zoom based on screen size\n controlZoom();\n\n // Set up PWA service worker\n if (\"serviceWorker\" in navigator) {\n navigator.serviceWorker\n .register(\"/service-worker.js\", { type: \"classic\" })\n .then(function (registration) {\n console.log(\n \"Service Worker registered with scope:\",\n registration.scope\n );\n })\n .catch(function (error) {\n console.log(\"Service Worker registration failed:\", error);\n });\n }\n\n refreshPageIfStale();\n};\n\n// controlZoom prevents zooming on mobile devices to improve user experience. Note that it is\n// not enforced by all browsers, so is not guaranteed to work on all of them. TODO: we may want to\n// remove that entirely as Brave/Chrome ignore these directives, and it may be globally useless if\n// all browsers ignore it.\nfunction controlZoom() {\n const viewportMeta = document.querySelector('meta[name=\"viewport\"]');\n\n function updateViewport() {\n if (window.innerWidth < 1024) {\n // Disable zooming on small screens\n viewportMeta.setAttribute(\n \"content\",\n \"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\"\n );\n } else {\n // Allow zooming on large screens\n viewportMeta.setAttribute(\n \"content\",\n \"width=device-width, initial-scale=1.0\"\n );\n }\n }\n\n // Update on initial load\n updateViewport();\n\n // Update on window resize\n window.addEventListener(\"resize\", updateViewport);\n}\n\nfunction refreshPageIfStale() {\n document.addEventListener(\"visibilitychange\", function () {\n if (document.visibilityState === \"visible\") {\n // Check the time elapsed\n const currentTime = new Date().getTime();\n const lastVisitTime = localStorage.getItem(\"lastVisitTime\");\n const timeElapsed = currentTime - lastVisitTime;\n\n // Define a threshold (e.g., 10 minutes = 600000 ms)\n if (timeElapsed > 600000) {\n // 30 minutes\n console.log(\"Refreshing data after inactivity\");\n window.location.reload();\n }\n } else {\n localStorage.setItem(\"lastVisitTime\", new Date().getTime());\n }\n });\n}\n\nwind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D,CAAC,CACH,CAEA,OAAO,iBAAmBC,EAC1B,OAAO,qBAAuBC", "names": ["createCalHeatmap", "countsByDay", "containerId", "filesToLoad", "loadScriptsAndStyles", "files", "promises", "createPromise", "file", "resolve", "reject", "element", "createHeatmap", "error", "cleanUpCountsByDay", "counts", "item", "getScreenSize", "breakpoints", "width", "screenSize", "currentSize", "start", "upToTodayTemplate", "DateHelper", "startTimestamp", "endTimestamp", "weekNumber", "x", "ts", "date", "n", "cal", "paintHeatmap", "theme", "getLightOrDarkTheme", "observer", "mutations", "mutation", "svgElement", "loadScriptsAndStyles", "files", "promises", "createPromise", "file", "resolve", "reject", "element", "targetElement", "controlZoom", "registration", "error", "refreshPageIfStale", "viewportMeta", "updateViewport", "currentTime", "lastVisitTime", "createCalHeatmap", "loadScriptsAndStyles"] }