@excalidraw/common 0.18.0-7ea3229 → 0.18.0-816c81c

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 (91) hide show
  1. package/dist/dev/index.js +137 -19
  2. package/dist/dev/index.js.map +3 -3
  3. package/dist/prod/index.js +3 -3
  4. package/dist/types/common/src/appEventBus.d.ts +27 -0
  5. package/dist/types/common/src/colors.d.ts +13 -13
  6. package/dist/types/common/src/index.d.ts +2 -0
  7. package/dist/types/common/src/utils.d.ts +1 -3
  8. package/dist/types/common/src/versionedSnapshotStore.d.ts +17 -0
  9. package/dist/types/element/src/Scene.d.ts +2 -0
  10. package/dist/types/element/src/arrowheads.d.ts +3 -0
  11. package/dist/types/element/src/binding.d.ts +3 -4
  12. package/dist/types/element/src/bounds.d.ts +1 -1
  13. package/dist/types/element/src/elbowArrow.d.ts +2 -0
  14. package/dist/types/element/src/index.d.ts +1 -0
  15. package/dist/types/element/src/linearElementEditor.d.ts +3 -0
  16. package/dist/types/element/src/mutateElement.d.ts +2 -0
  17. package/dist/types/element/src/selection.d.ts +1 -1
  18. package/dist/types/element/src/types.d.ts +5 -2
  19. package/dist/types/element/src/utils.d.ts +1 -1
  20. package/dist/types/excalidraw/actions/actionAddToLibrary.d.ts +23 -29
  21. package/dist/types/excalidraw/actions/actionBoundText.d.ts +16 -20
  22. package/dist/types/excalidraw/actions/actionCanvas.d.ts +161 -185
  23. package/dist/types/excalidraw/actions/actionClipboard.d.ts +16 -20
  24. package/dist/types/excalidraw/actions/actionCropEditor.d.ts +8 -10
  25. package/dist/types/excalidraw/actions/actionDeleteSelected.d.ts +25 -31
  26. package/dist/types/excalidraw/actions/actionElementLink.d.ts +4 -10
  27. package/dist/types/excalidraw/actions/actionElementLock.d.ts +16 -20
  28. package/dist/types/excalidraw/actions/actionEmbeddable.d.ts +8 -10
  29. package/dist/types/excalidraw/actions/actionExport.d.ts +104 -388
  30. package/dist/types/excalidraw/actions/actionFrame.d.ts +32 -40
  31. package/dist/types/excalidraw/actions/actionGroup.d.ts +18 -22
  32. package/dist/types/excalidraw/actions/actionLinearEditor.d.ts +8 -10
  33. package/dist/types/excalidraw/actions/actionLink.d.ts +8 -10
  34. package/dist/types/excalidraw/actions/actionMenu.d.ts +4 -10
  35. package/dist/types/excalidraw/actions/actionProperties.d.ts +17 -21
  36. package/dist/types/excalidraw/actions/actionSelectAll.d.ts +9 -11
  37. package/dist/types/excalidraw/actions/actionStyles.d.ts +7 -9
  38. package/dist/types/excalidraw/actions/actionToggleArrowBinding.d.ts +172 -0
  39. package/dist/types/excalidraw/actions/actionToggleGridMode.d.ts +8 -10
  40. package/dist/types/excalidraw/actions/actionToggleMidpointSnapping.d.ts +172 -0
  41. package/dist/types/excalidraw/actions/actionToggleObjectsSnapMode.d.ts +8 -10
  42. package/dist/types/excalidraw/actions/actionToggleSearchMenu.d.ts +4 -10
  43. package/dist/types/excalidraw/actions/actionToggleStats.d.ts +8 -10
  44. package/dist/types/excalidraw/actions/actionToggleViewMode.d.ts +8 -10
  45. package/dist/types/excalidraw/actions/actionToggleZenMode.d.ts +8 -10
  46. package/dist/types/excalidraw/actions/index.d.ts +2 -0
  47. package/dist/types/excalidraw/actions/types.d.ts +1 -1
  48. package/dist/types/excalidraw/appState.d.ts +29 -27
  49. package/dist/types/excalidraw/charts/charts.bar.d.ts +2 -0
  50. package/dist/types/excalidraw/charts/charts.constants.d.ts +48 -0
  51. package/dist/types/excalidraw/charts/charts.helpers.d.ts +32 -0
  52. package/dist/types/excalidraw/charts/charts.line.d.ts +2 -0
  53. package/dist/types/excalidraw/charts/charts.parse.d.ts +10 -0
  54. package/dist/types/excalidraw/charts/charts.radar.d.ts +2 -0
  55. package/dist/types/excalidraw/charts/charts.types.d.ts +18 -0
  56. package/dist/types/excalidraw/charts/index.d.ts +7 -0
  57. package/dist/types/excalidraw/clipboard.d.ts +4 -7
  58. package/dist/types/excalidraw/components/App.d.ts +33 -11
  59. package/dist/types/excalidraw/components/AppStateObserver.d.ts +37 -0
  60. package/dist/types/excalidraw/components/IconPicker.d.ts +14 -9
  61. package/dist/types/excalidraw/components/PasteChartDialog.d.ts +4 -5
  62. package/dist/types/excalidraw/components/TTDDialog/CodeMirrorEditor.d.ts +11 -0
  63. package/dist/types/excalidraw/components/TTDDialog/TTDDialogInput.d.ts +3 -3
  64. package/dist/types/excalidraw/components/TTDDialog/TTDDialogOutput.d.ts +4 -1
  65. package/dist/types/excalidraw/components/TTDDialog/mermaid-lang-lite.d.ts +2 -0
  66. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidAutoFix.d.ts +1 -0
  67. package/dist/types/excalidraw/components/TTDDialog/utils/mermaidError.d.ts +10 -0
  68. package/dist/types/excalidraw/components/Toast.d.ts +8 -4
  69. package/dist/types/excalidraw/components/icons.d.ts +17 -8
  70. package/dist/types/excalidraw/components/main-menu/DefaultItems.d.ts +2 -0
  71. package/dist/types/excalidraw/data/blob.d.ts +157 -162
  72. package/dist/types/excalidraw/data/filesystem.d.ts +3 -5
  73. package/dist/types/excalidraw/data/index.d.ts +2 -3
  74. package/dist/types/excalidraw/data/json.d.ts +90 -84
  75. package/dist/types/excalidraw/data/resave.d.ts +7 -2
  76. package/dist/types/excalidraw/types.d.ts +84 -13
  77. package/package.json +1 -1
  78. package/dist/types/excalidraw/charts.d.ts +0 -27
  79. package/dist/types/excalidraw/components/DiagramToCodePlugin/DiagramToCodePlugin.d.ts +0 -4
  80. package/dist/types/excalidraw/components/ExcalidrawLogo.d.ts +0 -15
  81. package/dist/types/excalidraw/components/InitializeApp.d.ts +0 -10
  82. package/dist/types/excalidraw/components/TTDDialog/TTDDialogTrigger.d.ts +0 -8
  83. package/dist/types/excalidraw/components/TTDDialog/utils/TTDStreamFetch.d.ts +0 -24
  84. package/dist/types/excalidraw/components/footer/FooterCenter.d.ts +0 -8
  85. package/dist/types/excalidraw/components/live-collaboration/LiveCollaborationTrigger.d.ts +0 -11
  86. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Center.d.ts +0 -58
  87. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.Hints.d.ts +0 -19
  88. package/dist/types/excalidraw/components/welcome-screen/WelcomeScreen.d.ts +0 -84
  89. package/dist/types/excalidraw/data/reconcile.d.ts +0 -7
  90. package/dist/types/excalidraw/index.d.ts +0 -47
  91. package/dist/types/excalidraw/polyfill.d.ts +0 -2
