{
  "version": 3,
  "sources": ["../../../../src/lib/ui/context/action-predicates.ts"],
  "sourcesContent": ["import { Editor, TLImageShape, TLShape, TLVideoShape } from '@tldraw/editor'\nimport { getArrowBindings } from '../../shapes/arrow/shared'\nimport { EmbedShapeUtil } from '../../shapes/embed/EmbedShapeUtil'\nimport { getFrameableShapeIds } from '../../utils/frames/frames'\nimport { getSelectedLinkShape } from '../../utils/shapes/shapes'\n\n// Shared by action isAvailable/isEnabled and the menu hooks, so the two can't drift.\n// Every function must stay pure and read only editor state or values fixed for the session (like\n// clipboard support): menus re-run them when editor state changes, so anything else goes stale.\n\nconst FLIPPABLE_TYPES = new Set(['group', 'image', 'arrow', 'line', 'draw', 'geo'])\n\n/** @internal */\nexport function canApplySelectionAction(editor: Editor) {\n\treturn editor.isIn('select') && editor.getSelectedShapeIds().length > 0\n}\n\n/** @internal */\nexport function getUnlockedSelectedShapes(editor: Editor): TLShape[] {\n\treturn editor.getSelectedShapes().filter((s) => !editor.isShapeOrAncestorLocked(s))\n}\n\n/** @internal */\nexport function hasUnlockedSelection(editor: Editor, min: number) {\n\treturn getUnlockedSelectedShapes(editor).length >= min\n}\n\n/** @internal */\nexport function canApplyToUnlockedSelection(editor: Editor, min: number) {\n\treturn editor.isIn('select') && hasUnlockedSelection(editor, min)\n}\n\n/** @internal */\nexport function hasShapesOnPage(editor: Editor) {\n\treturn editor.getCurrentPageShapeIds().size > 0\n}\n\n/** @internal */\nexport function hasLockedShapesOnPage(editor: Editor) {\n\treturn editor.getCurrentPageShapes().some((s) => s.isLocked)\n}\n\n/** @internal */\nexport function isGroupAllowed(editor: Editor) {\n\tif (!hasUnlockedSelection(editor, 2)) return false\n\tconst selected = editor.getSelectedShapes()\n\tconst selectedIds = new Set(selected.map((s) => s.id))\n\t// An arrow grouped without a shape it's bound to gets reparented back out of the group.\n\tfor (const shape of selected) {\n\t\tif (!editor.isShapeOfType(shape, 'arrow')) continue\n\t\tconst { start, end } = getArrowBindings(editor, shape)\n\t\tif (start && !selectedIds.has(start.toId)) return false\n\t\tif (end && !selectedIds.has(end.toId)) return false\n\t}\n\treturn true\n}\n\n/** @internal */\nexport function isUngroupAllowed(editor: Editor) {\n\treturn getUnlockedSelectedShapes(editor).some((s) => editor.isShapeOfType(s, 'group'))\n}\n\n/** @internal */\nexport function hasThreeStackableShapes(editor: Editor) {\n\tconst stackable = getUnlockedSelectedShapes(editor).filter((shape) => {\n\t\tif (!editor.isShapeOfType(shape, 'arrow')) return true\n\t\tconst { start, end } = getArrowBindings(editor, shape)\n\t\treturn !start && !end\n\t})\n\treturn stackable.length > 2\n}\n\n/** @internal */\nexport function isOnlyFlippableShapeSelected(editor: Editor) {\n\tconst shape = editor.getOnlySelectedShape()\n\treturn !!shape && FLIPPABLE_TYPES.has(shape.type) && !editor.isShapeOrAncestorLocked(shape)\n}\n\n/** @internal */\nexport function canToggleAutoSize(editor: Editor) {\n\tconst shape = editor.getOnlySelectedShape()\n\treturn !!shape && editor.isShapeOfType(shape, 'text') && shape.props.autoSize === false\n}\n\n/** @internal */\nexport function hasLinkShapeSelected(editor: Editor) {\n\treturn !!getSelectedLinkShape(editor)\n}\n\n/** @internal */\nexport function canFrameSelection(editor: Editor) {\n\tconst selected = editor.getSelectedShapes()\n\tif (selected.length === 0) return false\n\t// An all-frame selection unframes instead; remove-frame covers that.\n\tif (selected.every((s) => editor.isShapeOfType(s, 'frame'))) return false\n\treturn getFrameableShapeIds(editor, editor.getSelectedShapeIds()).length > 0\n}\n\n/** @internal */\nexport function areAllSelectedFrameLike(editor: Editor) {\n\tconst selected = editor.getSelectedShapes()\n\treturn selected.length > 0 && selected.every((s) => editor.isShapeFrameLike(s))\n}\n\n/** @internal */\nexport function canFitFrameToContent(editor: Editor) {\n\tconst shape = editor.getOnlySelectedShape()\n\treturn (\n\t\t!!shape && editor.isShapeFrameLike(shape) && editor.getSortedChildIdsForParent(shape).length > 0\n\t)\n}\n\n/** @internal */\nexport function isOnlyEmbedWithUrlSelected(editor: Editor) {\n\tconst shape = editor.getOnlySelectedShape()\n\treturn (\n\t\t!!shape &&\n\t\teditor.isShapeOfType(shape, 'embed') &&\n\t\t!!shape.props.url &&\n\t\t!editor.isShapeOrAncestorLocked(shape)\n\t)\n}\n\n/** @internal */\nexport function isOnlyEmbeddableBookmarkSelected(editor: Editor) {\n\tconst shape = editor.getOnlySelectedShape()\n\tif (!shape || !editor.isShapeOfType(shape, 'bookmark') || !shape.props.url) return false\n\tif (editor.isShapeOrAncestorLocked(shape) || !editor.hasShapeUtil('embed')) return false\n\treturn !!(editor.getShapeUtil('embed') as EmbedShapeUtil).getEmbedDefinition(shape.props.url)\n}\n\n/** @internal */\nexport function canFlatten(editor: Editor) {\n\tif (editor.getSelectedShapeIds().length === 0) return false\n\tconst shape = editor.getOnlySelectedShape()\n\treturn !(shape && editor.isShapeOfType(shape, 'image'))\n}\n\n/** @public */\nexport function supportsDownloadingOriginal(\n\tshape: TLShape,\n\teditor: Editor\n): shape is TLImageShape | TLVideoShape {\n\treturn (\n\t\t(editor.isShapeOfType(shape, 'image') || editor.isShapeOfType(shape, 'video')) &&\n\t\t!!(shape as any).props.assetId\n\t)\n}\n\n/** @internal */\nexport function hasDownloadableMediaSelected(editor: Editor) {\n\treturn editor.getSelectedShapes().some((s) => supportsDownloadingOriginal(s, editor))\n}\n\n/** @internal */\nexport function isContentOffscreen(editor: Editor) {\n\tconst ids = editor.getCurrentPageShapeIds()\n\treturn ids.size > 0 && ids.size === editor.getNotVisibleShapes().size\n}\n\n/** @internal */\nexport function canWriteClipboard(editor: Editor) {\n\treturn !!editor.getContainerWindow().navigator.clipboard?.write\n}\n\nconst clipboardReadable =\n\ttypeof window !== 'undefined' &&\n\t'navigator' in window &&\n\tBoolean(navigator.clipboard) &&\n\tBoolean(navigator.clipboard.read)\n\n/** @internal */\nexport function canReadClipboard() {\n\treturn clipboardReadable\n}\n"],
  "mappings": "AACA,SAAS,wBAAwB;AAEjC,SAAS,4BAA4B;AACrC,SAAS,4BAA4B;AAMrC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