Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
improve custom cursor performance and enable all cursor state (#223)
Caleb Taylor8c3e886e5629
diff --git a/js/app/packages/app/component/CustomCursorDemo.tsx b/js/app/packages/app/component/CustomCursorDemo.tsxdeleted file mode 100644index 52490e0349..0000000000--- a/js/app/packages/app/component/CustomCursorDemo.tsx+++ /dev/null@@ -1,215 +0,0 @@-import { For, onMount } from 'solid-js';--const ShadowDOMDemo = () => {- let shadowHost: HTMLDivElement | undefined;-- onMount(() => {- if (!shadowHost) return;-- const shadowRoot = shadowHost.attachShadow({ mode: 'open' });-- shadowRoot.innerHTML = `- <style>- :host {- display: block;- padding-top: 4rem;- }- p {- margin: 1em 0;- }- a {- color: var(--color-accent, #3b82f6);- text-decoration: underline;- }- code {- font-family: monospace;- background: rgba(0, 0, 0, 0.05);- padding: 0.125em 0.25em;- border-radius: 0.25em;- }- button {- color: var(--color-accent, #3b82f6);- padding: 0.5rem;- border: 1px solid var(--color-accent, #3b82f6);- background: transparent;- margin: 0 0.25rem;- }- button.cursor-pointer {- cursor: pointer;- }- </style>- <div class="pt-16">- <p>- By creating a- <a href="/en-US/docs/Web/API/BroadcastChannel" class="text-accent underline">- <code>BroadcastChannel</code>- </a>- object, you can receive any messages that are posted to it. You don't have to- <a href="/en-US/docs/Web/API/BroadcastChannel" class="text-accent underline">- <span><code>LINK</code></span>- </a>- maintain a reference to the frames or workers you wish to communicate with: they can "subscribe" to a particular channel by constructing their own- <a href="/en-US/docs/Web/API/BroadcastChannel" class="text-accent underline">- <code>BroadcastChannel</code>- </a>- with the same name, and have bi-directional communication between all of them.- </p>- <p>- The API doesn't associate any semantics to messages,- <button class="text-accent p-2 border-accent border">clicky button</button>- bar- <button class="text-accent p-2 border-accent border">- <span>clicky button 2</span>- </button>- foo- <button class="text-accent p-2 border-accent border cursor-pointer">- <span>clicky button 3</span>- </button>- so it is up to the code to know what kind of messages to expect and what to do with them.- </p>- </div>- `;- });-- return <div ref={shadowHost} />;-};--const CustomCursorDemo = () => {- const cursorTypes = [- // general cursors- { name: 'auto', cursor: 'auto' },- { name: 'default', cursor: 'default' },- { name: 'none', cursor: 'none' },-- // link and status cursors- { name: 'context-menu', cursor: 'context-menu' },- { name: 'help', cursor: 'help' },- { name: 'pointer', cursor: 'pointer' },- { name: 'progress', cursor: 'progress' },- { name: 'wait', cursor: 'wait' },-- // selection cursors- { name: 'cell', cursor: 'cell' },- { name: 'crosshair', cursor: 'crosshair' },- { name: 'text', cursor: 'text' },- { name: 'vertical-text', cursor: 'vertical-text' },-- // drag-and-drop cursors- { name: 'alias', cursor: 'alias' },- { name: 'copy', cursor: 'copy' },- { name: 'move', cursor: 'move' },- { name: 'no-drop', cursor: 'no-drop' },- { name: 'not-allowed', cursor: 'not-allowed' },- { name: 'grab', cursor: 'grab' },- { name: 'grabbing', cursor: 'grabbing' },-- // resizing and scrolling cursors- { name: 'all-scroll', cursor: 'all-scroll' },- { name: 'col-resize', cursor: 'col-resize' },- { name: 'row-resize', cursor: 'row-resize' },- { name: 'n-resize', cursor: 'n-resize' },- { name: 's-resize', cursor: 's-resize' },- { name: 'e-resize', cursor: 'e-resize' },- { name: 'w-resize', cursor: 'w-resize' },- { name: 'ns-resize', cursor: 'ns-resize' },- { name: 'ew-resize', cursor: 'ew-resize' },- { name: 'ne-resize', cursor: 'ne-resize' },- { name: 'nw-resize', cursor: 'nw-resize' },- { name: 'se-resize', cursor: 'se-resize' },- { name: 'sw-resize', cursor: 'sw-resize' },- { name: 'nesw-resize', cursor: 'nesw-resize' },-- // zooming cursors- { name: 'zoom-in', cursor: 'zoom-in' },- { name: 'zoom-out', cursor: 'zoom-out' },- ];-- return (- <div- class="p-8"- ref={(el) => {- onMount(() => {- el.style.overflow = 'auto';- });- }}- >- <style>- {`- :where(*, ::before, ::after) {- user-select: unset;- }-- :where(input, textarea, select, p *, p span, .pdfViewer *, .markdown-content *, [contenteditable], .md *) {- user-select: unset;- }- `}- </style>- <h1 class="text-2xl font-bold mb-6">Custom Cursor Types Demo</h1>- <div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4">- <For each={cursorTypes}>- {({ name, cursor }) => (- <div- class="border border-[var(--color-edge)] p-4 rounded hover:bg-[var(--color-surface-hover)] transition-colors"- style={{ cursor }}- >- {name}- </div>- )}- </For>- </div>- <div class="pt-16">- <p>- By creating a{' '}- <a- href="/en-US/docs/Web/API/BroadcastChannel"- class="text-accent underline"- >- <code>BroadcastChannel</code>- </a>{' '}- object, you can receive any messages that are posted to it. You don't- have to- <a- href="/en-US/docs/Web/API/BroadcastChannel"- class="text-accent underline"- >- <span>- <code>LINK</code>- </span>- </a>{' '}- maintain a reference to the frames or workers you wish to communicate- with: they can "subscribe" to a particular channel by constructing- their own{' '}- <a- href="/en-US/docs/Web/API/BroadcastChannel"- class="text-accent underline"- >- <code>BroadcastChannel</code>- </a>{' '}- with the same name, and have bi-directional communication between all- of them.- </p>- <p>- The API doesn't associate any semantics to messages,- <button class="text-accent p-2 border-accent border">- clicky button- </button>- bar- <button class="text-accent p-2 border-accent border">- <span>clicky button 2</span>- </button>- foo- <button class="text-accent p-2 border-accent border cursor-pointer">- <span>clicky button 3</span>- </button>- so it is up to the code to know what kind of messages to expect and- what to do with them.- </p>- </div>-- <h2 class="pt-16 text-2xl font-bold">Shadow DOM Demo</h2>- <ShadowDOMDemo />- </div>- );-};--export default CustomCursorDemo;diff --git a/js/app/packages/app/component/CustomCursorTest.tsx b/js/app/packages/app/component/CustomCursorTest.tsxnew file mode 100644index 0000000000..5bc0c9f691--- /dev/null+++ b/js/app/packages/app/component/CustomCursorTest.tsx@@ -0,0 +1,281 @@+import { createSignal, For, onMount } from 'solid-js';++const ShadowDOMTest = () => {+ let shadowHost: HTMLDivElement | undefined;++ onMount(() => {+ if (!shadowHost) return;++ const shadowRoot = shadowHost.attachShadow({ mode: 'open' });++ shadowRoot.innerHTML = `+ <style>+ :host {+ display: block;+ padding-top: 4rem;+ }+ p {+ margin: 1em 0;+ }+ a {+ color: var(--color-accent, #3b82f6);+ text-decoration: underline;+ }+ code {+ font-family: monospace;+ background: rgba(0, 0, 0, 0.05);+ padding: 0.125em 0.25em;+ border-radius: 0.25em;+ }+ button {+ color: var(--color-accent, #3b82f6);+ padding: 0.5rem;+ border: 1px solid var(--color-accent, #3b82f6);+ background: transparent;+ margin: 0 0.25rem;+ }+ button.cursor-pointer {+ cursor: pointer;+ }+ </style>+ <div class="pt-16">+ <p>+ By creating a+ <a href="/en-US/docs/Web/API/BroadcastChannel" class="text-accent underline">+ <code>BroadcastChannel</code>+ </a>+ object, you can receive any messages that are posted to it. You don't have to+ <a href="/en-US/docs/Web/API/BroadcastChannel" class="text-accent underline">+ <span><code>LINK</code></span>+ </a>+ maintain a reference to the frames or workers you wish to communicate with: they can "subscribe" to a particular channel by constructing their own+ <a href="/en-US/docs/Web/API/BroadcastChannel" class="text-accent underline">+ <code>BroadcastChannel</code>+ </a>+ with the same name, and have bi-directional communication between all of them.+ </p>+ <p>+ The API doesn't associate any semantics to messages,+ <button class="text-accent p-2 border-accent border">clicky button</button>+ bar+ <button class="text-accent p-2 border-accent border">+ <span>clicky button 2</span>+ </button>+ foo+ <button class="text-accent p-2 border-accent border cursor-pointer">+ <span>clicky button 3</span>+ </button>+ so it is up to the code to know what kind of messages to expect and what to do with them.+ </p>+ </div>+ `;+ });++ return <div ref={shadowHost} />;+};++const CustomCursorTest = () => {+ const [useClass, setUseClass] = createSignal(true);+ const [useStyle, setUseStyle] = createSignal(false);++ const cursorTypes = [+ // general cursors+ { name: 'auto', cursor: 'auto', tw: 'cursor-auto' },+ { name: 'default', cursor: 'default', tw: 'cursor-default' },+ { name: 'none', cursor: 'none', tw: 'cursor-none' },++ // link and status cursors+ { name: 'context-menu', cursor: 'context-menu', tw: 'cursor-context-menu' },+ { name: 'help', cursor: 'help', tw: 'cursor-help' },+ { name: 'pointer', cursor: 'pointer', tw: 'cursor-pointer' },+ { name: 'progress', cursor: 'progress', tw: 'cursor-progress' },+ { name: 'wait', cursor: 'wait', tw: 'cursor-wait' },++ // selection cursors+ { name: 'cell', cursor: 'cell', tw: 'cursor-cell' },+ { name: 'crosshair', cursor: 'crosshair', tw: 'cursor-crosshair' },+ { name: 'text', cursor: 'text', tw: 'cursor-text' },+ {+ name: 'vertical-text',+ cursor: 'vertical-text',+ tw: 'cursor-vertical-text',+ },++ // drag-and-drop cursors+ { name: 'alias', cursor: 'alias', tw: 'cursor-alias' },+ { name: 'copy', cursor: 'copy', tw: 'cursor-copy' },+ { name: 'move', cursor: 'move', tw: 'cursor-move' },+ { name: 'no-drop', cursor: 'no-drop', tw: 'cursor-no-drop' },+ { name: 'not-allowed', cursor: 'not-allowed', tw: 'cursor-not-allowed' },+ { name: 'grab', cursor: 'grab', tw: 'cursor-grab' },+ { name: 'grabbing', cursor: 'grabbing', tw: 'cursor-grabbing' },++ // resizing and scrolling cursors+ { name: 'all-scroll', cursor: 'all-scroll', tw: 'cursor-all-scroll' },+ { name: 'col-resize', cursor: 'col-resize', tw: 'cursor-col-resize' },+ { name: 'row-resize', cursor: 'row-resize', tw: 'cursor-row-resize' },+ { name: 'n-resize', cursor: 'n-resize', tw: 'cursor-n-resize' },+ { name: 's-resize', cursor: 's-resize', tw: 'cursor-s-resize' },+ { name: 'e-resize', cursor: 'e-resize', tw: 'cursor-e-resize' },+ { name: 'w-resize', cursor: 'w-resize', tw: 'cursor-w-resize' },+ { name: 'ns-resize', cursor: 'ns-resize', tw: 'cursor-ns-resize' },+ { name: 'ew-resize', cursor: 'ew-resize', tw: 'cursor-ew-resize' },+ { name: 'ne-resize', cursor: 'ne-resize', tw: 'cursor-ne-resize' },+ { name: 'nw-resize', cursor: 'nw-resize', tw: 'cursor-nw-resize' },+ { name: 'se-resize', cursor: 'se-resize', tw: 'cursor-se-resize' },+ { name: 'sw-resize', cursor: 'sw-resize', tw: 'cursor-sw-resize' },+ { name: 'nesw-resize', cursor: 'nesw-resize', tw: 'cursor-nesw-resize' },++ // zooming cursors+ { name: 'zoom-in', cursor: 'zoom-in', tw: 'cursor-zoom-in' },+ { name: 'zoom-out', cursor: 'zoom-out', tw: 'cursor-zoom-out' },+ ];++ return (+ <div+ class="p-8"+ ref={(el) => {+ onMount(() => {+ el.parentElement!.style.overflow = 'auto';+ });+ }}+ >+ <style>+ {`+ :where(*, ::before, ::after) {+ user-select: unset;+ }++ :where(input, textarea, select, p *, p span, .pdfViewer *, .markdown-content *, [contenteditable], .md *) {+ user-select: unset;+ }+ `}+ </style>+ <h1 class="text-2xl font-bold mb-6">Custom Cursor Types Test</h1>++ <div class="mb-6 flex gap-2 flex-wrap">+ <button+ class={`px-4 py-2 rounded border transition-colors ${+ useClass() && !useStyle()+ ? 'bg-[var(--color-accent)] text-white border-[var(--color-accent)]'+ : 'bg-transparent border-[var(--color-edge)] text-[var(--color-text)] hover:bg-[var(--color-surface-hover)]'+ }`}+ onClick={() => {+ setUseClass(true);+ setUseStyle(false);+ }}+ >+ Class Only+ </button>+ <button+ class={`px-4 py-2 rounded border transition-colors ${+ !useClass() && useStyle()+ ? 'bg-[var(--color-accent)] text-white border-[var(--color-accent)]'+ : 'bg-transparent border-[var(--color-edge)] text-[var(--color-text)] hover:bg-[var(--color-surface-hover)]'+ }`}+ onClick={() => {+ setUseClass(false);+ setUseStyle(true);+ }}+ >+ Style Only+ </button>+ <button+ class={`px-4 py-2 rounded border transition-colors ${+ useClass() && useStyle()+ ? 'bg-[var(--color-accent)] text-white border-[var(--color-accent)]'+ : 'bg-transparent border-[var(--color-edge)] text-[var(--color-text)] hover:bg-[var(--color-surface-hover)]'+ }`}+ onClick={() => {+ setUseClass(true);+ setUseStyle(true);+ }}+ >+ Both (Class + Style)+ </button>+ </div>+ <div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4">+ <For each={cursorTypes}>+ {({ name, cursor, tw }) => (+ <div+ class="border border-[var(--color-edge)] p-4 rounded hover:bg-[var(--color-surface-hover)] transition-colors"+ classList={{ [`${tw}`]: !!tw && useClass() }}+ style={{+ cursor: useStyle() ? cursor : undefined,+ }}+ >+ {name}+ </div>+ )}+ </For>+ </div>+ <div class="pt-16">+ <div+ class="flex items-center text-accent p-2 border-accent border my-4"+ style={{ cursor: 'pointer' }}+ >+ <div>div wrapper with inline style cursor pointer and hr child</div>+ <hr style="border:none;transition:border-color var(--transition);border-top:10px dashed var(--b4);box-sizing:border-box;width:100%;" />+ </div>+ <div class="border border-slate-500 p-2" contenteditable>+ contenteditable+ <ul class="p-2">+ <li class="list-disc mb-6">some text</li>+ <li class="list-disc">some text 2</li>+ </ul>+ </div>+ <p>+ By creating a{' '}+ <a+ href="/en-US/docs/Web/API/BroadcastChannel"+ class="text-accent underline"+ >+ <code>BroadcastChannel</code>+ </a>{' '}+ object, you can receive any messages that are posted to it. You don't+ have to+ <a+ href="/en-US/docs/Web/API/BroadcastChannel"+ class="text-accent underline"+ >+ <span>+ <code>LINK</code>+ </span>+ </a>{' '}+ maintain a reference to the frames or workers you wish to communicate+ with: they can "subscribe" to a particular channel by constructing+ their own{' '}+ <a+ href="/en-US/docs/Web/API/BroadcastChannel"+ class="text-accent underline"+ >+ <code>BroadcastChannel</code>+ </a>{' '}+ with the same name, and have bi-directional communication between all+ of them.+ </p>+ <p>+ The API doesn't associate any semantics to messages,+ <button class="text-accent p-2 border-accent border">+ clicky button+ </button>+ bar+ <button class="text-accent p-2 border-accent border">+ <span>clicky button 2</span>+ </button>+ foo+ <button class="text-accent p-2 border-accent border cursor-pointer">+ <span>clicky button 3</span>+ </button>+ so it is up to the code to know what kind of messages to expect and+ what to do with them.+ </p>+ </div>++ <h2 class="pt-16 text-2xl font-bold">Shadow DOM Demo</h2>+ <ShadowDOMTest />+ </div>+ );+};++export default CustomCursorTest;diff --git a/js/app/packages/app/component/custom-cursor/README.md b/js/app/packages/app/component/custom-cursor/README.mdnew file mode 100644index 0000000000..7eda70872c--- /dev/null+++ b/js/app/packages/app/component/custom-cursor/README.md@@ -0,0 +1,16 @@+# Custom Cursor++## Adding Cursor styling++If you adding cursor styling, as long as you use tailwind cursor variant, such as `cursor-pointer`, or inline style, the custom cursor logic will automatically determine cursor property.++But if you're adding an arbritrary class with cursor property, make sure to add custom cursor variable inside that declaration.++```css+.pointer-on-img {+ /* keep native as fallback when custom cursor is disabled */+ cursor: pointer;+ /* add custom cursor variable */+ --custom-cursor: pointer;+}+```diff --git a/js/app/packages/app/component/custom-cursor/cursor-svg/busy.svg b/js/app/packages/app/component/custom-cursor/cursor-svg/busy.svgindex 741c339120..a1d04eb250 100644--- a/js/app/packages/app/component/custom-cursor/cursor-svg/busy.svg+++ b/js/app/packages/app/component/custom-cursor/cursor-svg/busy.svg@@ -18,4 +18,4 @@}</style>-<linearGradient id="busya" x1="50%" x2="50%" y1="0%" y2="100%"><stop offset="0" stop-color="#4ab4ef"/><stop offset="1" stop-color="#3582e5"/></linearGradient><linearGradient id="busyb" x1="50%" x2="50%" y1="0%" y2="100%"><stop offset="0" stop-color="#3481e4"/><stop offset="1" stop-color="#2051db"/></linearGradient><linearGradient id="busyc" x1="50%" x2="50%" y1="0%" y2="100%"><stop offset="0" stop-color="#6bdcfc"/><stop offset="1" stop-color="#4dc6fa"/></linearGradient><linearGradient id="busyd" x1="50%" x2="50%" y1="0%" y2="100%"><stop offset="0" stop-color="#4bc5f9"/><stop offset="1" stop-color="#2fb0f8"/></linearGradient><mask id="busye" fill="#fff"><path d="m1 23c0 4.971 4.03 9 9 9 4.97 0 9-4.029 9-9 0-4.971-4.03-9-9-9-4.97 0-9 4.029-9 9z" fill="%COLOR-ACCENT%" fill-rule="evenodd"/></mask><g fill="none" fill-rule="evenodd" transform="translate(7)"><g mask="url(#busye)" class="animate-rotate"><g transform="translate(1 14)"><path d="m0 0h9v9h-9z" fill="url(#busya)"/><path d="m9 9h9v9h-9z" fill="url(#busyb)"/><path d="m9 0h9v9h-9z" fill="url(#busyc)"/><path d="m0 9h9v9h-9z" fill="url(#busyd)"/></g></g><g fill-rule="nonzero"><path d="m0 16.422v-16.015l11.591 11.619h-7.041l-.151.124z" fill="%COLOR-ACCENT%"/><path d="m1 2.814v11.188l2.969-2.866.16-.139h5.036z" fill="#000"/></g></g></svg>\ No newline at end of file+<linearGradient id="busya" x1="50%" x2="50%" y1="0%" y2="100%"><stop offset="0" stop-color="#4ab4ef"/><stop offset="1" stop-color="#3582e5"/></linearGradient><linearGradient id="busyb" x1="50%" x2="50%" y1="0%" y2="100%"><stop offset="0" stop-color="#3481e4"/><stop offset="1" stop-color="#2051db"/></linearGradient><linearGradient id="busyc" x1="50%" x2="50%" y1="0%" y2="100%"><stop offset="0" stop-color="#6bdcfc"/><stop offset="1" stop-color="#4dc6fa"/></linearGradient><linearGradient id="busyd" x1="50%" x2="50%" y1="0%" y2="100%"><stop offset="0" stop-color="#4bc5f9"/><stop offset="1" stop-color="#2fb0f8"/></linearGradient><mask id="busye" fill="#fff"><path d="m1 23c0 4.971 4.03 9 9 9 4.97 0 9-4.029 9-9 0-4.971-4.03-9-9-9-4.97 0-9 4.029-9 9z" fill="#fff" fill-rule="evenodd"/></mask><g fill="none" fill-rule="evenodd" transform="translate(7)"><g mask="url(#busye)" class="animate-rotate"><g transform="translate(1 14)"><path d="m0 0h9v9h-9z" fill="url(#busya)"/><path d="m9 9h9v9h-9z" fill="url(#busyb)"/><path d="m9 0h9v9h-9z" fill="url(#busyc)"/><path d="m0 9h9v9h-9z" fill="url(#busyd)"/></g></g><g fill-rule="nonzero"><path d="m0 16.422v-16.015l11.591 11.619h-7.041l-.151.124z" fill="%COLOR-ACCENT%"/><path d="m1 2.814v11.188l2.969-2.866.16-.139h5.036z" fill="#000"/></g></g></svg>\ No newline at end of filediff --git a/js/app/packages/app/component/custom-cursor/custom-cursor.css b/js/app/packages/app/component/custom-cursor/custom-cursor.cssnew file mode 100644index 0000000000..368aca2750--- /dev/null+++ b/js/app/packages/app/component/custom-cursor/custom-cursor.css@@ -0,0 +1,157 @@+/* This sheet is injected into style element appended into document.head and shadowRoots */++a[href] {+ --custom-cursor: pointer;+}+button {+ --custom-cursor: pointer;+}+summary {+ --custom-cursor: pointer;+} /* collapsible <details> */+label {+ --custom-cursor: pointer;+} /* when linked to a control */+input[type="button"],+input[type="submit"],+input[type="reset"] {+ --custom-cursor: pointer;+}+select {+ --custom-cursor: pointer;+}+option {+ --custom-cursor: pointer;+} /* some browsers */+optgroup {+ --custom-cursor: pointer;+}++input[type=text],+input:not([type]), /* default type="text" */+input[type=password],+input[type=search],+input[type=email],+input[type=tel],+input[type=url],+input[type=number], /* on the text area, not the spin box */+textarea,+[contenteditable] {+ --custom-cursor: text;+}++button:disabled,+input:disabled,+select:disabled,+textarea:disabled {+ --custom-cursor: not-allowed;+}++.cursor-auto {+ --custom-cursor: auto;+}+.cursor-default {+ --custom-cursor: default;+}+.cursor-pointer {+ --custom-cursor: pointer;+}+.cursor-wait {+ --custom-cursor: wait;+}+.cursor-text {+ --custom-cursor: text;+}+.cursor-move {+ --custom-cursor: move;+}+.cursor-help {+ --custom-cursor: help;+}+.cursor-not-allowed {+ --custom-cursor: not-allowed;+}+.cursor-none {+ --custom-cursor: none;+}+.cursor-grab {+ --custom-cursor: grab;+}+.cursor-grabbing {+ --custom-cursor: grabbing;+}+.cursor-zoom-in {+ --custom-cursor: zoom-in;+}+.cursor-zoom-out {+ --custom-cursor: zoom-out;+}+.cursor-progress {+ --custom-cursor: progress;+}+.cursor-alias {+ --custom-cursor: alias;+}+.cursor-context-menu {+ --custom-cursor: context-menu;+}+.cursor-cell {+ --custom-cursor: cell;+}+.cursor-crosshair {+ --custom-cursor: crosshair;+}+.cursor-copy {+ --custom-cursor: copy;+}+.cursor-no-drop {+ --custom-cursor: no-drop;+}+.cursor-all-scroll {+ --custom-cursor: all-scroll;+}+.cursor-vertical-text {+ --custom-cursor: vertical-text;+}+.cursor-col-resize {+ --custom-cursor: col-resize;+}+.cursor-row-resize {+ --custom-cursor: row-resize;+}+.cursor-ew-resize {+ --custom-cursor: ew-resize;+}+.cursor-nesw-resize {+ --custom-cursor: nesw-resize;+}+.cursor-ns-resize {+ --custom-cursor: ns-resize;+}+.cursor-nwse-resize {+ --custom-cursor: nwse-resize;+}+.cursor-e-resize {+ --custom-cursor: e-resize;+}+.cursor-n-resize {+ --custom-cursor: n-resize;+}+.cursor-ne-resize {+ --custom-cursor: ne-resize;+}+.cursor-nw-resize {+ --custom-cursor: nw-resize;+}+.cursor-s-resize {+ --custom-cursor: s-resize;+}+.cursor-se-resize {+ --custom-cursor: se-resize;+}+.cursor-sw-resize {+ --custom-cursor: sw-resize;+}+.cursor-w-resize {+ --custom-cursor: w-resize;+}diff --git a/js/app/packages/app/component/custom-cursor/custom-cursor.ts b/js/app/packages/app/component/custom-cursor/custom-cursor.tsindex 06fa0df86e..ab2d1122df 100644--- a/js/app/packages/app/component/custom-cursor/custom-cursor.ts+++ b/js/app/packages/app/component/custom-cursor/custom-cursor.ts@@ -1,6 +1,11 @@-import { getCustomCursorEnabled } from '@app/util/cursor';+import { ENABLE_CUSTOM_CURSOR } from '@core/constant/featureFlags';import { isMobile } from '@solid-primitives/platform';-import { createEffect, createRoot } from 'solid-js';+import {+ createEffect,+ createRoot,+ createSignal,+ createUniqueId,+} from 'solid-js';import { themeReactive } from '../../../block-theme/signals/themeReactive';import busySvgRaw from './cursor-svg/busy.svg?raw';import cellSvgRaw from './cursor-svg/cell.svg?raw';@@ -38,33 +43,15 @@ import textcursorSvgRaw from './cursor-svg/textcursor.svg?raw';import textcursorverticalSvgRaw from './cursor-svg/textcursorvertical.svg?raw';import zoominSvgRaw from './cursor-svg/zoomin.svg?raw';import zoomoutSvgRaw from './cursor-svg/zoomout.svg?raw';+import customCursorCSSFileRaw from './custom-cursor.css?raw';-let cursorStyleEl: HTMLStyleElement | null = null;let defaultCursor: string = '';let hexColor: string = '';let cursorCache: Record<string, string> = {};let currentCursorType: string | null = 'auto';-const shadowRoots = new Set<ShadowRoot>();-let _overridedCursorTargetEl: HTMLElement | null = null;-const _overrideCursorAttr = 'data-override-cursor';-// const overrideCursorSelector = `[${overrideCursorAttr}]`-const overrideCursorSelector = `*`;--// Get or create style elements in all matching shadow roots-function getShadowRootStyleEls(): HTMLStyleElement[] {- const styleElements: HTMLStyleElement[] = [];-- for (const shadowRoot of shadowRoots) {- let styleEl = shadowRoot.querySelector('style');- if (!styleEl) {- styleEl = document.createElement('style');- shadowRoot.appendChild(styleEl);- }- styleElements.push(styleEl);- }+const styleElements = new Set<HTMLStyleElement>();- return styleElements;-}+export const [customCursorEnabled, setCustomCursorEnabled] = createSignal(true);// Extract fallback cursor from custom cursor string (e.g., 'url(...) 11 9, auto' -> 'auto')function extractFallbackCursor(cursor: string): string {@@ -294,7 +281,7 @@ function getCursor(cursorType: string): string {if (!cursorDef.svg) {// For auto, none, all-scroll - return empty or fallbackif (cursorType === 'auto') return cursorMap.default || '';- if (cursorType === 'none') return '';+ if (cursorType === 'none') return 'none';return '';}@@ -320,32 +307,54 @@ function getCursor(cursorType: string): string {return cursorCss;}-function updateCursorStyle() {- if (!currentCursorType) return;- const cursor = getCursor(currentCursorType);-- const cursorStyle = cursor- ? `${overrideCursorSelector} { cursor: ${cursor} !important; }`- : '';+const cursorClassPrefix = createUniqueId();+const getCursorClassFromKey = (key: string) => {+ return `${cursorClassPrefix}-${key}`;+};+const allCustomCursorClasses = Object.keys(cursorSvgMap).map((key) =>+ getCursorClassFromKey(key)+);++function generateCustomCursorStyleTextContent() {+ let styleTextContent = customCursorCSSFileRaw;+ styleTextContent += `${'*'} { cursor: ${getCursor('default')} !important; }`;+ styleTextContent += Object.keys(cursorSvgMap)+ .map((key) => {+ return `+ .${getCursorClassFromKey(key)} {+ cursor: ${getCursor(key)} !important;+ --custom-cursor: ${key};+ }`;+ })+ .join('');+ return styleTextContent;+}+function createCustomCursorStylesheetEl(element: HTMLElement | ShadowRoot) {+ const styleEl = document.createElement('style');+ styleElements.add(styleEl);+ styleEl.textContent = generateCustomCursorStyleTextContent();+ element.appendChild(styleEl);+}- if (cursor) {- cursorStyleEl!.textContent = cursorStyle;- const shadowStyleEls = getShadowRootStyleEls();- for (const shadowStyleEl of shadowStyleEls) {- shadowStyleEl.textContent = cursorStyle;- }- } else {- cursorStyleEl!.textContent = '';- const shadowStyleEls = getShadowRootStyleEls();- for (const shadowStyleEl of shadowStyleEls) {- shadowStyleEl.textContent = '';+function updateAllCustomCursorStylesheetEls() {+ styleElements.forEach((styleEl) => {+ if (!styleEl.isConnected) {+ styleElements.delete(styleEl);+ return;}- }+ styleEl.textContent = generateCustomCursorStyleTextContent();+ });}+const clearAllCustomCursorStylesheetEls = () => {+ styleElements.forEach((styleEl) => {+ styleEl.textContent = '';+ });+};+function updateCursor() {updateCustomCursor();- updateCursorStyle();+ updateAllCustomCursorStylesheetEls();}function updateCustomCursor() {@@ -378,54 +387,54 @@ function updateCustomCursor() {cursorMap.default = defaultCursor;}-const clearCursorOverrideStyle = () => {- cursorStyleEl!.textContent = '';- const shadowStyleEls = getShadowRootStyleEls();- for (const shadowStyleEl of shadowStyleEls) {- shadowStyleEl.textContent = '';- }-};-// Initialize cursorfunction initCursor() {+ if (!ENABLE_CUSTOM_CURSOR) return;+if (isMobile) return;updateCustomCursor();-- // Initialize cursor style element- if (!cursorStyleEl) {- cursorStyleEl = document.createElement('style');- cursorStyleEl.id = 'custom-cursor-style';- document.head.appendChild(cursorStyleEl);- }+ createCustomCursorStylesheetEl(document.head);// Add mousemove listener to handle cursor states and text glyph detection- const _onMouseMove = (e: MouseEvent) => {- if (!getCustomCursorEnabled()) {- clearCursorOverrideStyle();+ const onMouseMove = (e: MouseEvent) => {+ if (!customCursorEnabled()) {+ clearAllCustomCursorStylesheetEls();return;}const target = e.target as Element;if (target.shadowRoot) {- shadowRoots.add(target.shadowRoot);+ createCustomCursorStylesheetEl(target.shadowRoot);+[...target.shadowRoot.children].forEach((child) => {- child.addEventListener('mousemove', _onMouseMove);+ child.addEventListener('mousemove', onMouseMove);});return;}- clearCursorOverrideStyle();-- const targetComputedStyle = getComputedStyle(target);- const computedCursor = targetComputedStyle.cursor;- const computedUserSelect = targetComputedStyle.userSelect;- // TODO: maybe use attribute selector instead of wild card selector to improve perf- // target.setAttribute(overrideCursorAttr, '')- // if (target !== overridedCursorTargetEl) {- // overridedCursorTargetEl?.removeAttribute(overrideCursorAttr)- // }- // overridedCursorTargetEl = target as HTMLElement+ target.classList.remove(...allCustomCursorClasses);++ const getCursorValueFromTargetEl = (target: Element) => {+ const run = () => {+ if (target instanceof HTMLElement && target.style.cursor) {+ return target.style.cursor;+ }+ const targetComputedStyle = getComputedStyle(target);+ const customCursorCSSVariableValue =+ targetComputedStyle.getPropertyValue('--custom-cursor');+ if (customCursorCSSVariableValue) {+ return customCursorCSSVariableValue;+ }++ return targetComputedStyle.cursor;+ };+ return run().replace('!important', '');+ };++ const computedCursor = getCursorValueFromTargetEl(target);+ const computedUserSelect = getComputedStyle(target).userSelect;+ // target.classList.add(getCursorClassFromKey(currentCursorType!));// Extract fallback cursor if computed cursor is a custom cursor stringconst baseCursor = extractFallbackCursor(computedCursor);@@ -435,28 +444,25 @@ function initCursor() {// Use inferred cursor type if available, otherwise use extracted fallback cursorlet cs = inferredCursorType || baseCursor;- // Only use text glyph detection when cursor is 'auto'- if (cs === 'auto' && isOverTextGlyph(e.clientX, e.clientY)) {- if (computedUserSelect === 'none') {- cs = 'default';- } else {- cs = 'text';- }- if (target.tagName === 'BUTTON' || target.closest('button')) {- cs = 'default';+ // Only use text glyph detection when cursor is 'auto' and not 'text'+ if (cs !== 'text') {+ if (cs === 'auto' && isOverTextGlyph(e.clientX, e.clientY)) {+ if (computedUserSelect === 'none') {+ cs = 'default';+ } else {+ cs = 'text';+ }+ if (target.tagName === 'BUTTON' || target.closest('button')) {+ cs = 'default';+ }}}currentCursorType = cs;- // TODO: Only update if cursor type changed- // if (cs === currentCursorType) {- // return;- // }-- updateCursorStyle();+ target.classList.add(getCursorClassFromKey(currentCursorType));};- // document.addEventListener('mousemove', onMouseMove);+ document.addEventListener('mousemove', onMouseMove);}if (document.readyState === 'loading') {@@ -465,32 +471,16 @@ if (document.readyState === 'loading') {initCursor();}-// Watch for theme changes and preference changes-let lastAccentColor = '';-let lastCursorEnabled = getCustomCursorEnabled();-createRoot(() => {+ if (!ENABLE_CUSTOM_CURSOR) return;+createEffect(() => {const { l, c, h } = themeReactive.a0;const col = `oklch(${l[0]()} ${c[0]()} ${h[0]()}deg)`;-- const currentAccentColor = col;- const currentCursorEnabled = getCustomCursorEnabled();-- if (- (currentAccentColor && currentAccentColor !== lastAccentColor) ||- currentCursorEnabled !== lastCursorEnabled- ) {- lastAccentColor = currentAccentColor;- lastCursorEnabled = currentCursorEnabled;-- updateCursor();+ if (!customCursorEnabled()) {+ clearAllCustomCursorStylesheetEls();+ return;}+ updateCursor();});});--// Listen for immediate preference changes-window.addEventListener('cursor-preference-changed', () => {- lastCursorEnabled = getCustomCursorEnabled();- updateCustomCursor();-});diff --git a/js/app/packages/app/component/settings/Appearance.tsx b/js/app/packages/app/component/settings/Appearance.tsxindex ff61a0de8a..df762ed977 100644--- a/js/app/packages/app/component/settings/Appearance.tsx+++ b/js/app/packages/app/component/settings/Appearance.tsx@@ -8,21 +8,23 @@ import { ThemeEditorAdvanced } from '../../../block-theme/components/ThemeEditorimport { ThemeEditorBasic } from '../../../block-theme/components/ThemeEditorBasic';import ThemeList from '../../../block-theme/components/ThemeList';import ThemeTools from '../../../block-theme/components/ThemeTools';-import {- getCustomCursorEnabled,- setCustomCursorEnabled,-} from '../../util/cursor';+// import {+// getCustomCursorEnabled,+// setCustomCursorEnabled,+// } from '../../util/cursor';import {getSoundEffectsEnabled,getSoundEffectsVolume,setSoundEffectsEnabled,setSoundEffectsVolume,} from '../../util/soundSettings';+import {+ customCursorEnabled,+ setCustomCursorEnabled,+} from '../custom-cursor/custom-cursor';export function Appearance() {- const [cursorEnabled, setCursorEnabled] = createSignal(- getCustomCursorEnabled()- );+ const [cursorEnabled, setCursorEnabled] = createSignal(customCursorEnabled());const [soundEnabled, setSoundEnabled] = createSignal(getSoundEffectsEnabled());diff --git a/js/app/packages/app/component/split-layout/componentRegistry.tsx b/js/app/packages/app/component/split-layout/componentRegistry.tsxindex 4dccf98636..423ff3a82f 100644--- a/js/app/packages/app/component/split-layout/componentRegistry.tsx+++ b/js/app/packages/app/component/split-layout/componentRegistry.tsx@@ -72,7 +72,7 @@ if (LOCAL_ONLY) {);registerComponent('custom-cursor',- lazy(() => import('@app/component/CustomCursorDemo'))+ lazy(() => import('@app/component/CustomCursorTest')));registerComponent('resize',diff --git a/js/app/packages/app/util/cursor.ts b/js/app/packages/app/util/cursor.tsdeleted file mode 100644index c0e1bdf696..0000000000--- a/js/app/packages/app/util/cursor.ts+++ /dev/null@@ -1,12 +0,0 @@-const CURSOR_ENABLED_KEY = 'custom-cursor-enabled';--export function getCustomCursorEnabled(): boolean {- const stored = localStorage.getItem(CURSOR_ENABLED_KEY);- return stored === null ? true : stored === 'true';-}--export function setCustomCursorEnabled(enabled: boolean) {- localStorage.setItem(CURSOR_ENABLED_KEY, String(enabled));- // Dispatch event to notify cursor code of preference change- window.dispatchEvent(new CustomEvent('cursor-preference-changed'));-}diff --git a/js/app/packages/core/constant/featureFlags.ts b/js/app/packages/core/constant/featureFlags.tsindex f91970933d..9a1553d965 100644--- a/js/app/packages/core/constant/featureFlags.ts+++ b/js/app/packages/core/constant/featureFlags.ts@@ -152,3 +152,5 @@ export const ENABLE_PREVIEW = true;export const ENABLE_DOCK_NOTITIFCATIONS = DEV_MODE_ENV;export const ENABLE_TTFT = DEV_MODE_ENV;++export const ENABLE_CUSTOM_CURSOR = true;