UNPKG

tldraw

Version:

A tiny little drawing editor.

50 lines (49 loc) 2.09 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var kbd_utils_exports = {}; __export(kbd_utils_exports, { kbd: () => kbd, kbdStr: () => kbdStr }); module.exports = __toCommonJS(kbd_utils_exports); var import_editor = require("@tldraw/editor"); const cmdKey = import_editor.tlenv.isDarwin ? "\u2318" : "__CTRL__"; const ctrlKey = import_editor.tlenv.isDarwin ? "\u2303" : "__CTRL__"; const altKey = import_editor.tlenv.isDarwin ? "\u2325" : "__ALT__"; function kbd(str) { if (str === ",") return [","]; return str.split(",")[0].split(/(\[\[[^\]]+\]\])/g).map( (s) => s.startsWith("[[") ? s.replace(/[[\]]/g, "") : s.replace(/cmd\+/g, cmdKey).replace(/ctrl\+/g, ctrlKey).replace(/alt\+/g, altKey).replace(/shift\+/g, "\u21E7").replace(/\$/g, cmdKey).replace(/\?/g, altKey).replace(/!/g, "\u21E7").match(/__CTRL__|__ALT__|./g) || [] ).flat().map((sub, index) => { if (sub[0] === "+") return []; let modifiedKey; if (sub === "__CTRL__") { modifiedKey = "Ctrl"; } else if (sub === "__ALT__") { modifiedKey = "Alt"; } else { modifiedKey = sub[0].toUpperCase() + sub.slice(1); } return import_editor.tlenv.isDarwin || !index ? modifiedKey : ["+", modifiedKey]; }).flat(); } function kbdStr(str) { return "\u2014 " + kbd(str).join("\u2009"); } //# sourceMappingURL=kbd-utils.js.map