@tldraw/editor 5.2.0-next.355d68cf24e8 → 5.2.0-next.79b13319d317

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/dist-cjs/index.d.ts +2 -36
  3. package/dist-cjs/index.js +3 -4
  4. package/dist-cjs/index.js.map +2 -2
  5. package/dist-cjs/lib/editor/Editor.js +17 -3
  6. package/dist-cjs/lib/editor/Editor.js.map +2 -2
  7. package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js +1 -1
  8. package/dist-cjs/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.js.map +2 -2
  9. package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js +79 -0
  10. package/dist-cjs/lib/editor/overlays/strokeShapeIndicators.js.map +7 -0
  11. package/dist-cjs/version.js +3 -3
  12. package/dist-cjs/version.js.map +1 -1
  13. package/dist-esm/index.d.mts +2 -36
  14. package/dist-esm/index.mjs +2 -6
  15. package/dist-esm/index.mjs.map +2 -2
  16. package/dist-esm/lib/editor/Editor.mjs +17 -3
  17. package/dist-esm/lib/editor/Editor.mjs.map +2 -2
  18. package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs +1 -1
  19. package/dist-esm/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.mjs.map +2 -2
  20. package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs +59 -0
  21. package/dist-esm/lib/editor/overlays/strokeShapeIndicators.mjs.map +7 -0
  22. package/dist-esm/version.mjs +3 -3
  23. package/dist-esm/version.mjs.map +1 -1
  24. package/editor.css +2 -0
  25. package/package.json +8 -8
  26. package/src/index.ts +1 -5
  27. package/src/lib/editor/Editor.ts +24 -3
  28. package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.test.ts +14 -0
  29. package/src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.ts +6 -3
  30. package/src/lib/editor/managers/FontManager/FontManager.test.ts +13 -9
  31. package/src/lib/editor/managers/TextManager/TextManager.test.ts +16 -14
  32. package/src/lib/editor/overlays/strokeShapeIndicators.ts +86 -0
  33. package/src/version.ts +3 -3
  34. package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js +0 -161
  35. package/dist-cjs/lib/editor/overlays/ShapeIndicatorOverlayUtil.js.map +0 -7
  36. package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs +0 -141
  37. package/dist-esm/lib/editor/overlays/ShapeIndicatorOverlayUtil.mjs.map +0 -7
  38. package/src/lib/editor/overlays/ShapeIndicatorOverlayUtil.ts +0 -216
