@excalidraw/common 0.18.0-54a9826 → 0.18.0-60b2758

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 (72) hide show
  1. package/dist/dev/index.js +175 -2
  2. package/dist/dev/index.js.map +3 -3
  3. package/dist/prod/index.js +3 -3
  4. package/dist/types/common/debug.d.ts +21 -0
  5. package/dist/types/common/src/colors.d.ts +1 -1
  6. package/dist/types/common/src/constants.d.ts +1 -0
  7. package/dist/types/common/src/index.d.ts +1 -0
  8. package/dist/types/common/src/utils.d.ts +3 -4
  9. package/dist/types/element/src/arrows/focus.d.ts +1 -1
  10. package/dist/types/element/src/binding.d.ts +6 -5
  11. package/dist/types/element/src/types.d.ts +1 -1
  12. package/dist/types/element/src/utils.d.ts +5 -3
  13. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +24 -27
  14. package/dist/types/excalidraw/actions/actionBoundText.d.ts +16 -18
  15. package/dist/types/excalidraw/actions/actionCanvas.d.ts +97 -109
  16. package/dist/types/excalidraw/actions/actionClipboard.d.ts +16 -18
  17. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +8 -9
  18. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +24 -27
  19. package/dist/types/excalidraw/actions/actionElementLink.d.ts +4 -9
  20. package/dist/types/excalidraw/actions/actionElementLock.d.ts +16 -18
  21. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +8 -9
  22. package/dist/types/excalidraw/actions/actionExport.d.ts +34 -42
  23. package/dist/types/excalidraw/actions/actionFrame.d.ts +32 -36
  24. package/dist/types/excalidraw/actions/actionGroup.d.ts +16 -18
  25. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +8 -9
  26. package/dist/types/excalidraw/actions/actionLink.d.ts +8 -9
  27. package/dist/types/excalidraw/actions/actionMenu.d.ts +4 -9
  28. package/dist/types/excalidraw/actions/actionProperties.d.ts +16 -18
  29. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +8 -9
  30. package/dist/types/excalidraw/actions/actionStyles.d.ts +8 -9
  31. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +8 -9
  32. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +8 -9
  33. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +4 -9
  34. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +8 -9
  35. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +8 -9
  36. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +8 -9
  37. package/dist/types/excalidraw/actions/shortcuts.d.ts +1 -1
  38. package/dist/types/excalidraw/appState.d.ts +6 -7
  39. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -0
  40. package/dist/types/excalidraw/charts/charts.constants.d.ts +48 -0
  41. package/dist/types/excalidraw/charts/charts.helpers.d.ts +32 -0
  42. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -0
  43. package/dist/types/excalidraw/charts/charts.parse.d.ts +10 -0
  44. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -0
  45. package/dist/types/excalidraw/charts/charts.types.d.ts +18 -0
  46. package/dist/types/excalidraw/charts/index.d.ts +7 -0
  47. package/dist/types/excalidraw/clipboard.d.ts +0 -2
  48. package/dist/types/excalidraw/components/App.d.ts +4 -2
  49. package/dist/types/excalidraw/components/CommandPalette/types.d.ts +1 -1
  50. package/dist/types/excalidraw/components/PasteChartDialog.d.ts +4 -5
  51. package/dist/types/excalidraw/components/PropertiesPopover.d.ts +1 -1
  52. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenu.d.ts +30 -17
  53. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuContent.d.ts +3 -2
  54. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItem.d.ts +11 -13
  55. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuItemCheckbox.d.ts +5 -0
  56. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSub.d.ts +23 -0
  57. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubContent.d.ts +8 -0
  58. package/dist/types/excalidraw/components/dropdownMenu/DropdownMenuSubTrigger.d.ts +12 -0
  59. package/dist/types/excalidraw/components/dropdownMenu/common.d.ts +1 -1
  60. package/dist/types/excalidraw/components/dropdownMenu/dropdownMenuUtils.d.ts +2 -0
  61. package/dist/types/excalidraw/components/icons.d.ts +6 -1
  62. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +15 -0
  63. package/dist/types/excalidraw/components/main-menu/MainMenu.d.ts +23 -13
  64. package/dist/types/excalidraw/components/shapes.d.ts +74 -1
  65. package/dist/types/excalidraw/data/blob.d.ts +28 -30
  66. package/dist/types/excalidraw/data/json.d.ts +14 -15
  67. package/dist/types/excalidraw/index.d.ts +1 -0
  68. package/dist/types/excalidraw/types.d.ts +13 -10
  69. package/dist/types/math/src/point.d.ts +6 -1
  70. package/dist/types/math/src/types.d.ts +25 -1
  71. package/package.json +1 -1
  72. package/dist/types/excalidraw/charts.d.ts +0 -27
