} [options.onLogout]
+ */
+export default function ProfileInclude({
+ user: initialUser = null,
+ getAvatarSrc,
+ onLogin,
+ onLogout,
+} = {}) {
+ let user = initialUser;
+
+ const $page = Page(t("my profile", "My profile"));
+ $page.classList.add("profile-page");
+
+ const close = () => {
+ $page.hide();
+ Sidebar.hide();
+ };
+ const goto = (fn) => () => {
+ close();
+ setTimeout(() => {
+ try {
+ fn();
+ } catch (error) {
+ helpers.error(error);
+ }
+ }, 200);
+ };
+
+ const $heroSlot = ;
+ const $footSlot = ;
+ const activity = section(t("activity", "Activity"));
+ const languages = section(t("top languages", "Top languages"));
+
+ /* ---------- account ---------- */
+ async function signIn() {
+ if (!onLogin) return;
+ const next = await onLogin();
+ if (next) {
+ user = next;
+ refreshAccount();
+ }
+ }
+
+ async function signOut() {
+ const ok = await confirm(
+ t("logout", "Logout"),
+ t(
+ "logout confirm",
+ "Are you sure you want to log out of your Acode account?",
+ ),
+ );
+ if (!ok) return;
+ const success = onLogout ? await onLogout() : true;
+ if (success === false) return;
+ user = null;
+ refreshAccount();
+ }
+
+ async function resetActivity() {
+ const ok = await confirm(
+ t("reset activity", "Reset activity"),
+ t(
+ "reset activity warning",
+ "This clears the time, lines, files and streaks tracked on this device.",
+ ),
+ );
+ if (!ok) return;
+ tracker.reset();
+ renderActivity();
+ renderLanguages();
+ toast(t("activity reset", "Activity reset"));
+ }
+
+ function renderHero() {
+ $heroSlot.textContent = "";
+ $heroSlot.append(
+ user ? buildUserHero(user, getAvatarSrc) : buildGuestHero(signIn),
+ );
+ }
+
+ function renderFoot() {
+ $footSlot.textContent = "";
+ const $card = ;
+ $card.append(
+ row({
+ iconName: "trash",
+ title: t("reset activity", "Reset activity"),
+ chevron: false,
+ onclick: resetActivity,
+ }),
+ );
+ if (user) {
+ $card.append(
+ row({
+ iconName: "logout",
+ title: t("logout", "Logout"),
+ danger: true,
+ chevron: false,
+ onclick: signOut,
+ }),
+ );
+ }
+ $footSlot.append($card);
+ }
+
+ function refreshAccount() {
+ // After the first render, sign in/out also swaps the sample heatmap.
+ if (activity.$body.firstChild) renderActivity();
+ renderHero();
+ renderFoot();
+ }
+
+ /* ---------- activity ---------- */
+ const $share = ;
+ $share.setAttribute("aria-label", t("share", "Share"));
+ $share.append(icon("share", 16));
+ activity.$trail.append(
+ {t("last 12 months", "Last 12 months")},
+ $share,
+ );
+
+ let sharing = false;
+ $share.onclick = async () => {
+ if (sharing) return;
+ sharing = true;
+ try {
+ const blob = await renderShareCard($share, {
+ name: user?.name || t("activity", "Activity"),
+ data: tracker.getSummary(),
+ formatDuration,
+ label: t,
+ });
+ await shareImage(blob, "acode-activity.png");
+ } catch (error) {
+ console.error(error);
+ toast(t("share failed", "Could not share your activity"));
+ } finally {
+ sharing = false;
+ }
+ };
+
+ function renderActivity() {
+ const data = tracker.getSummary();
+ // Signed out with nothing tracked yet: show a faded sample instead of
+ // a blank grid.
+ const isPlaceholder = !user && !data.totals.activeDays;
+ $share.style.display = data.totals.activeDays ? "" : "none";
+ const weeks = buildWeeks(
+ isPlaceholder ? samplePattern(data.year) : data.year,
+ );
+ const labels = monthLabels(weeks);
+ const todayKey = data.year[data.year.length - 1].date;
+ const $grid = ;
+
+ weeks.forEach((week, i) => {
+ const $week = ;
+ $week.append({labels[i] || ""}
);
+ for (const day of week) {
+ let cellClass = "pf-gh-cell none";
+ if (day) {
+ cellClass = `pf-gh-cell lv${day.level}`;
+ if (day.date === todayKey && !isPlaceholder) cellClass += " today";
+ }
+ const $cell = ;
+ if (day && !isPlaceholder) $cell.dataset.tip = tipText(day);
+ $week.append($cell);
+ }
+ $grid.append($week);
+ });
+
+ // Tapping a day highlights it and shows its details.
+ let $selected = null;
+ $grid.onclick = (e) => {
+ const $cell = e.target;
+ const tip = $cell?.dataset?.tip;
+ if (!tip) return;
+ $selected?.classList.remove("selected");
+ $selected = $cell;
+ $cell.classList.add("selected");
+ toast(tip);
+ };
+
+ const $scroll = {$grid}
;
+
+ // Weekday labels (Mon/Wed/Fri) stay put while the grid scrolls.
+ const $days = ;
+ $days.append();
+ for (let row = 0; row < 7; row++) {
+ // 2024-01-07 was a Sunday, matching the Sunday-first grid.
+ const name =
+ row % 2 === 1
+ ? new Date(2024, 0, 7 + row).toLocaleDateString(undefined, {
+ weekday: "short",
+ })
+ : "";
+ $days.append({name}
);
+ }
+ const $heat = (
+
+ {$days}
+ {$scroll}
+
+ );
+
+ const $legend = ;
+ $legend.append({t("less", "Less")});
+ for (let n = 0; n <= 4; n++) {
+ $legend.append();
+ }
+ $legend.append({t("more", "More")});
+
+ const { today, totals } = data;
+ const todayText = today.ms
+ ? t("today time", "Today {time}", { time: formatDuration(today.ms) })
+ : t("nothing yet today", "Nothing yet today");
+
+ activity.$body.textContent = "";
+ activity.$body.append(
+
+ {metric(formatDuration(totals.ms), t("coding time", "Coding time"))}
+ {metric(`${data.current}d`, t("streak", "Streak"))}
+ {metric(`${data.longest}d`, t("best streak", "Best streak"))}
+ {metric(String(totals.activeDays), t("active days", "Active days"))}
+
,
+ $heat,
+
+
+ {isPlaceholder
+ ? t(
+ "activity placeholder hint",
+ "Sign in and start coding to fill this in",
+ )
+ : todayText}
+
+ {$legend}
+
,
+ );
+
+ // Newest weeks are on the right, so start scrolled to the end.
+ setTimeout(() => {
+ $scroll.scrollLeft = $scroll.scrollWidth;
+ }, 50);
+
+ renderWeek(data);
+ return data;
+ }
+
+ /* ---------- this week (last 7 days) ---------- */
+ const thisWeek = section(t("this week", "This week"));
+
+ function renderWeek(data) {
+ const days = data.year.slice(-7);
+ const max = Math.max(...days.map((day) => day.ms), 1);
+ const total = days.reduce((sum, day) => sum + day.ms, 0);
+ thisWeek.$trail.textContent = total ? formatDuration(total) : "";
+
+ const $chart = ;
+ days.forEach((day, i) => {
+ const isToday = i === days.length - 1;
+ const percent = day.ms
+ ? Math.max(8, Math.round((day.ms / max) * 100))
+ : 0;
+ const barClass = ["pf-week-bar", !day.ms && "empty", isToday && "today"]
+ .filter(Boolean)
+ .join(" ");
+ const name = new Date(`${day.date}T00:00:00Z`).toLocaleDateString(
+ undefined,
+ { weekday: "short", timeZone: "UTC" },
+ );
+ $chart.append(
+ toast(tipText(day))}>
+
+
+
+
+ {name}
+
+
,
+ );
+ });
+ thisWeek.$body.textContent = "";
+ thisWeek.$body.append($chart);
+ }
+
+ function renderLanguages(list = tracker.getSummary().languages) {
+ languages.$body.textContent = "";
+ if (!list.length) {
+ languages.$body.append(
+
+ {t("languages empty", "Languages show up here as you code.")}
+
,
+ );
+ return;
+ }
+ const $strip = ;
+ for (const lang of list) {
+ $strip.append(
+ ,
+ );
+ }
+ languages.$body.append($strip);
+
+ for (const lang of list) {
+ const percent = lang.share * 100;
+ const label = percent < 1 ? "<1%" : `${Math.round(percent)}%`;
+ languages.$body.append(
+
+
+ {lang.name}
+ {label}
+
,
+ );
+ }
+ }
+
+ /* ---------- recents ---------- */
+ const recent = section(t("recently used", "Recently used"));
+ const recentFiles = recents.files.filter(Boolean).slice(0, 4);
+ const recentFolders = recents.folders.filter((f) => f?.url).slice(0, 2);
+
+ for (const file of recentFiles) {
+ const { name, location } = pathDetails(file);
+ recent.$body.append(
+ row({
+ iconName: "file",
+ title: name,
+ subtitle: location,
+ chevron: false,
+ onclick: goto(() =>
+ Promise.resolve(openFile(file, { render: true })).catch((err) =>
+ helpers.error(err),
+ ),
+ ),
+ }),
+ );
+ }
+ for (const folder of recentFolders) {
+ const { name, location } = pathDetails(folder.url);
+ recent.$body.append(
+ row({
+ iconName: "folder",
+ title: name,
+ subtitle: location,
+ chevron: false,
+ onclick: goto(() => openFolder(folder.url, folder.opts)),
+ }),
+ );
+ }
+
+ /* ---------- menu ---------- */
+ // Count of plugins downloaded to this device; tapping opens the
+ // Plugins page, which starts on its "Installed" tab.
+ const $pluginCount = –;
+
+ const menu = section(t("more", "More"));
+ const menuRows = [
+ {
+ iconName: "package",
+ title: t("plugins", "Plugins"),
+ value: $pluginCount,
+ onclick: goto(async () =>
+ (
+ await import(/* webpackChunkName: "plugins" */ "pages/plugins")
+ ).default(),
+ ),
+ },
+ {
+ iconName: "sliders",
+ title: t("settings", "Settings"),
+ onclick: goto(async () =>
+ (
+ await import(
+ /* webpackChunkName: "mainSettings" */ "settings/mainSettings"
+ )
+ ).default(),
+ ),
+ },
+ {
+ iconName: "contrast",
+ title: t("app theme", "App theme"),
+ onclick: goto(async () =>
+ (
+ await import(
+ /* webpackChunkName: "changeTheme" */ "palettes/changeTheme"
+ )
+ ).default("app"),
+ ),
+ },
+ {
+ iconName: "folder",
+ title: t("open folder", "Open folder"),
+ onclick: goto(() => acode.exec("open-folder")),
+ },
+ {
+ iconName: "external",
+ title: t("acode account", "Acode account"),
+ value: String(config.BASE_URL || "").replace(/^https?:\/\//, ""),
+ onclick: openUrl(config.BASE_URL),
+ },
+ {
+ iconName: "info",
+ title: t("about", "About"),
+ value: window.BuildInfo?.version || "",
+ onclick: goto(async () =>
+ (await import(/* webpackChunkName: "about" */ "pages/about")).default(),
+ ),
+ },
+ ];
+ for (const item of menuRows) menu.$body.append(row(item));
+
+ async function fillPlugins() {
+ let total = LOADED_PLUGINS.size;
+ try {
+ const list = await fsOperation(PLUGIN_DIR).lsDir();
+ total = list.length;
+ } catch {}
+ $pluginCount.textContent = String(total);
+ }
+
+ /* ---------- assemble ---------- */
+ const $main = ;
+ $main.append($heroSlot, activity.$el, thisWeek.$el, languages.$el);
+ if (recentFiles.length || recentFolders.length) $main.append(recent.$el);
+ $main.append(menu.$el, $footSlot);
+
+ refreshAccount();
+ renderLanguages(renderActivity().languages);
+ fillPlugins();
+
+ // Index per section drives the staggered entrance (see profile.scss).
+ [...$main.children].forEach(($el, i) => $el.style.setProperty("--pf-i", i));
+
+ $page.body = $main;
+
+ actionStack.push({
+ id: "profile",
+ action: $page.hide,
+ });
+
+ $page.onhide = function () {
+ actionStack.remove("profile");
+ };
+
+ app.append($page);
+}
diff --git a/src/pages/profile/profile.scss b/src/pages/profile/profile.scss
new file mode 100644
index 0000000000..879f627a12
--- /dev/null
+++ b/src/pages/profile/profile.scss
@@ -0,0 +1,551 @@
+@keyframes pf-rise {
+ from {
+ opacity: 0;
+ transform: translateY(12px);
+ }
+ to {
+ opacity: 1;
+ transform: none;
+ }
+}
+
+#profile-page {
+ --pf-blue: #3b82f6;
+ /* Follows the active theme; the button keeps a fixed blue for contrast. */
+ --pf-accent: var(--active-color, var(--pf-blue));
+ --pf-muted: color-mix(in srgb, var(--primary-text-color) 60%, transparent);
+ --pf-border: var(--border-color, rgba(255, 255, 255, 0.1));
+ --pf-danger: var(--danger-color, #ff5c5c);
+
+ /* Activity graph: one blue, five steps (works on light and dark themes) */
+ --pf-lv0: color-mix(in srgb, var(--primary-text-color) 9%, transparent);
+ --pf-lv1: color-mix(in srgb, var(--pf-accent) 28%, transparent);
+ --pf-lv2: color-mix(in srgb, var(--pf-accent) 50%, transparent);
+ --pf-lv3: color-mix(in srgb, var(--pf-accent) 75%, transparent);
+ --pf-lv4: var(--pf-accent);
+
+ box-sizing: border-box;
+ width: 100%;
+ max-width: 560px;
+ margin: 0 auto;
+ padding: 20px 16px 40px;
+ display: flex;
+ flex-direction: column;
+ gap: 24px;
+ overflow-y: auto;
+ color: var(--primary-text-color);
+
+ .pf-icon {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ flex-shrink: 0;
+ }
+
+ /* Sections fade up one after another (--pf-i is set in profile.js). */
+ > .pf-slot,
+ > .pf-section {
+ animation: pf-rise 0.4s ease-out both;
+ animation-delay: calc(var(--pf-i, 0) * 60ms);
+ }
+
+ @media (prefers-reduced-motion: reduce) {
+ > .pf-slot,
+ > .pf-section { animation: none; }
+ }
+
+ /* Faded sample graph for signed-out users with no activity yet. */
+ .pf-gh-wrap.placeholder {
+ opacity: 0.35;
+ pointer-events: none;
+ }
+
+ .pf-slot {
+ display: flex;
+ flex-direction: column;
+ }
+
+ .pf-link {
+ color: var(--pf-accent);
+ &:active { opacity: 0.6; }
+ }
+
+ /* ---------- header ---------- */
+ .pf-hero {
+ display: flex;
+ align-items: center;
+ gap: 16px;
+ padding: 0 4px;
+ }
+
+ .pf-hero-text {
+ flex: 1;
+ min-width: 0;
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+ gap: 2px;
+ }
+
+ .pf-avatar {
+ position: relative;
+ flex-shrink: 0;
+ width: 68px;
+ height: 68px;
+ border-radius: 50%;
+ overflow: hidden;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ border: 1px solid var(--pf-border);
+ background: var(--pf-lv0);
+
+ .pf-avatar-initial {
+ font-size: 28px;
+ font-weight: 600;
+ }
+
+ .pf-avatar-img {
+ position: absolute;
+ inset: 0;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ opacity: 0;
+ transition: opacity 0.25s ease;
+ }
+
+ &.loaded {
+ .pf-avatar-img { opacity: 1; }
+ .pf-avatar-initial { display: none; }
+ }
+
+ &.guest { color: var(--pf-muted); }
+
+ /* Pro: subtle gold ring */
+ &.pro {
+ border-color: transparent;
+ box-shadow:
+ 0 0 0 2px #ffc94d,
+ 0 0 14px rgba(255, 201, 77, 0.3);
+ }
+ }
+
+ .pf-name-row {
+ display: flex;
+ align-items: center;
+ flex-wrap: wrap;
+ gap: 8px;
+ }
+
+ .pf-name {
+ margin: 0;
+ font-size: 20px;
+ font-weight: 600;
+ line-height: 1.25;
+ word-break: break-word;
+ }
+
+ .pf-verified {
+ display: inline-flex;
+ color: var(--pf-accent);
+ }
+
+ .pf-badge {
+ padding: 1px 7px;
+ border-radius: 999px;
+ font-size: 10.5px;
+ font-weight: 600;
+ letter-spacing: 0.06em;
+ color: var(--pf-muted);
+ border: 1px solid var(--pf-border);
+
+ &.pro {
+ color: #1b1300;
+ border-color: transparent;
+ background: #ffc94d;
+ }
+ }
+
+ .pf-email {
+ font-size: 13.5px;
+ color: var(--pf-muted);
+ word-break: break-all;
+ }
+
+ .pf-meta {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ gap: 6px;
+ margin-top: 2px;
+ font-size: 12.5px;
+ color: var(--pf-muted);
+
+ .pf-link { color: var(--pf-accent); }
+ }
+
+ /* ---------- sections ---------- */
+ .pf-section {
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+ }
+
+ .pf-section-head {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 0 4px;
+ font-size: 13px;
+ }
+
+ .pf-section-title {
+ margin: 0;
+ font-size: 12px;
+ font-weight: 600;
+ text-transform: uppercase;
+ letter-spacing: 0.08em;
+ color: var(--pf-muted);
+ }
+
+ .pf-section-trail {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ font-size: 12px;
+ color: var(--pf-muted);
+ }
+
+ .pf-share {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ width: 28px;
+ height: 28px;
+ margin: -6px -6px -6px 0;
+ padding: 0;
+ border: none;
+ border-radius: 50%;
+ background: transparent;
+ color: var(--pf-muted);
+ transition:
+ transform 0.12s ease,
+ background 0.12s ease;
+
+ &:active {
+ background: var(--pf-lv0);
+ transform: scale(0.9);
+ }
+ }
+
+ .pf-card {
+ display: flex;
+ flex-direction: column;
+ border-radius: 14px;
+ border: 1px solid var(--pf-border);
+ overflow: hidden;
+ }
+
+ /* ---------- activity ---------- */
+ .pf-metrics {
+ display: flex;
+ padding: 14px 8px 4px;
+ }
+
+ .pf-metric {
+ flex: 1;
+ min-width: 0;
+ text-align: center;
+
+ .pf-metric-value {
+ font-size: 17px;
+ font-weight: 600;
+ white-space: nowrap;
+ }
+
+ .pf-metric-label {
+ margin-top: 2px;
+ font-size: 11px;
+ color: var(--pf-muted);
+ white-space: nowrap;
+ }
+ }
+
+ .pf-gh-scroll {
+ flex: 1;
+ min-width: 0;
+ overflow-x: auto;
+ padding: 14px 14px 10px 6px;
+ scrollbar-width: none;
+ -webkit-overflow-scrolling: touch;
+
+ &::-webkit-scrollbar { display: none; }
+ }
+
+ .pf-gh-grid {
+ display: flex;
+ gap: 3px;
+ width: max-content;
+ }
+
+ .pf-gh-week {
+ display: flex;
+ flex-direction: column;
+ gap: 3px;
+ }
+
+ .pf-gh-month {
+ flex: none;
+ width: 11px;
+ height: 14px;
+ line-height: 14px;
+ font-size: 10.5px;
+ white-space: nowrap;
+ overflow: visible;
+ color: var(--pf-muted);
+ }
+
+ .pf-gh-cell {
+ flex: none;
+ width: 11px;
+ height: 11px;
+ border-radius: 2px;
+ background: var(--pf-lv0);
+
+ &.lv1 { background: var(--pf-lv1); }
+ &.lv2 { background: var(--pf-lv2); }
+ &.lv3 { background: var(--pf-lv3); }
+ &.lv4 { background: var(--pf-lv4); }
+ &.none { background: transparent; }
+ &.today { box-shadow: 0 0 0 1.5px var(--pf-muted); }
+ &.selected { box-shadow: 0 0 0 1.5px var(--primary-text-color); }
+ }
+
+ .pf-gh-wrap {
+ display: flex;
+ align-items: flex-start;
+ }
+
+ /* Rows line up with the grid: spacer = month label row, then 7 days. */
+ .pf-gh-days {
+ flex: none;
+ display: flex;
+ flex-direction: column;
+ gap: 3px;
+ padding: 14px 0 10px 14px;
+
+ .pf-gh-spacer { height: 14px; }
+
+ .pf-gh-daylabel {
+ height: 11px;
+ line-height: 11px;
+ font-size: 9.5px;
+ white-space: nowrap;
+ color: var(--pf-muted);
+ }
+ }
+
+ .pf-gh-foot {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: center;
+ justify-content: space-between;
+ gap: 8px 12px;
+ padding: 0 14px 12px;
+ font-size: 12px;
+ color: var(--pf-muted);
+ }
+
+ .pf-gh-legend {
+ display: flex;
+ align-items: center;
+ gap: 3px;
+
+ span:first-child { margin-right: 4px; }
+ span:last-child { margin-left: 4px; }
+ }
+
+ /* ---------- this week ---------- */
+ .pf-week {
+ display: flex;
+ gap: 8px;
+ padding: 16px 14px 12px;
+ }
+
+ .pf-week-col {
+ flex: 1;
+ min-width: 0;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 8px;
+
+ &:active { opacity: 0.7; }
+ }
+
+ .pf-week-area {
+ display: flex;
+ align-items: flex-end;
+ justify-content: center;
+ width: 100%;
+ height: 64px;
+ }
+
+ .pf-week-bar {
+ display: block;
+ width: 100%;
+ max-width: 26px;
+ min-height: 3px;
+ border-radius: 5px;
+ background: color-mix(in srgb, var(--pf-accent) 55%, transparent);
+
+ &.empty { background: var(--pf-lv0); }
+ &.today { background: var(--pf-accent); }
+ }
+
+ .pf-week-day {
+ font-size: 11px;
+ color: var(--pf-muted);
+
+ &.today {
+ color: var(--primary-text-color);
+ font-weight: 600;
+ }
+ }
+
+ /* ---------- languages ---------- */
+ .pf-lang-strip {
+ display: flex;
+ gap: 2px;
+ height: 8px;
+ margin: 14px 14px 6px;
+ border-radius: 999px;
+ overflow: hidden;
+
+ .pf-lang-seg {
+ flex: 1 1 0;
+ min-width: 4px;
+ }
+ }
+
+ .pf-lang {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ padding: 10px 14px;
+ border-bottom: 1px solid var(--pf-border);
+ font-size: 14px;
+
+ &:last-child { border-bottom: none; }
+
+ .pf-lang-dot {
+ flex-shrink: 0;
+ width: 10px;
+ height: 10px;
+ border-radius: 50%;
+ }
+
+ .pf-lang-name {
+ flex: 1;
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ .pf-lang-percent { color: var(--pf-muted); }
+ }
+
+ /* ---------- rows ---------- */
+ .pf-row {
+ display: flex;
+ align-items: center;
+ gap: 14px;
+ transition:
+ transform 0.12s ease,
+ background 0.12s ease;
+ padding: 14px;
+ border-bottom: 1px solid var(--pf-border);
+ color: var(--primary-text-color);
+
+ &:last-child { border-bottom: none; }
+ &:active {
+ background: var(--pf-lv0);
+ transform: scale(0.98);
+ }
+
+ > .pf-icon { color: var(--pf-muted); }
+
+ .pf-row-text {
+ flex: 1;
+ min-width: 0;
+ }
+
+ .pf-row-title {
+ font-size: 15px;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ .pf-row-sub {
+ margin-top: 2px;
+ font-size: 12px;
+ color: var(--pf-muted);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+
+ .pf-row-value {
+ font-size: 13.5px;
+ color: var(--pf-muted);
+ }
+
+ &.danger {
+ > .pf-icon,
+ .pf-row-title { color: var(--pf-danger); }
+ }
+ }
+
+ /* ---------- empty / buttons ---------- */
+ .pf-empty {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 12px;
+ padding: 22px 16px;
+ font-size: 13.5px;
+ text-align: center;
+ color: var(--pf-muted);
+ }
+
+ .pf-btn {
+ display: inline-flex;
+ align-items: center;
+ justify-content: center;
+ gap: 8px;
+ margin-top: 6px;
+ padding: 10px 22px;
+ border: 1px solid transparent;
+ border-radius: 10px;
+ font-family: inherit;
+ font-size: 14px;
+ font-weight: 600;
+ color: #fff;
+ background: var(--pf-blue);
+ transition:
+ transform 0.12s ease,
+ filter 0.12s ease;
+
+ &.small { padding: 7px 16px; font-size: 13px; margin-top: 0; }
+ &:active {
+ filter: brightness(0.9);
+ transform: scale(0.97);
+ }
+ &:disabled { opacity: 0.6; }
+ }
+
+ .pf-hero-text .pf-btn { margin-top: 8px; }
+}
diff --git a/src/pages/profile/shareCard.js b/src/pages/profile/shareCard.js
new file mode 100644
index 0000000000..76ddc58809
--- /dev/null
+++ b/src/pages/profile/shareCard.js
@@ -0,0 +1,149 @@
+import { buildWeeks, monthLabels } from "./heatmap";
+
+const WIDTH = 1200;
+const PAD = 72;
+const GAP = 5;
+const FONT = "sans-serif";
+
+/** Resolves any CSS color (var(), color-mix()...) to a value canvas can paint. */
+function resolveColor($ref, value) {
+ const $probe = document.createElement("i");
+ $probe.style.position = "absolute";
+ $probe.style.visibility = "hidden";
+ $probe.style.background = value;
+ $ref.append($probe);
+ const color = getComputedStyle($probe).backgroundColor;
+ $probe.remove();
+ return color;
+}
+
+function roundRect(ctx, x, y, w, h, r) {
+ ctx.beginPath();
+ ctx.moveTo(x + r, y);
+ ctx.arcTo(x + w, y, x + w, y + h, r);
+ ctx.arcTo(x + w, y + h, x, y + h, r);
+ ctx.arcTo(x, y + h, x, y, r);
+ ctx.arcTo(x, y, x + w, y, r);
+ ctx.closePath();
+}
+
+/**
+ * Draws the activity card (stats + heatmap) to a PNG using the current theme.
+ * @param {HTMLElement} $ref element inside the profile page, used to read the
+ * theme colors
+ * @param {object} options
+ * @param {string} options.name title shown at the top
+ * @param {object} options.data summary from the activity tracker
+ * @param {(ms:number) => string} options.formatDuration
+ * @param {(key:string, fallback:string) => string} options.label
+ * @returns {Promise}
+ */
+export default function renderShareCard($ref, options) {
+ const { name, data, formatDuration, label } = options;
+ const paint = (value) => resolveColor($ref, value);
+ const colors = {
+ bg: paint("var(--primary-color, #1e1e1e)"),
+ text: paint("var(--primary-text-color, #ffffff)"),
+ muted: paint("var(--pf-muted)"),
+ accent: paint("var(--pf-accent)"),
+ levels: [0, 1, 2, 3, 4].map((n) => paint(`var(--pf-lv${n})`)),
+ };
+
+ const weeks = buildWeeks(data.year);
+ const months = monthLabels(weeks);
+ const cols = weeks.length;
+ const cell = Math.floor((WIDTH - PAD * 2 - GAP * (cols - 1)) / cols);
+ const gridH = cell * 7 + GAP * 6;
+
+ const metricsTop = PAD + 130;
+ const monthBase = metricsTop + 170;
+ const gridTop = monthBase + 18;
+ const legendBase = gridTop + gridH + 72;
+ const height = legendBase + PAD;
+
+ const canvas = document.createElement("canvas");
+ canvas.width = WIDTH;
+ canvas.height = height;
+ const ctx = canvas.getContext("2d");
+
+ ctx.fillStyle = colors.bg;
+ ctx.fillRect(0, 0, WIDTH, height);
+ ctx.textAlign = "left";
+ ctx.textBaseline = "alphabetic";
+
+ // Title
+ ctx.fillStyle = colors.text;
+ ctx.font = `700 54px ${FONT}`;
+ ctx.fillText(name, PAD, PAD + 50, WIDTH - PAD * 2);
+ ctx.fillStyle = colors.muted;
+ ctx.font = `400 28px ${FONT}`;
+ ctx.fillText(label("last 12 months", "Last 12 months"), PAD, PAD + 96);
+
+ // Stats
+ const { totals } = data;
+ const metrics = [
+ [formatDuration(totals.ms), label("coding time", "Coding time")],
+ [`${data.current}d`, label("streak", "Streak")],
+ [`${data.longest}d`, label("best streak", "Best streak")],
+ [String(totals.activeDays), label("active days", "Active days")],
+ ];
+ const colW = (WIDTH - PAD * 2) / metrics.length;
+ metrics.forEach(([value, caption], i) => {
+ const left = PAD + colW * i;
+ ctx.fillStyle = colors.text;
+ ctx.font = `700 56px ${FONT}`;
+ ctx.fillText(value, left, metricsTop + 60, colW - 16);
+ ctx.fillStyle = colors.muted;
+ ctx.font = `400 26px ${FONT}`;
+ ctx.fillText(caption, left, metricsTop + 104, colW - 16);
+ });
+
+ // Heatmap
+ ctx.font = `400 22px ${FONT}`;
+ weeks.forEach((week, i) => {
+ const left = PAD + i * (cell + GAP);
+ if (months[i]) {
+ ctx.fillStyle = colors.muted;
+ ctx.fillText(months[i], left, monthBase);
+ }
+ week.forEach((day, row) => {
+ if (!day) return;
+ ctx.fillStyle = colors.levels[day.level] || colors.levels[0];
+ roundRect(ctx, left, gridTop + row * (cell + GAP), cell, cell, 3);
+ ctx.fill();
+ });
+ });
+
+ // Legend and brand
+ ctx.font = `400 24px ${FONT}`;
+ const less = label("less", "Less");
+ const more = label("more", "More");
+ const swatch = 22;
+ const swatchGap = 6;
+ const lessW = ctx.measureText(less).width;
+ const moreW = ctx.measureText(more).width;
+ const swatchesW = swatch * 5 + swatchGap * 4;
+ let lx = WIDTH - PAD - (lessW + moreW + swatchesW + 32);
+ ctx.fillStyle = colors.muted;
+ ctx.fillText(less, lx, legendBase);
+ lx += lessW + 16;
+ for (const level of colors.levels) {
+ ctx.fillStyle = level;
+ roundRect(ctx, lx, legendBase - swatch + 3, swatch, swatch, 4);
+ ctx.fill();
+ lx += swatch + swatchGap;
+ }
+ ctx.fillStyle = colors.muted;
+ ctx.fillText(more, lx + 10, legendBase);
+
+ ctx.fillStyle = colors.accent;
+ ctx.font = `700 30px ${FONT}`;
+ ctx.fillText("Acode", PAD, legendBase);
+
+ return new Promise((resolve, reject) => {
+ canvas.toBlob((blob) => {
+ if (blob) resolve(blob);
+ else reject(new Error("Unable to render the activity card"));
+ }, "image/png");
+ });
+}
diff --git a/src/utils/helpers.js b/src/utils/helpers.js
index e48e94bea0..7fdf99ccdd 100644
--- a/src/utils/helpers.js
+++ b/src/utils/helpers.js
@@ -1,6 +1,7 @@
import fsOperation from "fileSystem";
import alert from "dialogs/alert";
import escapeStringRegexp from "escape-string-regexp";
+import activity from "lib/activity";
import adRewards from "lib/adRewards";
import config from "lib/config";
import fileIcons from "lib/fileIcons";
@@ -424,6 +425,8 @@ export default {
? await fsOperation(baseUri).createFile(name)
: await fsOperation(baseUri).createDirectory(name);
+ if (expectedType === "file") activity.recordFileCreated();
+
return {
url: createdUrl || targetUri,
created: true,