package/dist/dev/index.js CHANGED
@@ -2484,7 +2484,7 @@ var isInteractive = (target) => {
2484
2484
  return isInputLike(target) || target instanceof Element && !!target.closest("label, button");
2485
2485
  };
2486
2486
  var isWritableElement = (target) => target instanceof HTMLElement && target.dataset.type === "wysiwyg" || target instanceof HTMLBRElement || // newline in wysiwyg
2487
- target instanceof HTMLTextAreaElement || target instanceof HTMLInputElement && (target.type === "text" || target.type === "number" || target.type === "password" || target.type === "search");
2487
+ target instanceof HTMLTextAreaElement || target instanceof HTMLInputElement && (target.type === "text" || target.type === "number" || target.type === "password" || target.type === "search") || target instanceof HTMLElement && target.closest(".cm-editor") !== null;
2488
2488
  var getFontFamilyString = ({
2489
2489
  fontFamily
2490
2490
  }) => {
@@ -2529,32 +2529,23 @@ var debounce = (fn, timeout) => {
2529
2529
  };
2530
2530
  return ret;
2531
2531
  };
2532
- var throttleRAF = (fn, opts) => {
2532
+ var throttleRAF = (fn) => {
2533
2533
  let timerId = null;
2534
2534
  let lastArgs = null;
2535
- let lastArgsTrailing = null;
2536
- const scheduleFunc = (args) => {
2535
+ const scheduleFunc = () => {
2537
2536
  timerId = window.requestAnimationFrame(() => {
2538
2537
  timerId = null;
2539
- fn(...args);
2538
+ const args = lastArgs;
2540
2539
  lastArgs = null;
2541
- if (lastArgsTrailing) {
2542
- lastArgs = lastArgsTrailing;
2543
- lastArgsTrailing = null;
2544
- scheduleFunc(lastArgs);
2540
+ if (args) {
2541
+ fn(...args);
2545
2542
  }
2546
2543
  });
2547
2544
  };
2548
2545
  const ret = (...args) => {
2549
- if (isTestEnv()) {
2550
- fn(...args);
2551
- return;
2552
- }
2553
2546
  lastArgs = args;
2554
2547
  if (timerId === null) {
2555
- scheduleFunc(lastArgs);
2556
- } else if (opts?.trailing) {
2557
- lastArgsTrailing = args;
2548
+ scheduleFunc();
2558
2549
  }
2559
2550
  };
2560
2551
  ret.flush = () => {
@@ -2563,12 +2554,12 @@ var throttleRAF = (fn, opts) => {
2563
2554
  timerId = null;
2564
2555
  }
2565
2556
  if (lastArgs) {
2566
- fn(...lastArgsTrailing || lastArgs);
2567
- lastArgs = lastArgsTrailing = null;
2557
+ fn(...lastArgs);
2558
+ lastArgs = null;
2568
2559
  }
2569
2560
  };
2570
2561
  ret.cancel = () => {
2571
- lastArgs = lastArgsTrailing = null;
2562
+ lastArgs = null;
2572
2563
  if (timerId !== null) {
2573
2564
  cancelAnimationFrame(timerId);
2574
2565
  timerId = null;
@@ -3236,6 +3227,131 @@ var Emitter = class {
3236
3227
  }
3237
3228
  };
3238
3229
 
3230
+ // src/appEventBus.ts
3231
+ init_define_import_meta_env();
3232
+ var AppEventBus = class {
3233
+ constructor(behavior) {
3234
+ this.behavior = behavior;
3235
+ }
3236
+ emitters = /* @__PURE__ */ new Map();
3237
+ lastPayload = /* @__PURE__ */ new Map();
3238
+ emittedOnce = /* @__PURE__ */ new Set();
3239
+ getEmitter(name) {
3240
+ let emitter = this.emitters.get(name);
3241
+ if (!emitter) {
3242
+ emitter = new Emitter();
3243
+ this.emitters.set(name, emitter);
3244
+ }
3245
+ return emitter;
3246
+ }
3247
+ toPromiseValue(args) {
3248
+ return args.length === 1 ? args[0] : args;
3249
+ }
3250
+ on(name, callback) {
3251
+ const eventBehavior = this.behavior[name];
3252
+ const cachedPayload = this.lastPayload.get(name);
3253
+ if (callback) {
3254
+ if (eventBehavior.replay === "last" && cachedPayload) {
3255
+ queueMicrotask(() => callback(...cachedPayload));
3256
+ if (eventBehavior.cardinality === "once") {
3257
+ return () => {
3258
+ };
3259
+ }
3260
+ }
3261
+ return this.getEmitter(name).on(callback);
3262
+ }
3263
+ if (eventBehavior.cardinality !== "once" || eventBehavior.replay !== "last") {
3264
+ throw new Error(`Event "${String(name)}" requires a callback`);
3265
+ }
3266
+ if (cachedPayload) {
3267
+ return Promise.resolve(this.toPromiseValue(cachedPayload));
3268
+ }
3269
+ return new Promise((resolve) => {
3270
+ this.getEmitter(name).once((...args) => {
3271
+ resolve(this.toPromiseValue(args));
3272
+ });
3273
+ });
3274
+ }
3275
+ emit(name, ...args) {
3276
+ const eventBehavior = this.behavior[name];
3277
+ if (!isProdEnv()) {
3278
+ if (eventBehavior.cardinality === "once") {
3279
+ if (this.emittedOnce.has(name)) {
3280
+ throw new Error(`Event "${String(name)}" can only be emitted once`);
3281
+ }
3282
+ this.emittedOnce.add(name);
3283
+ }
3284
+ }
3285
+ if (eventBehavior.replay === "last") {
3286
+ this.lastPayload.set(name, args);
3287
+ }
3288
+ try {
3289
+ this.getEmitter(name).trigger(...args);
3290
+ } finally {
3291
+ if (eventBehavior.cardinality === "once") {
3292
+ this.getEmitter(name).clear();
3293
+ }
3294
+ }
3295
+ }
3296
+ clear() {
3297
+ this.lastPayload.clear();
3298
+ this.emittedOnce.clear();
3299
+ for (const emitter of this.emitters.values()) {
3300
+ emitter.clear();
3301
+ }
3302
+ this.emitters.clear();
3303
+ }
3304
+ };
3305
+
3306
+ // src/versionedSnapshotStore.ts
3307
+ init_define_import_meta_env();
3308
+ var VersionedSnapshotStore = class {
3309
+ constructor(initialValue, isEqual = Object.is) {
3310
+ this.isEqual = isEqual;
3311
+ this.value = initialValue;
3312
+ }
3313
+ version = 0;
3314
+ value;
3315
+ waiters = /* @__PURE__ */ new Set();
3316
+ subscribers = /* @__PURE__ */ new Set();
3317
+ getSnapshot() {
3318
+ return { version: this.version, value: this.value };
3319
+ }
3320
+ set(nextValue) {
3321
+ if (this.isEqual(this.value, nextValue)) {
3322
+ return false;
3323
+ }
3324
+ this.value = nextValue;
3325
+ this.version += 1;
3326
+ const snapshot = this.getSnapshot();
3327
+ for (const subscriber of this.subscribers) {
3328
+ subscriber(snapshot);
3329
+ }
3330
+ for (const waiter of this.waiters) {
3331
+ waiter(snapshot);
3332
+ }
3333
+ this.waiters.clear();
3334
+ return true;
3335
+ }
3336
+ update(updater) {
3337
+ return this.set(updater(this.value));
3338
+ }
3339
+ subscribe(subscriber) {
3340
+ this.subscribers.add(subscriber);
3341
+ return () => {
3342
+ this.subscribers.delete(subscriber);
3343
+ };
3344
+ }
3345
+ pull(sinceVersion = -1) {
3346
+ if (this.version !== sinceVersion) {
3347
+ return Promise.resolve(this.getSnapshot());
3348
+ }
3349
+ return new Promise((resolve) => {
3350
+ this.waiters.add(resolve);
3351
+ });
3352
+ }
3353
+ };
3354
+
3239
3355
  // debug.ts
3240
3356
  init_define_import_meta_env();
3241
3357
  var lessPrecise = (num, precision = 5) => parseFloat(num.toPrecision(precision));
@@ -3409,6 +3525,7 @@ export {
3409
3525
  ARROW_LABEL_FONT_SIZE_TO_MIN_WIDTH_RATIO,
3410
3526
  ARROW_LABEL_WIDTH_FRACTION,
3411
3527
  ARROW_TYPE,
3528
+ AppEventBus,
3412
3529
  BIND_MODE_TIMEOUT,
3413
3530
  BOUND_TEXT_PADDING,
3414
3531
  BinaryHeap,
@@ -3534,6 +3651,7 @@ export {
3534
3651
  VERSIONS,
3535
3652
  VERSION_TIMEOUT,
3536
3653
  VERTICAL_ALIGN,
3654
+ VersionedSnapshotStore,
3537
3655
  WINDOWS_EMOJI_FALLBACK_FONT,
3538
3656
  YOUTUBE_STATES,
3539
3657
  ZOOM_STEP,