package/dist/dev/index.js CHANGED
@@ -1562,7 +1562,7 @@ var normalizeInputColor = (color) => {
1562
1562
  }
1563
1563
  const tc = tinycolor(color);
1564
1564
  if (tc.isValid()) {
1565
- if (tc.getFormat() === "hex" && !color.startsWith("#")) {
1565
+ if (["hex", "hex8"].includes(tc.getFormat()) && !color.startsWith("#")) {
1566
1566
  return `#${color}`;
1567
1567
  }
1568
1568
  return color;
@@ -1659,7 +1659,8 @@ var CLASSES = {
1659
1659
  SEARCH_MENU_INPUT_WRAPPER: "layer-ui__search-inputWrapper",
1660
1660
  CONVERT_ELEMENT_TYPE_POPUP: "ConvertElementTypePopup",
1661
1661
  SHAPE_ACTIONS_THEME_SCOPE: "shape-actions-theme-scope",
1662
- FRAME_NAME: "frame-name"
1662
+ FRAME_NAME: "frame-name",
1663
+ DROPDOWN_MENU_EVENT_WRAPPER: "dropdown-menu-event-wrapper"
1663
1664
  };
1664
1665
  var FONT_SIZES = {
1665
1666
  sm: 16,
@@ -3158,6 +3159,9 @@ var setFeatureFlag = (flag, value) => {
3158
3159
  console.error("unable to set feature flag", e);
3159
3160
  }
3160
3161
  };
3162
+ var oneOf = (needle, haystack) => {
3163
+ return haystack.includes(needle);
3164
+ };
3161
3165
 
3162
3166
  // src/random.ts
3163
3167
  var random = new Random(Date.now());
@@ -3231,6 +3235,173 @@ var Emitter = class {
3231
3235
  this.subscribers = [];
3232
3236
  }
3233
3237
  };
3238
+
3239
+ // debug.ts
3240
+ init_define_import_meta_env();
3241
+ var lessPrecise = (num, precision = 5) => parseFloat(num.toPrecision(precision));
3242
+ var getAvgFrameTime = (times) => lessPrecise(times.reduce((a, b) => a + b) / times.length);
3243
+ var Debug = class _Debug {
3244
+ static DEBUG_LOG_TIMES = true;
3245
+ static TIMES_AGGR = {};
3246
+ static TIMES_AVG = {};
3247
+ static LAST_DEBUG_LOG_CALL = 0;
3248
+ static DEBUG_LOG_INTERVAL_ID = null;
3249
+ static LAST_FRAME_TIMESTAMP = 0;
3250
+ static FRAME_COUNT = 0;
3251
+ static ANIMATION_FRAME_ID = null;
3252
+ static scheduleAnimationFrame = () => {
3253
+ if (_Debug.DEBUG_LOG_INTERVAL_ID !== null) {
3254
+ _Debug.ANIMATION_FRAME_ID = requestAnimationFrame((timestamp) => {
3255
+ if (_Debug.LAST_FRAME_TIMESTAMP !== timestamp) {
3256
+ _Debug.LAST_FRAME_TIMESTAMP = timestamp;
3257
+ _Debug.FRAME_COUNT++;
3258
+ }
3259
+ if (_Debug.DEBUG_LOG_INTERVAL_ID !== null) {
3260
+ _Debug.scheduleAnimationFrame();
3261
+ }
3262
+ });
3263
+ }
3264
+ };
3265
+ static setupInterval = () => {
3266
+ if (_Debug.DEBUG_LOG_INTERVAL_ID === null) {
3267
+ console.info("%c(starting perf recording)", "color: lime");
3268
+ _Debug.DEBUG_LOG_INTERVAL_ID = window.setInterval(_Debug.debugLogger, 1e3);
3269
+ _Debug.scheduleAnimationFrame();
3270
+ }
3271
+ _Debug.LAST_DEBUG_LOG_CALL = Date.now();
3272
+ };
3273
+ static debugLogger = () => {
3274
+ if (_Debug.DEBUG_LOG_TIMES) {
3275
+ for (const [name, { t, times }] of Object.entries(_Debug.TIMES_AGGR)) {
3276
+ if (times.length) {
3277
+ console.info(
3278
+ name,
3279
+ lessPrecise(times.reduce((a, b) => a + b)),
3280
+ times.sort((a, b) => a - b).map((x) => lessPrecise(x))
3281
+ );
3282
+ _Debug.TIMES_AGGR[name] = { t, times: [] };
3283
+ }
3284
+ }
3285
+ for (const [name, { t, times, avg }] of Object.entries(_Debug.TIMES_AVG)) {
3286
+ if (times.length) {
3287
+ const totalTime = times.reduce((a, b) => a + b);
3288
+ const avgFrameTime = lessPrecise(totalTime / _Debug.FRAME_COUNT);
3289
+ console.info(
3290
+ name,
3291
+ `- ${times.length} calls - ${avgFrameTime}ms/frame across ${_Debug.FRAME_COUNT} frames (${lessPrecise(
3292
+ avgFrameTime / 16.67 * 100,
3293
+ 1
3294
+ )}% of frame budget)`
3295
+ );
3296
+ _Debug.TIMES_AVG[name] = {
3297
+ t,
3298
+ times: [],
3299
+ avg: avg != null ? getAvgFrameTime([avg, avgFrameTime]) : avgFrameTime
3300
+ };
3301
+ }
3302
+ }
3303
+ }
3304
+ _Debug.FRAME_COUNT = 0;
3305
+ if (Date.now() - _Debug.LAST_DEBUG_LOG_CALL > 600 && _Debug.DEBUG_LOG_INTERVAL_ID !== null) {
3306
+ console.info("%c(stopping perf recording)", "color: red");
3307
+ window.clearInterval(_Debug.DEBUG_LOG_INTERVAL_ID);
3308
+ window.cancelAnimationFrame(_Debug.ANIMATION_FRAME_ID);
3309
+ _Debug.ANIMATION_FRAME_ID = null;
3310
+ _Debug.FRAME_COUNT = 0;
3311
+ _Debug.LAST_FRAME_TIMESTAMP = 0;
3312
+ _Debug.DEBUG_LOG_INTERVAL_ID = null;
3313
+ _Debug.TIMES_AGGR = {};
3314
+ _Debug.TIMES_AVG = {};
3315
+ }
3316
+ };
3317
+ static logTime = (time, name = "default") => {
3318
+ _Debug.setupInterval();
3319
+ const now = performance.now();
3320
+ const { t, times } = _Debug.TIMES_AGGR[name] = _Debug.TIMES_AGGR[name] || {
3321
+ t: 0,
3322
+ times: []
3323
+ };
3324
+ if (t) {
3325
+ times.push(time != null ? time : now - t);
3326
+ }
3327
+ _Debug.TIMES_AGGR[name].t = now;
3328
+ };
3329
+ static logTimeAverage = (time, name = "default") => {
3330
+ _Debug.setupInterval();
3331
+ const now = performance.now();
3332
+ const { t, times } = _Debug.TIMES_AVG[name] = _Debug.TIMES_AVG[name] || {
3333
+ t: 0,
3334
+ times: []
3335
+ };
3336
+ if (t) {
3337
+ times.push(time != null ? time : now - t);
3338
+ }
3339
+ _Debug.TIMES_AVG[name].t = now;
3340
+ };
3341
+ static logWrapper = (type) => (fn, name = "default") => {
3342
+ return (...args) => {
3343
+ const t0 = performance.now();
3344
+ const ret = fn(...args);
3345
+ _Debug[type](performance.now() - t0, name);
3346
+ return ret;
3347
+ };
3348
+ };
3349
+ static logTimeWrap = _Debug.logWrapper("logTime");
3350
+ static logTimeAverageWrap = _Debug.logWrapper("logTimeAverage");
3351
+ static perfWrap = (fn, name = "default") => {
3352
+ return (...args) => {
3353
+ console.time(name);
3354
+ const ret = fn(...args);
3355
+ console.timeEnd(name);
3356
+ return ret;
3357
+ };
3358
+ };
3359
+ static CHANGED_CACHE = {};
3360
+ static logChanged(name, obj) {
3361
+ const prev = _Debug.CHANGED_CACHE[name];
3362
+ _Debug.CHANGED_CACHE[name] = obj;
3363
+ if (!prev) {
3364
+ return;
3365
+ }
3366
+ const allKeys = /* @__PURE__ */ new Set([...Object.keys(prev), ...Object.keys(obj)]);
3367
+ const changed = {};
3368
+ for (const key of allKeys) {
3369
+ const prevVal = prev[key];
3370
+ const nextVal = obj[key];
3371
+ if (!deepEqual(prevVal, nextVal)) {
3372
+ changed[key] = { prev: prevVal, next: nextVal };
3373
+ }
3374
+ }
3375
+ if (Object.keys(changed).length > 0) {
3376
+ console.info(`[${name}] changed:`, changed);
3377
+ }
3378
+ }
3379
+ };
3380
+ function deepEqual(a, b) {
3381
+ if (Object.is(a, b)) {
3382
+ return true;
3383
+ }
3384
+ if (a === null || b === null || typeof a !== "object" || typeof b !== "object") {
3385
+ return false;
3386
+ }
3387
+ if (Array.isArray(a) !== Array.isArray(b)) {
3388
+ return false;
3389
+ }
3390
+ const keysA = Object.keys(a);
3391
+ const keysB = Object.keys(b);
3392
+ if (keysA.length !== keysB.length) {
3393
+ return false;
3394
+ }
3395
+ for (const key of keysA) {
3396
+ if (!deepEqual(
3397
+ a[key],
3398
+ b[key]
3399
+ )) {
3400
+ return false;
3401
+ }
3402
+ }
3403
+ return true;
3404
+ }
3234
3405
  export {
3235
3406
  ACTIVE_THRESHOLD,
3236
3407
  ALLOWED_PASTE_MIME_TYPES,
@@ -3283,6 +3454,7 @@ export {
3283
3454
  DEFAULT_VERTICAL_ALIGN,
3284
3455
  DOUBLE_TAP_POSITION_THRESHOLD,
3285
3456
  DRAGGING_THRESHOLD,
3457
+ Debug,
3286
3458
  EDITOR_LS_KEYS,
3287
3459
  ELEMENT_LINK_KEY,
3288
3460
  ELEMENT_READY_TO_ERASE_OPACITY,
@@ -3455,6 +3627,7 @@ export {
3455
3627
  normalizeEOL,
3456
3628
  normalizeInputColor,
3457
3629
  normalizeLink,
3630
+ oneOf,
3458
3631
  preventUnload,
3459
3632
  promiseTry,
3460
3633
  queryFocusableElements,