@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 2.33 kB
Source Map (JSON)
{"version":3,"file":"utils.mjs","names":[],"sources":["../../src/Hotkey/utils.ts"],"sourcesContent":["import { KeyMapEnum } from './const';\n\n// https://superuser.com/questions/1238058/key-combination-order\nexport const NORMATIVE_MODIFIER = [\n // win: Ctrl ,mac: Control\n KeyMapEnum.Ctrl,\n KeyMapEnum.Control,\n KeyMapEnum.CommandOrControl,\n\n // win: Win ,mac: Command\n KeyMapEnum.Meta,\n\n // Mod should have same priority as Ctrl since it represents Ctrl on Windows\n KeyMapEnum.Mod,\n\n // win: Alt ,mac: Option\n KeyMapEnum.Alt,\n\n // win: Shift ,mac: Shift\n KeyMapEnum.Shift,\n];\n\nconst orderMap = Object.fromEntries(NORMATIVE_MODIFIER.map((key, index) => [key, index]));\n\nexport const splitKeysByPlus = (keys: string): string[] => {\n return keys\n .replaceAll('++', `+${KeyMapEnum.Equal}`)\n .split('+')\n .sort((x, y) => {\n const idxX = orderMap[x.toLowerCase()] ?? orderMap.length;\n const idxY = orderMap[y.toLowerCase()] ?? orderMap.length;\n\n return idxX - idxY;\n });\n};\n\nexport const startCase = (str: string): string => {\n return str\n .replaceAll(/([A-Z])/g, ' $1')\n .replace(/^./, (s) => s.toUpperCase())\n .trim();\n};\n\nexport const checkIsAppleDevice = (isApple?: boolean) => {\n if (isApple !== undefined) {\n return isApple;\n }\n\n if (typeof window === 'undefined' || typeof navigator === 'undefined') {\n return false; // 处理 SSR 环境\n }\n\n const userAgent = navigator.userAgent.toLowerCase();\n return /mac|iphone|ipod|ipad|ios/i.test(userAgent);\n};\n\nexport const combineKeys = (keys: string[]): string => keys.join('+');\n"],"mappings":";;AAGA,MAAa,qBAAqB;CAEhC,WAAW;CACX,WAAW;CACX,WAAW;CAGX,WAAW;CAGX,WAAW;CAGX,WAAW;CAGX,WAAW;AACb;AAEA,MAAM,WAAW,OAAO,YAAY,mBAAmB,KAAK,KAAK,UAAU,CAAC,KAAK,KAAK,CAAC,CAAC;AAExF,MAAa,mBAAmB,SAA2B;CACzD,OAAO,KACJ,WAAW,MAAM,IAAI,WAAW,OAAO,CAAC,CACxC,MAAM,GAAG,CAAC,CACV,MAAM,GAAG,MAAM;EAId,QAHa,SAAS,EAAE,YAAY,MAAM,SAAS,WACtC,SAAS,EAAE,YAAY,MAAM,SAAS;CAGrD,CAAC;AACL;AAEA,MAAa,aAAa,QAAwB;CAChD,OAAO,IACJ,WAAW,YAAY,KAAK,CAAC,CAC7B,QAAQ,OAAO,MAAM,EAAE,YAAY,CAAC,CAAC,CACrC,KAAK;AACV;AAEA,MAAa,sBAAsB,YAAsB;CACvD,IAAI,YAAY,KAAA,GACd,OAAO;CAGT,IAAI,OAAO,WAAW,eAAe,OAAO,cAAc,aACxD,OAAO;CAGT,MAAM,YAAY,UAAU,UAAU,YAAY;CAClD,OAAO,4BAA4B,KAAK,SAAS;AACnD;AAEA,MAAa,eAAe,SAA2B,KAAK,KAAK,GAAG"}