@@ -61,7 +61,7 @@ class CollaboratorsManager {
61
61
  const currentUserId = this.editor.user.getId();
62
62
  return collaborators.filter((presence) => {
63
63
  const { lastActivityTimestamp, userId, chatMessage } = presence;
64
- const elapsed = Math.max(0, now - (lastActivityTimestamp ?? now));
64
+ const elapsed = lastActivityTimestamp ? Math.max(0, now - lastActivityTimestamp) : 0;
65
65
  if (elapsed > collaboratorInactiveTimeoutMs) {
66
66
  return followingUserId === userId || highlightedUserIds.includes(userId);
67
67
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/lib/editor/managers/CollaboratorsManager/CollaboratorsManager.ts"],
4
- "sourcesContent": ["import { EMPTY_ARRAY, atom, computed } from '@tldraw/state'\nimport type { TLInstancePresence } from '@tldraw/tlschema'\nimport { maxBy } from '@tldraw/utils'\nimport type { Editor } from '../../Editor'\n\n/**\n * Tracks remote peers and exposes the collaborator-related queries used by the\n * editor and its overlays. Encapsulates the visibility clock that periodically\n * re-evaluates which collaborators should be visible based on activity.\n *\n * Accessed via {@link Editor.collaborators}.\n *\n * @public\n */\nexport class CollaboratorsManager {\n\tconstructor(private readonly editor: Editor) {}\n\n\tprivate _visibilityClockStarted = false\n\n\tprivate _startVisibilityClock() {\n\t\tif (this._visibilityClockStarted) return\n\t\tthis._visibilityClockStarted = true\n\n\t\t// Editor disposes `editor.timers` on its own teardown, so the interval is\n\t\t// automatically cleared when the editor is disposed.\n\t\tthis.editor.timers.setInterval(() => {\n\t\t\tthis._visibilityClock.set(Date.now())\n\t\t}, this.editor.options.collaboratorCheckIntervalMs)\n\t}\n\n\t/**\n\t * Drives reactive re-evaluation of {@link CollaboratorsManager.getVisibleCollaborators}.\n\t * Ticked on a fixed interval so callers don't need to manage their own activity timers.\n\t */\n\tprivate readonly _visibilityClock = atom('collaboratorVisibilityClock', Date.now())\n\n\t@computed\n\tprivate _getCollaboratorsQuery() {\n\t\treturn this.editor.store.query.records('instance_presence', () => ({\n\t\t\tuserId: { neq: this.editor.user.getId() },\n\t\t}))\n\t}\n\n\t/**\n\t * Returns a list of presence records for all peer collaborators.\n\t * This will return the latest presence record for each connected user.\n\t */\n\t@computed\n\tgetCollaborators(): TLInstancePresence[] {\n\t\tconst allPresenceRecords = this._getCollaboratorsQuery().get()\n\t\tif (!allPresenceRecords.length) return EMPTY_ARRAY\n\t\tconst userIds = [...new Set(allPresenceRecords.map((c) => c.userId))].sort()\n\t\treturn userIds.map((id) => {\n\t\t\tconst latestPresence = maxBy(\n\t\t\t\tallPresenceRecords.filter((c) => c.userId === id),\n\t\t\t\t(p) => p.lastActivityTimestamp ?? 0\n\t\t\t)\n\t\t\treturn latestPresence!\n\t\t})\n\t}\n\n\t/**\n\t * Returns a list of presence records for all peer collaborators on the current page.\n\t * This will return the latest presence record for each connected user.\n\t */\n\t@computed\n\tgetCollaboratorsOnCurrentPage(): TLInstancePresence[] {\n\t\tconst currentPageId = this.editor.getCurrentPageId()\n\t\treturn this.getCollaborators().filter((c) => c.currentPageId === currentPageId)\n\t}\n\n\t/**\n\t * Returns a list of presence records for peer collaborators who should currently be\n\t * shown in the UI. Filters {@link CollaboratorsManager.getCollaborators} by activity\n\t * state (active / idle / inactive) and visibility rules such as following and\n\t * highlighted users. Re-evaluates on the visibility clock, so callers don't need to\n\t * drive their own activity timer.\n\t */\n\t@computed\n\tgetVisibleCollaborators(): TLInstancePresence[] {\n\t\tconst { editor } = this\n\t\tconst { collaboratorInactiveTimeoutMs, collaboratorIdleTimeoutMs } = editor.options\n\n\t\tthis._startVisibilityClock()\n\t\tthis._visibilityClock.get()\n\t\tconst now = Date.now()\n\t\tconst collaborators = this.getCollaborators()\n\t\tif (!collaborators.length) return EMPTY_ARRAY\n\n\t\tconst { followingUserId, highlightedUserIds } = this.editor.getInstanceState()\n\t\tconst currentUserId = this.editor.user.getId()\n\n\t\treturn collaborators.filter((presence) => {\n\t\t\tconst { lastActivityTimestamp, userId, chatMessage } = presence\n\n\t\t\t// Treat a missing `lastActivityTimestamp` as \"active right now\" (elapsed = 0)\n\t\t\t// so newly-joined peers aren't immediately classified as idle/inactive.\n\t\t\tconst elapsed = Math.max(0, now - (lastActivityTimestamp ?? now))\n\n\t\t\tif (elapsed > collaboratorInactiveTimeoutMs) {\n\t\t\t\t// Inactive: If they're inactive, only show if we're following them or they're highlighted\n\t\t\t\treturn followingUserId === userId || highlightedUserIds.includes(userId)\n\t\t\t}\n\n\t\t\tif (elapsed > collaboratorIdleTimeoutMs) {\n\t\t\t\t// Idle: If they're idle and following us, hide them unless they have a chat message or are highlighted\n\t\t\t\tif (presence.followingUserId === currentUserId) {\n\t\t\t\t\treturn !!(chatMessage || highlightedUserIds.includes(userId))\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Active\n\t\t\treturn true\n\t\t})\n\t}\n\n\t/**\n\t * Returns a list of presence records for peer collaborators who should currently be\n\t * shown in the UI, filtered to those on the current page.\n\t */\n\t@computed\n\tgetVisibleCollaboratorsOnCurrentPage(): TLInstancePresence[] {\n\t\tconst currentPageId = this.editor.getCurrentPageId()\n\t\treturn this.getVisibleCollaborators().filter((c) => c.currentPageId === currentPageId)\n\t}\n}\n"],
5
- "mappings": ";;;;;;;;;;AAAA,SAAS,aAAa,MAAM,gBAAgB;AAE5C,SAAS,aAAa;AAYf,MAAM,qBAAqB;AAAA,EACjC,YAA6B,QAAgB;AAAhB;AAAA,EAAiB;AAAA,EAAjB;AAAA,EAErB,0BAA0B;AAAA,EAE1B,wBAAwB;AAC/B,QAAI,KAAK,wBAAyB;AAClC,SAAK,0BAA0B;AAI/B,SAAK,OAAO,OAAO,YAAY,MAAM;AACpC,WAAK,iBAAiB,IAAI,KAAK,IAAI,CAAC;AAAA,IACrC,GAAG,KAAK,OAAO,QAAQ,2BAA2B;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMiB,mBAAmB,KAAK,+BAA+B,KAAK,IAAI,CAAC;AAAA,EAG1E,yBAAyB;AAChC,WAAO,KAAK,OAAO,MAAM,MAAM,QAAQ,qBAAqB,OAAO;AAAA,MAClE,QAAQ,EAAE,KAAK,KAAK,OAAO,KAAK,MAAM,EAAE;AAAA,IACzC,EAAE;AAAA,EACH;AAAA,EAOA,mBAAyC;AACxC,UAAM,qBAAqB,KAAK,uBAAuB,EAAE,IAAI;AAC7D,QAAI,CAAC,mBAAmB,OAAQ,QAAO;AACvC,UAAM,UAAU,CAAC,GAAG,IAAI,IAAI,mBAAmB,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK;AAC3E,WAAO,QAAQ,IAAI,CAAC,OAAO;AAC1B,YAAM,iBAAiB;AAAA,QACtB,mBAAmB,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE;AAAA,QAChD,CAAC,MAAM,EAAE,yBAAyB;AAAA,MACnC;AACA,aAAO;AAAA,IACR,CAAC;AAAA,EACF;AAAA,EAOA,gCAAsD;AACrD,UAAM,gBAAgB,KAAK,OAAO,iBAAiB;AACnD,WAAO,KAAK,iBAAiB,EAAE,OAAO,CAAC,MAAM,EAAE,kBAAkB,aAAa;AAAA,EAC/E;AAAA,EAUA,0BAAgD;AAC/C,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,EAAE,+BAA+B,0BAA0B,IAAI,OAAO;AAE5E,SAAK,sBAAsB;AAC3B,SAAK,iBAAiB,IAAI;AAC1B,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,gBAAgB,KAAK,iBAAiB;AAC5C,QAAI,CAAC,cAAc,OAAQ,QAAO;AAElC,UAAM,EAAE,iBAAiB,mBAAmB,IAAI,KAAK,OAAO,iBAAiB;AAC7E,UAAM,gBAAgB,KAAK,OAAO,KAAK,MAAM;AAE7C,WAAO,cAAc,OAAO,CAAC,aAAa;AACzC,YAAM,EAAE,uBAAuB,QAAQ,YAAY,IAAI;AAIvD,YAAM,UAAU,KAAK,IAAI,GAAG,OAAO,yBAAyB,IAAI;AAEhE,UAAI,UAAU,+BAA+B;AAE5C,eAAO,oBAAoB,UAAU,mBAAmB,SAAS,MAAM;AAAA,MACxE;AAEA,UAAI,UAAU,2BAA2B;AAExC,YAAI,SAAS,oBAAoB,eAAe;AAC/C,iBAAO,CAAC,EAAE,eAAe,mBAAmB,SAAS,MAAM;AAAA,QAC5D;AAAA,MACD;AAGA,aAAO;AAAA,IACR,CAAC;AAAA,EACF;AAAA,EAOA,uCAA6D;AAC5D,UAAM,gBAAgB,KAAK,OAAO,iBAAiB;AACnD,WAAO,KAAK,wBAAwB,EAAE,OAAO,CAAC,MAAM,EAAE,kBAAkB,aAAa;AAAA,EACtF;AACD;AAxFS;AAAA,EADP;AAAA,GAtBW,qBAuBJ;AAWR;AAAA,EADC;AAAA,GAjCW,qBAkCZ;AAkBA;AAAA,EADC;AAAA,GAnDW,qBAoDZ;AAaA;AAAA,EADC;AAAA,GAhEW,qBAiEZ;AA0CA;AAAA,EADC;AAAA,GA1GW,qBA2GZ;",
4
+ "sourcesContent": ["import { EMPTY_ARRAY, atom, computed } from '@tldraw/state'\nimport type { TLInstancePresence } from '@tldraw/tlschema'\nimport { maxBy } from '@tldraw/utils'\nimport type { Editor } from '../../Editor'\n\n/**\n * Tracks remote peers and exposes the collaborator-related queries used by the\n * editor and its overlays. Encapsulates the visibility clock that periodically\n * re-evaluates which collaborators should be visible based on activity.\n *\n * Accessed via {@link Editor.collaborators}.\n *\n * @public\n */\nexport class CollaboratorsManager {\n\tconstructor(private readonly editor: Editor) {}\n\n\tprivate _visibilityClockStarted = false\n\n\tprivate _startVisibilityClock() {\n\t\tif (this._visibilityClockStarted) return\n\t\tthis._visibilityClockStarted = true\n\n\t\t// Editor disposes `editor.timers` on its own teardown, so the interval is\n\t\t// automatically cleared when the editor is disposed.\n\t\tthis.editor.timers.setInterval(() => {\n\t\t\tthis._visibilityClock.set(Date.now())\n\t\t}, this.editor.options.collaboratorCheckIntervalMs)\n\t}\n\n\t/**\n\t * Drives reactive re-evaluation of {@link CollaboratorsManager.getVisibleCollaborators}.\n\t * Ticked on a fixed interval so callers don't need to manage their own activity timers.\n\t */\n\tprivate readonly _visibilityClock = atom('collaboratorVisibilityClock', Date.now())\n\n\t@computed\n\tprivate _getCollaboratorsQuery() {\n\t\treturn this.editor.store.query.records('instance_presence', () => ({\n\t\t\tuserId: { neq: this.editor.user.getId() },\n\t\t}))\n\t}\n\n\t/**\n\t * Returns a list of presence records for all peer collaborators.\n\t * This will return the latest presence record for each connected user.\n\t */\n\t@computed\n\tgetCollaborators(): TLInstancePresence[] {\n\t\tconst allPresenceRecords = this._getCollaboratorsQuery().get()\n\t\tif (!allPresenceRecords.length) return EMPTY_ARRAY\n\t\tconst userIds = [...new Set(allPresenceRecords.map((c) => c.userId))].sort()\n\t\treturn userIds.map((id) => {\n\t\t\tconst latestPresence = maxBy(\n\t\t\t\tallPresenceRecords.filter((c) => c.userId === id),\n\t\t\t\t(p) => p.lastActivityTimestamp ?? 0\n\t\t\t)\n\t\t\treturn latestPresence!\n\t\t})\n\t}\n\n\t/**\n\t * Returns a list of presence records for all peer collaborators on the current page.\n\t * This will return the latest presence record for each connected user.\n\t */\n\t@computed\n\tgetCollaboratorsOnCurrentPage(): TLInstancePresence[] {\n\t\tconst currentPageId = this.editor.getCurrentPageId()\n\t\treturn this.getCollaborators().filter((c) => c.currentPageId === currentPageId)\n\t}\n\n\t/**\n\t * Returns a list of presence records for peer collaborators who should currently be\n\t * shown in the UI. Filters {@link CollaboratorsManager.getCollaborators} by activity\n\t * state (active / idle / inactive) and visibility rules such as following and\n\t * highlighted users. Re-evaluates on the visibility clock, so callers don't need to\n\t * drive their own activity timer.\n\t */\n\t@computed\n\tgetVisibleCollaborators(): TLInstancePresence[] {\n\t\tconst { editor } = this\n\t\tconst { collaboratorInactiveTimeoutMs, collaboratorIdleTimeoutMs } = editor.options\n\n\t\tthis._startVisibilityClock()\n\t\tthis._visibilityClock.get()\n\t\tconst now = Date.now()\n\t\tconst collaborators = this.getCollaborators()\n\t\tif (!collaborators.length) return EMPTY_ARRAY\n\n\t\tconst { followingUserId, highlightedUserIds } = this.editor.getInstanceState()\n\t\tconst currentUserId = this.editor.user.getId()\n\n\t\treturn collaborators.filter((presence) => {\n\t\t\tconst { lastActivityTimestamp, userId, chatMessage } = presence\n\n\t\t\t// Treat a missing or zero `lastActivityTimestamp` as \"active right now\"\n\t\t\t// (elapsed = 0) so newly-joined peers aren't immediately classified as\n\t\t\t// idle/inactive. The broadcast default for peers who haven't moved their\n\t\t\t// pointer yet is `0` (e.g. someone on a touch device who joins and just\n\t\t\t// watches), so a plain `?? now` would leave them hidden. See issue #9017.\n\t\t\tconst elapsed = lastActivityTimestamp ? Math.max(0, now - lastActivityTimestamp) : 0\n\n\t\t\tif (elapsed > collaboratorInactiveTimeoutMs) {\n\t\t\t\t// Inactive: If they're inactive, only show if we're following them or they're highlighted\n\t\t\t\treturn followingUserId === userId || highlightedUserIds.includes(userId)\n\t\t\t}\n\n\t\t\tif (elapsed > collaboratorIdleTimeoutMs) {\n\t\t\t\t// Idle: If they're idle and following us, hide them unless they have a chat message or are highlighted\n\t\t\t\tif (presence.followingUserId === currentUserId) {\n\t\t\t\t\treturn !!(chatMessage || highlightedUserIds.includes(userId))\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Active\n\t\t\treturn true\n\t\t})\n\t}\n\n\t/**\n\t * Returns a list of presence records for peer collaborators who should currently be\n\t * shown in the UI, filtered to those on the current page.\n\t */\n\t@computed\n\tgetVisibleCollaboratorsOnCurrentPage(): TLInstancePresence[] {\n\t\tconst currentPageId = this.editor.getCurrentPageId()\n\t\treturn this.getVisibleCollaborators().filter((c) => c.currentPageId === currentPageId)\n\t}\n}\n"],
5
+ "mappings": ";;;;;;;;;;AAAA,SAAS,aAAa,MAAM,gBAAgB;AAE5C,SAAS,aAAa;AAYf,MAAM,qBAAqB;AAAA,EACjC,YAA6B,QAAgB;AAAhB;AAAA,EAAiB;AAAA,EAAjB;AAAA,EAErB,0BAA0B;AAAA,EAE1B,wBAAwB;AAC/B,QAAI,KAAK,wBAAyB;AAClC,SAAK,0BAA0B;AAI/B,SAAK,OAAO,OAAO,YAAY,MAAM;AACpC,WAAK,iBAAiB,IAAI,KAAK,IAAI,CAAC;AAAA,IACrC,GAAG,KAAK,OAAO,QAAQ,2BAA2B;AAAA,EACnD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMiB,mBAAmB,KAAK,+BAA+B,KAAK,IAAI,CAAC;AAAA,EAG1E,yBAAyB;AAChC,WAAO,KAAK,OAAO,MAAM,MAAM,QAAQ,qBAAqB,OAAO;AAAA,MAClE,QAAQ,EAAE,KAAK,KAAK,OAAO,KAAK,MAAM,EAAE;AAAA,IACzC,EAAE;AAAA,EACH;AAAA,EAOA,mBAAyC;AACxC,UAAM,qBAAqB,KAAK,uBAAuB,EAAE,IAAI;AAC7D,QAAI,CAAC,mBAAmB,OAAQ,QAAO;AACvC,UAAM,UAAU,CAAC,GAAG,IAAI,IAAI,mBAAmB,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK;AAC3E,WAAO,QAAQ,IAAI,CAAC,OAAO;AAC1B,YAAM,iBAAiB;AAAA,QACtB,mBAAmB,OAAO,CAAC,MAAM,EAAE,WAAW,EAAE;AAAA,QAChD,CAAC,MAAM,EAAE,yBAAyB;AAAA,MACnC;AACA,aAAO;AAAA,IACR,CAAC;AAAA,EACF;AAAA,EAOA,gCAAsD;AACrD,UAAM,gBAAgB,KAAK,OAAO,iBAAiB;AACnD,WAAO,KAAK,iBAAiB,EAAE,OAAO,CAAC,MAAM,EAAE,kBAAkB,aAAa;AAAA,EAC/E;AAAA,EAUA,0BAAgD;AAC/C,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,EAAE,+BAA+B,0BAA0B,IAAI,OAAO;AAE5E,SAAK,sBAAsB;AAC3B,SAAK,iBAAiB,IAAI;AAC1B,UAAM,MAAM,KAAK,IAAI;AACrB,UAAM,gBAAgB,KAAK,iBAAiB;AAC5C,QAAI,CAAC,cAAc,OAAQ,QAAO;AAElC,UAAM,EAAE,iBAAiB,mBAAmB,IAAI,KAAK,OAAO,iBAAiB;AAC7E,UAAM,gBAAgB,KAAK,OAAO,KAAK,MAAM;AAE7C,WAAO,cAAc,OAAO,CAAC,aAAa;AACzC,YAAM,EAAE,uBAAuB,QAAQ,YAAY,IAAI;AAOvD,YAAM,UAAU,wBAAwB,KAAK,IAAI,GAAG,MAAM,qBAAqB,IAAI;AAEnF,UAAI,UAAU,+BAA+B;AAE5C,eAAO,oBAAoB,UAAU,mBAAmB,SAAS,MAAM;AAAA,MACxE;AAEA,UAAI,UAAU,2BAA2B;AAExC,YAAI,SAAS,oBAAoB,eAAe;AAC/C,iBAAO,CAAC,EAAE,eAAe,mBAAmB,SAAS,MAAM;AAAA,QAC5D;AAAA,MACD;AAGA,aAAO;AAAA,IACR,CAAC;AAAA,EACF;AAAA,EAOA,uCAA6D;AAC5D,UAAM,gBAAgB,KAAK,OAAO,iBAAiB;AACnD,WAAO,KAAK,wBAAwB,EAAE,OAAO,CAAC,MAAM,EAAE,kBAAkB,aAAa;AAAA,EACtF;AACD;AA3FS;AAAA,EADP;AAAA,GAtBW,qBAuBJ;AAWR;AAAA,EADC;AAAA,GAjCW,qBAkCZ;AAkBA;AAAA,EADC;AAAA,GAnDW,qBAoDZ;AAaA;AAAA,EADC;AAAA,GAhEW,qBAiEZ;AA6CA;AAAA,EADC;AAAA,GA7GW,qBA8GZ;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,59 @@
1
+ import { createComputedCache } from "@tldraw/store";
2
+ const indicatorPathCache = createComputedCache(
3
+ "shapeIndicatorPath",
4
+ (editor, shape) => {
5
+ const util = editor.getShapeUtil(shape);
6
+ return util.getIndicatorPath(shape);
7
+ },
8
+ {
9
+ areRecordsEqual(a, b) {
10
+ return a.props === b.props;
11
+ }
12
+ }
13
+ );
14
+ function strokeShapeIndicators(editor, ctx, shapeIds) {
15
+ if (shapeIds.length === 0) return;
16
+ const batched = new Path2D();
17
+ for (const shapeId of shapeIds) {
18
+ const shape = editor.getShape(shapeId);
19
+ if (!shape || shape.isLocked) continue;
20
+ const pageTransform = editor.getShapePageTransform(shape);
21
+ if (!pageTransform) continue;
22
+ const indicatorPath = indicatorPathCache.get(editor, shape.id);
23
+ if (!indicatorPath) continue;
24
+ if (indicatorPath instanceof Path2D) {
25
+ batched.addPath(indicatorPath, pageTransform);
26
+ continue;
27
+ }
28
+ const { path, clipPath, additionalPaths } = indicatorPath;
29
+ if (!clipPath) {
30
+ batched.addPath(path, pageTransform);
31
+ if (additionalPaths) {
32
+ for (const p of additionalPaths) batched.addPath(p, pageTransform);
33
+ }
34
+ continue;
35
+ }
36
+ ctx.save();
37
+ ctx.transform(
38
+ pageTransform.a,
39
+ pageTransform.b,
40
+ pageTransform.c,
41
+ pageTransform.d,
42
+ pageTransform.e,
43
+ pageTransform.f
44
+ );
45
+ ctx.save();
46
+ ctx.clip(clipPath, "evenodd");
47
+ ctx.stroke(path);
48
+ ctx.restore();
49
+ if (additionalPaths) {
50
+ for (const p of additionalPaths) ctx.stroke(p);
51
+ }
52
+ ctx.restore();
53
+ }
54
+ ctx.stroke(batched);
55
+ }
56
+ export {
57
+ strokeShapeIndicators
58
+ };
59
+ //# sourceMappingURL=strokeShapeIndicators.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/lib/editor/overlays/strokeShapeIndicators.ts"],
4
+ "sourcesContent": ["import { createComputedCache } from '@tldraw/store'\nimport { TLShape, TLShapeId } from '@tldraw/tlschema'\nimport type { Editor } from '../Editor'\n\nconst indicatorPathCache = createComputedCache(\n\t'shapeIndicatorPath',\n\t(editor: Editor, shape: TLShape) => {\n\t\tconst util = editor.getShapeUtil(shape)\n\t\treturn util.getIndicatorPath(shape)\n\t},\n\t{\n\t\tareRecordsEqual(a, b) {\n\t\t\treturn a.props === b.props\n\t\t},\n\t}\n)\n\n/**\n * Combine every batchable shape indicator into a single page-space `Path2D` and\n * emit one stroke call. Shapes whose indicator needs an evenodd clip (e.g.\n * arrows with labels or complex arrowheads) can't be batched \u2014 they still\n * stroke individually inside a save/restore with `ctx.clip` applied.\n *\n * Shared by any overlay util that paints shape indicators (e.g. collaborator\n * selections).\n *\n * @public\n */\nexport function strokeShapeIndicators(\n\teditor: Editor,\n\tctx: CanvasRenderingContext2D,\n\tshapeIds: TLShapeId[]\n): void {\n\tif (shapeIds.length === 0) return\n\n\tconst batched = new Path2D()\n\n\tfor (const shapeId of shapeIds) {\n\t\tconst shape = editor.getShape(shapeId)\n\t\tif (!shape || shape.isLocked) continue\n\n\t\tconst pageTransform = editor.getShapePageTransform(shape)\n\t\tif (!pageTransform) continue\n\n\t\tconst indicatorPath = indicatorPathCache.get(editor, shape.id)\n\t\tif (!indicatorPath) continue\n\n\t\tif (indicatorPath instanceof Path2D) {\n\t\t\tbatched.addPath(indicatorPath, pageTransform)\n\t\t\tcontinue\n\t\t}\n\n\t\tconst { path, clipPath, additionalPaths } = indicatorPath\n\n\t\tif (!clipPath) {\n\t\t\tbatched.addPath(path, pageTransform)\n\t\t\tif (additionalPaths) {\n\t\t\t\tfor (const p of additionalPaths) batched.addPath(p, pageTransform)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\n\t\t// Clipped case: fall back to an individual stroke. Rare (arrows with\n\t\t// labels / complex arrowheads), so the extra save/restore/stroke\n\t\t// pair per such shape isn't worth batching away.\n\t\tctx.save()\n\t\tctx.transform(\n\t\t\tpageTransform.a,\n\t\t\tpageTransform.b,\n\t\t\tpageTransform.c,\n\t\t\tpageTransform.d,\n\t\t\tpageTransform.e,\n\t\t\tpageTransform.f\n\t\t)\n\t\tctx.save()\n\t\tctx.clip(clipPath, 'evenodd')\n\t\tctx.stroke(path)\n\t\tctx.restore()\n\t\tif (additionalPaths) {\n\t\t\tfor (const p of additionalPaths) ctx.stroke(p)\n\t\t}\n\t\tctx.restore()\n\t}\n\n\tctx.stroke(batched)\n}\n"],
5
+ "mappings": "AAAA,SAAS,2BAA2B;AAIpC,MAAM,qBAAqB;AAAA,EAC1B;AAAA,EACA,CAAC,QAAgB,UAAmB;AACnC,UAAM,OAAO,OAAO,aAAa,KAAK;AACtC,WAAO,KAAK,iBAAiB,KAAK;AAAA,EACnC;AAAA,EACA;AAAA,IACC,gBAAgB,GAAG,GAAG;AACrB,aAAO,EAAE,UAAU,EAAE;AAAA,IACtB;AAAA,EACD;AACD;AAaO,SAAS,sBACf,QACA,KACA,UACO;AACP,MAAI,SAAS,WAAW,EAAG;AAE3B,QAAM,UAAU,IAAI,OAAO;AAE3B,aAAW,WAAW,UAAU;AAC/B,UAAM,QAAQ,OAAO,SAAS,OAAO;AACrC,QAAI,CAAC,SAAS,MAAM,SAAU;AAE9B,UAAM,gBAAgB,OAAO,sBAAsB,KAAK;AACxD,QAAI,CAAC,cAAe;AAEpB,UAAM,gBAAgB,mBAAmB,IAAI,QAAQ,MAAM,EAAE;AAC7D,QAAI,CAAC,cAAe;AAEpB,QAAI,yBAAyB,QAAQ;AACpC,cAAQ,QAAQ,eAAe,aAAa;AAC5C;AAAA,IACD;AAEA,UAAM,EAAE,MAAM,UAAU,gBAAgB,IAAI;AAE5C,QAAI,CAAC,UAAU;AACd,cAAQ,QAAQ,MAAM,aAAa;AACnC,UAAI,iBAAiB;AACpB,mBAAW,KAAK,gBAAiB,SAAQ,QAAQ,GAAG,aAAa;AAAA,MAClE;AACA;AAAA,IACD;AAKA,QAAI,KAAK;AACT,QAAI;AAAA,MACH,cAAc;AAAA,MACd,cAAc;AAAA,MACd,cAAc;AAAA,MACd,cAAc;AAAA,MACd,cAAc;AAAA,MACd,cAAc;AAAA,IACf;AACA,QAAI,KAAK;AACT,QAAI,KAAK,UAAU,SAAS;AAC5B,QAAI,OAAO,IAAI;AACf,QAAI,QAAQ;AACZ,QAAI,iBAAiB;AACpB,iBAAW,KAAK,gBAAiB,KAAI,OAAO,CAAC;AAAA,IAC9C;AACA,QAAI,QAAQ;AAAA,EACb;AAEA,MAAI,OAAO,OAAO;AACnB;",
6
+ "names": []
7
+ }
@@ -1,8 +1,8 @@
1
- const version = "5.2.0-next.355d68cf24e8";
1
+ const version = "5.2.0-next.79b13319d317";
2
2
  const publishDates = {
3
3
  major: "2026-05-06T16:28:18.473Z",
4
- minor: "2026-06-05T16:25:52.737Z",
5
- patch: "2026-06-05T16:25:52.737Z"
4
+ minor: "2026-06-10T11:15:34.674Z",
5
+ patch: "2026-06-10T11:15:34.674Z"
6
6
  };
7
7
  export {
8
8
  publishDates,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/version.ts"],
4
- "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '5.2.0-next.355d68cf24e8'\nexport const publishDates = {\n\tmajor: '2026-05-06T16:28:18.473Z',\n\tminor: '2026-06-05T16:25:52.737Z',\n\tpatch: '2026-06-05T16:25:52.737Z',\n}\n"],
4
+ "sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '5.2.0-next.79b13319d317'\nexport const publishDates = {\n\tmajor: '2026-05-06T16:28:18.473Z',\n\tminor: '2026-06-10T11:15:34.674Z',\n\tpatch: '2026-06-10T11:15:34.674Z',\n}\n"],
5
5
  "mappings": "AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
6
6
  "names": []
7
7
  }
package/editor.css CHANGED
@@ -182,6 +182,7 @@
182
182
  --tl-color-text-0: hsl(0, 0%, 11%);
183
183
  --tl-color-text-1: hsl(0, 0%, 18%);
184
184
  --tl-color-text-3: hsl(204, 4%, 45%);
185
+ --tl-color-text-disabled: hsl(204, 4%, 55%);
185
186
  --tl-color-text-shadow: hsl(0, 0%, 100%);
186
187
  --tl-color-text-highlight: hsl(52, 100%, 50%);
187
188
  --tl-color-text-highlight-p3: color(display-p3 0.972 0.8205 0.05);
@@ -236,6 +237,7 @@
236
237
  --tl-color-text-0: hsl(0, 9%, 94%);
237
238
  --tl-color-text-1: hsl(0, 0%, 85%);
238
239
  --tl-color-text-3: hsl(204, 4%, 75%);
240
+ --tl-color-text-disabled: hsl(204, 4%, 50%);
239
241
  --tl-color-text-shadow: hsl(210, 13%, 18%);
240
242
  --tl-color-text-highlight: hsl(52, 100%, 41%);
241
243
  --tl-color-text-highlight-p3: color(display-p3 0.8078 0.6225 0.0312);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tldraw/editor",
3
3
  "description": "tldraw infinite canvas SDK (editor).",
4
- "version": "5.2.0-next.355d68cf24e8",
4
+ "version": "5.2.0-next.79b13319d317",
5
5
  "author": {
6
6
  "name": "tldraw Inc.",
7
7
  "email": "hello@tldraw.com"
@@ -49,12 +49,12 @@
49
49
  "@tiptap/core": "^3.12.1",
50
50
  "@tiptap/pm": "^3.12.1",
51
51
  "@tiptap/react": "^3.12.1",
52
- "@tldraw/state": "5.2.0-next.355d68cf24e8",
53
- "@tldraw/state-react": "5.2.0-next.355d68cf24e8",
54
- "@tldraw/store": "5.2.0-next.355d68cf24e8",
55
- "@tldraw/tlschema": "5.2.0-next.355d68cf24e8",
56
- "@tldraw/utils": "5.2.0-next.355d68cf24e8",
57
- "@tldraw/validate": "5.2.0-next.355d68cf24e8",
52
+ "@tldraw/state": "5.2.0-next.79b13319d317",
53
+ "@tldraw/state-react": "5.2.0-next.79b13319d317",
54
+ "@tldraw/store": "5.2.0-next.79b13319d317",
55
+ "@tldraw/tlschema": "5.2.0-next.79b13319d317",
56
+ "@tldraw/utils": "5.2.0-next.79b13319d317",
57
+ "@tldraw/validate": "5.2.0-next.79b13319d317",
58
58
  "classnames": "^2.5.1",
59
59
  "eventemitter3": "^4.0.7",
60
60
  "idb": "^7.1.1",
@@ -80,7 +80,7 @@
80
80
  "react": "^19.2.1",
81
81
  "react-dom": "^19.2.1",
82
82
  "resize-observer-polyfill": "^1.5.1",
83
- "vitest": "^3.2.4"
83
+ "vitest": "^4.1.7"
84
84
  },
85
85
  "module": "dist-esm/index.mjs",
86
86
  "source": "src/index.ts",
package/src/index.ts CHANGED
@@ -185,11 +185,7 @@ export {
185
185
  type TLOverlay,
186
186
  type TLOverlayUtilConstructor,
187
187
  } from './lib/editor/overlays/OverlayUtil'
188
- export {
189
- ShapeIndicatorOverlayUtil,
190
- strokeShapeIndicators,
191
- type TLShapeIndicatorOverlay,
192
- } from './lib/editor/overlays/ShapeIndicatorOverlayUtil'
188
+ export { strokeShapeIndicators } from './lib/editor/overlays/strokeShapeIndicators'
193
189
  export {
194
190
  getPerfectDashProps,
195
191
  type PerfectDashTerminal,
@@ -4029,16 +4029,34 @@ export class Editor extends EventEmitter<TLEventMap> {
4029
4029
 
4030
4030
  this.once('stop-camera-animation', cancel)
4031
4031
 
4032
+ const dirZ = direction.z ?? 0
4033
+
4032
4034
  const moveCamera = (elapsed: number) => {
4033
4035
  const { x: cx, y: cy, z: cz } = this.getCamera()
4034
- const movementVec = Vec.Mul(direction, (currentSpeed * elapsed) / cz)
4036
+
4037
+ // Pan movement from x/y direction
4038
+ const dx = (direction.x * (currentSpeed * elapsed)) / cz
4039
+ const dy = (direction.y * (currentSpeed * elapsed)) / cz
4040
+
4041
+ let newCx = cx + dx
4042
+ let newCy = cy + dy
4043
+ let newCz = cz
4044
+
4045
+ // animate zoom if z direction is passed in
4046
+ if (dirZ !== 0) {
4047
+ newCz = cz * (1 + dirZ * currentSpeed * elapsed)
4048
+ // Adjust x/y to keep the viewport center fixed while zooming
4049
+ const center = this.getViewportScreenCenter()
4050
+ newCx += center.x / newCz - center.x / cz
4051
+ newCy += center.y / newCz - center.y / cz
4052
+ }
4035
4053
 
4036
4054
  // Apply friction
4037
4055
  currentSpeed *= 1 - friction
4038
4056
  if (currentSpeed < speedThreshold) {
4039
4057
  cancel()
4040
4058
  } else {
4041
- this._setCamera(new Vec(cx + movementVec.x, cy + movementVec.y, cz))
4059
+ this._setCamera(new Vec(newCx, newCy, newCz))
4042
4060
  }
4043
4061
  }
4044
4062
 
@@ -11332,7 +11350,10 @@ export class Editor extends EventEmitter<TLEventMap> {
11332
11350
  }
11333
11351
 
11334
11352
  if (slideSpeed > 0) {
11335
- this.slideCamera({ speed: slideSpeed, direction: slideDirection })
11353
+ this.slideCamera({
11354
+ speed: slideSpeed,
11355
+ direction: { x: slideDirection.x, y: slideDirection.y, z: 0 },
11356
+ })
11336
11357
  }
11337
11358
  } else {
11338
11359
  if (info.button === STYLUS_ERASER_BUTTON) {
@@ -129,4 +129,18 @@ describe(CollaboratorsManager, () => {
129
129
 
130
130
  expect(manager.getVisibleCollaborators()).toHaveLength(1)
131
131
  })
132
+
133
+ it('shows newly-joined collaborators that have not recorded any activity yet', () => {
134
+ // A peer who has joined but not moved their pointer broadcasts the default
135
+ // `lastActivityTimestamp` of 0. They should still be treated as active so
136
+ // they appear in the people menu / face pile. See issue #9017.
137
+ const zero = createPresence('zero')
138
+ zero.lastActivityTimestamp = 0
139
+ const nullish = createPresence('nullish')
140
+ nullish.lastActivityTimestamp = null
141
+ const { editor } = createEditor([zero, nullish])
142
+ const manager = new CollaboratorsManager(editor)
143
+
144
+ expect(manager.getVisibleCollaborators()).toHaveLength(2)
145
+ })
132
146
  })
@@ -93,9 +93,12 @@ export class CollaboratorsManager {
93
93
  return collaborators.filter((presence) => {
94
94
  const { lastActivityTimestamp, userId, chatMessage } = presence
95
95
 
96
- // Treat a missing `lastActivityTimestamp` as "active right now" (elapsed = 0)
97
- // so newly-joined peers aren't immediately classified as idle/inactive.
98
- const elapsed = Math.max(0, now - (lastActivityTimestamp ?? now))
96
+ // Treat a missing or zero `lastActivityTimestamp` as "active right now"
97
+ // (elapsed = 0) so newly-joined peers aren't immediately classified as
98
+ // idle/inactive. The broadcast default for peers who haven't moved their
99
+ // pointer yet is `0` (e.g. someone on a touch device who joins and just
100
+ // watches), so a plain `?? now` would leave them hidden. See issue #9017.
101
+ const elapsed = lastActivityTimestamp ? Math.max(0, now - lastActivityTimestamp) : 0
99
102
 
100
103
  if (elapsed > collaboratorInactiveTimeoutMs) {
101
104
  // Inactive: If they're inactive, only show if we're following them or they're highlighted
@@ -15,12 +15,14 @@ import { FontManager } from './FontManager'
15
15
  vi.mock('../../Editor')
16
16
 
17
17
  // Mock globals
18
- global.FontFace = vi.fn().mockImplementation((family, src, descriptors) => ({
19
- family,
20
- src,
21
- ...descriptors,
22
- load: vi.fn(() => Promise.resolve()),
23
- }))
18
+ global.FontFace = vi.fn().mockImplementation(function (family: any, src: any, descriptors: any) {
19
+ return {
20
+ family,
21
+ src,
22
+ ...descriptors,
23
+ load: vi.fn(() => Promise.resolve()),
24
+ }
25
+ })
24
26
 
25
27
  Object.defineProperty(global.document, 'fonts', {
26
28
  value: {
@@ -200,9 +202,11 @@ describe('FontManager', () => {
200
202
  const font = createMockFont()
201
203
  const error = new Error('Font load failed')
202
204
 
203
- ;(global.FontFace as Mock).mockReturnValue({
204
- family: font.family,
205
- load: vi.fn(() => Promise.reject(error)),
205
+ ;(global.FontFace as Mock).mockImplementationOnce(function () {
206
+ return {
207
+ family: font.family,
208
+ load: vi.fn(() => Promise.reject(error)),
209
+ }
206
210
  })
207
211
 
208
212
  const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
@@ -82,20 +82,22 @@ const mockEditor = {
82
82
  getContainerDocument: vi.fn(() => mockDocument),
83
83
  } as unknown as Editor
84
84
 
85
- global.Range = vi.fn(() => ({
86
- setStart: vi.fn(),
87
- setEnd: vi.fn(),
88
- getClientRects: vi.fn(() => [
89
- {
90
- width: 10,
91
- height: 16,
92
- left: 0,
93
- top: 0,
94
- right: 10,
95
- bottom: 16,
96
- },
97
- ]),
98
- })) as any
85
+ global.Range = vi.fn(function () {
86
+ return {
87
+ setStart: vi.fn(),
88
+ setEnd: vi.fn(),
89
+ getClientRects: vi.fn(() => [
90
+ {
91
+ width: 10,
92
+ height: 16,
93
+ left: 0,
94
+ top: 0,
95
+ right: 10,
96
+ bottom: 16,
97
+ },
98
+ ]),
99
+ }
100
+ }) as any
99
101
 
100
102
  describe('TextManager', () => {
101
103
  let textManager: TextManager
@@ -0,0 +1,86 @@
1
+ import { createComputedCache } from '@tldraw/store'
2
+ import { TLShape, TLShapeId } from '@tldraw/tlschema'
3
+ import type { Editor } from '../Editor'
4
+
5
+ const indicatorPathCache = createComputedCache(
6
+ 'shapeIndicatorPath',
7
+ (editor: Editor, shape: TLShape) => {
8
+ const util = editor.getShapeUtil(shape)
9
+ return util.getIndicatorPath(shape)
10
+ },
11
+ {
12
+ areRecordsEqual(a, b) {
13
+ return a.props === b.props
14
+ },
15
+ }
16
+ )
17
+
18
+ /**
19
+ * Combine every batchable shape indicator into a single page-space `Path2D` and
20
+ * emit one stroke call. Shapes whose indicator needs an evenodd clip (e.g.
21
+ * arrows with labels or complex arrowheads) can't be batched — they still
22
+ * stroke individually inside a save/restore with `ctx.clip` applied.
23
+ *
24
+ * Shared by any overlay util that paints shape indicators (e.g. collaborator
25
+ * selections).
26
+ *
27
+ * @public
28
+ */
29
+ export function strokeShapeIndicators(
30
+ editor: Editor,
31
+ ctx: CanvasRenderingContext2D,
32
+ shapeIds: TLShapeId[]
33
+ ): void {
34
+ if (shapeIds.length === 0) return
35
+
36
+ const batched = new Path2D()
37
+
38
+ for (const shapeId of shapeIds) {
39
+ const shape = editor.getShape(shapeId)
40
+ if (!shape || shape.isLocked) continue
41
+
42
+ const pageTransform = editor.getShapePageTransform(shape)
43
+ if (!pageTransform) continue
44
+
45
+ const indicatorPath = indicatorPathCache.get(editor, shape.id)
46
+ if (!indicatorPath) continue
47
+
48
+ if (indicatorPath instanceof Path2D) {
49
+ batched.addPath(indicatorPath, pageTransform)
50
+ continue
51
+ }
52
+
53
+ const { path, clipPath, additionalPaths } = indicatorPath
54
+
55
+ if (!clipPath) {
56
+ batched.addPath(path, pageTransform)
57
+ if (additionalPaths) {
58
+ for (const p of additionalPaths) batched.addPath(p, pageTransform)
59
+ }
60
+ continue
61
+ }
62
+
63
+ // Clipped case: fall back to an individual stroke. Rare (arrows with
64
+ // labels / complex arrowheads), so the extra save/restore/stroke
65
+ // pair per such shape isn't worth batching away.
66
+ ctx.save()
67
+ ctx.transform(
68
+ pageTransform.a,
69
+ pageTransform.b,
70
+ pageTransform.c,
71
+ pageTransform.d,
72
+ pageTransform.e,
73
+ pageTransform.f
74
+ )
75
+ ctx.save()
76
+ ctx.clip(clipPath, 'evenodd')
77
+ ctx.stroke(path)
78
+ ctx.restore()
79
+ if (additionalPaths) {
80
+ for (const p of additionalPaths) ctx.stroke(p)
81
+ }
82
+ ctx.restore()
83
+ }
84
+
85
+ ctx.stroke(batched)
86
+ }
package/src/version.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  // This file is automatically generated by internal/scripts/refresh-assets.ts.
2
2
  // Do not edit manually. Or do, I'm a comment, not a cop.
3
3
 
4
- export const version = '5.2.0-next.355d68cf24e8'
4
+ export const version = '5.2.0-next.79b13319d317'
5
5
  export const publishDates = {
6
6
  major: '2026-05-06T16:28:18.473Z',
7
- minor: '2026-06-05T16:25:52.737Z',
8
- patch: '2026-06-05T16:25:52.737Z',
7
+ minor: '2026-06-10T11:15:34.674Z',
8
+ patch: '2026-06-10T11:15:34.674Z',
9
9
  }
@@ -1,161 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var ShapeIndicatorOverlayUtil_exports = {};
20
- __export(ShapeIndicatorOverlayUtil_exports, {
21
- ShapeIndicatorOverlayUtil: () => ShapeIndicatorOverlayUtil,
22
- strokeShapeIndicators: () => strokeShapeIndicators
23
- });
24
- module.exports = __toCommonJS(ShapeIndicatorOverlayUtil_exports);
25
- var import_state = require("@tldraw/state");
26
- var import_store = require("@tldraw/store");
27
- var import_OverlayUtil = require("./OverlayUtil");
28
- const indicatorPathCache = (0, import_store.createComputedCache)(
29
- "shapeIndicatorPath",
30
- (editor, shape) => {
31
- const util = editor.getShapeUtil(shape);
32
- return util.getIndicatorPath(shape);
33
- },
34
- {
35
- areRecordsEqual(a, b) {
36
- return a.props === b.props;
37
- }
38
- }
39
- );
40
- function strokeShapeIndicators(editor, ctx, shapeIds) {
41
- if (shapeIds.length === 0) return;
42
- const batched = new Path2D();
43
- for (const shapeId of shapeIds) {
44
- const shape = editor.getShape(shapeId);
45
- if (!shape || shape.isLocked) continue;
46
- const pageTransform = editor.getShapePageTransform(shape);
47
- if (!pageTransform) continue;
48
- const indicatorPath = indicatorPathCache.get(editor, shape.id);
49
- if (!indicatorPath) continue;
50
- if (indicatorPath instanceof Path2D) {
51
- batched.addPath(indicatorPath, pageTransform);
52
- continue;
53
- }
54
- const { path, clipPath, additionalPaths } = indicatorPath;
55
- if (!clipPath) {
56
- batched.addPath(path, pageTransform);
57
- if (additionalPaths) {
58
- for (const p of additionalPaths) batched.addPath(p, pageTransform);
59
- }
60
- continue;
61
- }
62
- ctx.save();
63
- ctx.transform(
64
- pageTransform.a,
65
- pageTransform.b,
66
- pageTransform.c,
67
- pageTransform.d,
68
- pageTransform.e,
69
- pageTransform.f
70
- );
71
- ctx.save();
72
- ctx.clip(clipPath, "evenodd");
73
- ctx.stroke(path);
74
- ctx.restore();
75
- if (additionalPaths) {
76
- for (const p of additionalPaths) ctx.stroke(p);
77
- }
78
- ctx.restore();
79
- }
80
- ctx.stroke(batched);
81
- }
82
- class ShapeIndicatorOverlayUtil extends import_OverlayUtil.OverlayUtil {
83
- static type = "shape_indicator";
84
- options = { zIndex: 50, lineWidth: 1.5, hintedLineWidth: 2.5 };
85
- // Narrow projection of instance state. Reading the full record would
86
- // re-fire getOverlays on every cursor move / brush update; gating on these
87
- // three booleans means we only re-fire when one of them actually flips.
88
- _instanceFlags$ = (0, import_state.computed)(
89
- "shape indicator instance flags",
90
- () => {
91
- const i = this.editor.getInstanceState();
92
- return {
93
- isChangingStyle: i.isChangingStyle,
94
- isHoveringCanvas: i.isHoveringCanvas,
95
- isCoarsePointer: i.isCoarsePointer
96
- };
97
- },
98
- {
99
- isEqual: (a, b) => a.isChangingStyle === b.isChangingStyle && a.isHoveringCanvas === b.isHoveringCanvas && a.isCoarsePointer === b.isCoarsePointer
100
- }
101
- );
102
- isActive() {
103
- return true;
104
- }
105
- getOverlays() {
106
- const editor = this.editor;
107
- const renderingShapeIds = new Set(editor.getRenderingShapes().map((s) => s.id));
108
- const idsToDisplay = [];
109
- const { isChangingStyle, isHoveringCanvas, isCoarsePointer } = this._instanceFlags$.get();
110
- const isIdleOrEditing = editor.isInAny("select.idle", "select.editing_shape");
111
- const isInSelectState = editor.isInAny(
112
- "select.brushing",
113
- "select.scribble_brushing",
114
- "select.pointing_shape",
115
- "select.pointing_selection",
116
- "select.pointing_handle"
117
- );
118
- if (!isChangingStyle && (isIdleOrEditing || isInSelectState)) {
119
- for (const id of editor.getSelectedShapeIds()) {
120
- if (renderingShapeIds.has(id)) idsToDisplay.push(id);
121
- }
122
- if (isIdleOrEditing && isHoveringCanvas && !isCoarsePointer) {
123
- const hovered = editor.getHoveredShapeId();
124
- if (hovered && renderingShapeIds.has(hovered) && !idsToDisplay.includes(hovered)) {
125
- idsToDisplay.push(hovered);
126
- }
127
- }
128
- }
129
- const hintingShapeIds = [];
130
- for (const id of editor.getHintingShapeIds()) {
131
- if (renderingShapeIds.has(id)) hintingShapeIds.push(id);
132
- }
133
- if (idsToDisplay.length === 0 && hintingShapeIds.length === 0) {
134
- return [];
135
- }
136
- return [
137
- {
138
- id: "shape_indicator",
139
- type: "shape_indicator",
140
- props: { idsToDisplay, hintingShapeIds }
141
- }
142
- ];
143
- }
144
- render(ctx, overlays) {
145
- const overlay = overlays[0];
146
- if (!overlay) return;
147
- const editor = this.editor;
148
- const zoom = editor.getZoomLevel();
149
- const { idsToDisplay, hintingShapeIds } = overlay.props;
150
- ctx.lineCap = "round";
151
- ctx.lineJoin = "round";
152
- ctx.strokeStyle = editor.getCurrentTheme().colors[editor.getColorMode()].selectionStroke;
153
- ctx.lineWidth = this.options.lineWidth / zoom;
154
- strokeShapeIndicators(editor, ctx, idsToDisplay);
155
- if (hintingShapeIds.length > 0) {
156
- ctx.lineWidth = this.options.hintedLineWidth / zoom;
157
- strokeShapeIndicators(editor, ctx, hintingShapeIds);
158
- }
159
- }
160
- }
161
- //# sourceMappingURL=ShapeIndicatorOverlayUtil.js.map