kritzel-stencil 0.0.145 → 0.0.147

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 (44) hide show
  1. package/dist/cjs/{default-text-tool.config-D2dP2xyB.js → default-text-tool.config-C0W0noF9.js} +54 -34
  2. package/dist/cjs/default-text-tool.config-C0W0noF9.js.map +1 -0
  3. package/dist/cjs/index.cjs.js +1 -1
  4. package/dist/cjs/kritzel-color_22.cjs.entry.js +16 -41
  5. package/dist/collection/classes/core/viewport.class.js +4 -2
  6. package/dist/collection/classes/core/viewport.class.js.map +1 -1
  7. package/dist/collection/classes/objects/text.class.js +23 -23
  8. package/dist/collection/classes/objects/text.class.js.map +1 -1
  9. package/dist/collection/classes/tools/text-tool.class.js +3 -10
  10. package/dist/collection/classes/tools/text-tool.class.js.map +1 -1
  11. package/dist/collection/configs/default-engine-config.js +1 -2
  12. package/dist/collection/configs/default-engine-config.js.map +1 -1
  13. package/dist/collection/interfaces/debug-info.interface.js.map +1 -1
  14. package/dist/components/index.js +3 -3
  15. package/dist/components/kritzel-controls.js +1 -1
  16. package/dist/components/kritzel-editor.js +3 -3
  17. package/dist/components/kritzel-engine.js +1 -1
  18. package/dist/components/{p-ByRC-aCs.js → p-CrkPot2F.js} +8 -7
  19. package/dist/components/p-CrkPot2F.js.map +1 -0
  20. package/dist/components/{p-BgRGxOIE.js → p-DPN0PZvw.js} +3 -3
  21. package/dist/components/{p-BgRGxOIE.js.map → p-DPN0PZvw.js.map} +1 -1
  22. package/dist/components/{p-COGwCbe1.js → p-G2HGJcNm.js} +28 -34
  23. package/dist/components/p-G2HGJcNm.js.map +1 -0
  24. package/dist/esm/{default-text-tool.config-CsZAW1Cu.js → default-text-tool.config-nXXHSTK9.js} +54 -35
  25. package/dist/esm/default-text-tool.config-nXXHSTK9.js.map +1 -0
  26. package/dist/esm/index.js +2 -2
  27. package/dist/esm/kritzel-color_22.entry.js +6 -31
  28. package/dist/stencil/index.esm.js +1 -1
  29. package/dist/stencil/p-5d9c3f1b.entry.js +2 -0
  30. package/dist/stencil/p-5d9c3f1b.entry.js.map +1 -0
  31. package/dist/stencil/p-nXXHSTK9.js +2 -0
  32. package/dist/stencil/p-nXXHSTK9.js.map +1 -0
  33. package/dist/stencil/stencil.esm.js +1 -1
  34. package/dist/types/classes/objects/text.class.d.ts +1 -0
  35. package/dist/types/interfaces/debug-info.interface.d.ts +0 -1
  36. package/package.json +15 -14
  37. package/dist/cjs/default-text-tool.config-D2dP2xyB.js.map +0 -1
  38. package/dist/components/p-ByRC-aCs.js.map +0 -1
  39. package/dist/components/p-COGwCbe1.js.map +0 -1
  40. package/dist/esm/default-text-tool.config-CsZAW1Cu.js.map +0 -1
  41. package/dist/stencil/p-27adbf9d.entry.js +0 -2
  42. package/dist/stencil/p-27adbf9d.entry.js.map +0 -1
  43. package/dist/stencil/p-CsZAW1Cu.js +0 -2
  44. package/dist/stencil/p-CsZAW1Cu.js.map +0 -1
@@ -353,6 +353,32 @@ class KritzelKeyboardHelper {
353
353
  }
354
354
  }
355
355
 
356
+ class KritzelDevicesHelper {
357
+ static isTouchDevice() {
358
+ return window.matchMedia('(any-pointer: coarse)').matches;
359
+ }
360
+ static isAndroid() {
361
+ return /android/i.test(navigator.userAgent);
362
+ }
363
+ static isIOS() {
364
+ return /iPad|iPhone|iPod/.test(navigator.userAgent);
365
+ }
366
+ static detectOS() {
367
+ if (this.isIOS()) {
368
+ return 'iOS';
369
+ }
370
+ else if (this.isAndroid()) {
371
+ return 'Android';
372
+ }
373
+ else {
374
+ return 'Other';
375
+ }
376
+ }
377
+ static isFirefox() {
378
+ return /firefox/i.test(navigator.userAgent);
379
+ }
380
+ }
381
+
356
382
  // ::- Persistent data structure representing an ordered mapping from
357
383
  // strings to values, with some convenient update methods.
358
384
  function OrderedMap(content) {
@@ -13906,17 +13932,12 @@ class KritzelText extends KritzelBaseObject {
13906
13932
  }),
13907
13933
  editable: () => false,
13908
13934
  dispatchTransaction: transaction => {
13909
- // Apply the transaction to get the new state
13910
13935
  const newState = this.editor.state.apply(transaction);
13911
- // Update the editor state first
13912
13936
  this.editor.updateState(newState);
13913
- // Only update content and adjust size if the document actually changed
13914
- // AND it's not from a remote source (to prevent infinite loops)
13915
13937
  if (transaction.docChanged) {
13916
13938
  this.content = newState.doc.toJSON();
13917
13939
  this.adjustSizeOnInput();
13918
13940
  if (!transaction.getMeta('fromRemote')) {
13919
- // Mark updates as temporary while editing - they'll be consolidated on save
13920
13941
  this._core.store.state.objectsMap.update(this, { temporary: true });
13921
13942
  }
13922
13943
  }
@@ -13928,7 +13949,6 @@ class KritzelText extends KritzelBaseObject {
13928
13949
  if (this.editor && content) {
13929
13950
  const newDoc = this.editor.state.schema.nodeFromJSON(content);
13930
13951
  const tr = this.editor.state.tr.replaceWith(0, this.editor.state.doc.content.size, newDoc.content);
13931
- // Mark this transaction as coming from remote/external source
13932
13952
  tr.setMeta('fromRemote', true);
13933
13953
  this.editor.dispatch(tr);
13934
13954
  }
@@ -13976,39 +13996,46 @@ class KritzelText extends KritzelBaseObject {
13976
13996
  focus(coords) {
13977
13997
  if (this.editor) {
13978
13998
  const doc = this.editor.state.doc;
13979
- if (coords) {
13999
+ if (coords.x && coords.y) {
13980
14000
  const pos = this.editor.posAtCoords({ left: coords.x, top: coords.y });
13981
14001
  if (pos) {
13982
14002
  this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, pos.pos)));
13983
14003
  this.editor.focus();
14004
+ if (KritzelDevicesHelper.isIOS()) {
14005
+ this.scrollIntoViewOnIOS();
14006
+ }
13984
14007
  return;
13985
14008
  }
13986
14009
  }
13987
14010
  const end = Math.max(1, doc.content.size - 1);
13988
14011
  this.editor.dispatch(this.editor.state.tr.setSelection(TextSelection.create(doc, end)));
13989
14012
  this.editor.focus();
14013
+ if (KritzelDevicesHelper.isIOS()) {
14014
+ this.scrollIntoViewOnIOS();
14015
+ }
13990
14016
  }
13991
14017
  }
14018
+ scrollIntoViewOnIOS() {
14019
+ setTimeout(() => {
14020
+ if (this.editor && this.editor.dom) {
14021
+ this.editor.dom.scrollIntoView({
14022
+ behavior: 'smooth',
14023
+ block: 'center',
14024
+ inline: 'nearest'
14025
+ });
14026
+ }
14027
+ }, 300);
14028
+ }
13992
14029
  edit(event) {
13993
14030
  KritzelKeyboardHelper.disableInteractiveWidget();
13994
14031
  this.uneditedObject = this.clone();
13995
14032
  this._core.store.setState('activeTool', KritzelToolRegistry.getTool('text'));
13996
- if (this.editor) {
13997
- this.editor.setProps({ editable: () => true });
13998
- }
14033
+ this.editor.setProps({ editable: () => true });
13999
14034
  this.isEditing = true;
14000
14035
  this._core.rerender();
14001
- requestAnimationFrame(() => {
14002
- this.adjustSizeOnInput();
14003
- // Focus after the DOM has been updated
14004
- if (event) {
14005
- this.focus({ x: event.clientX, y: event.clientY });
14006
- }
14007
- else {
14008
- this.focus();
14009
- }
14010
- KritzelKeyboardHelper.enableInteractiveWidget();
14011
- });
14036
+ this.adjustSizeOnInput();
14037
+ this.focus({ x: event?.clientX, y: event?.clientY });
14038
+ KritzelKeyboardHelper.enableInteractiveWidget();
14012
14039
  }
14013
14040
  save() {
14014
14041
  requestAnimationFrame(() => this.adjustSizeOnInput());
@@ -14016,9 +14043,7 @@ class KritzelText extends KritzelBaseObject {
14016
14043
  this.editor.setProps({ editable: () => false });
14017
14044
  this.editor.dom.blur();
14018
14045
  this.isEditing = false;
14019
- // Consolidate all temporary keystrokes into a single undo item
14020
14046
  this._core.store.state.objectsMap.consolidateTemporaryItems();
14021
- // Final update with normal origin
14022
14047
  this._core.store.state.objectsMap.update(this);
14023
14048
  }
14024
14049
  handlePointerDown(event) {
@@ -14860,7 +14885,7 @@ class KritzelTextTool extends KritzelBaseTool {
14860
14885
  text.zIndex = this._core.store.currentZIndex;
14861
14886
  this._core.store.state.objectsMap.insert(text);
14862
14887
  this._core.rerender();
14863
- requestAnimationFrame(() => text.edit(event));
14888
+ text.edit(event);
14864
14889
  }
14865
14890
  if (event.pointerType === 'touch') {
14866
14891
  const activePointers = Array.from(this._core.store.state.pointers.values());
@@ -14885,7 +14910,6 @@ class KritzelTextTool extends KritzelBaseTool {
14885
14910
  if (activePointers.length > 1) {
14886
14911
  return;
14887
14912
  }
14888
- KritzelKeyboardHelper.disableInteractiveWidget();
14889
14913
  const clientX = Math.round(activePointers[0].clientX - this._core.store.offsetX);
14890
14914
  const clientY = Math.round(activePointers[0].clientY - this._core.store.offsetY);
14891
14915
  const text = KritzelText.create(this._core, this.fontSize, this.fontFamily);
@@ -14895,19 +14919,14 @@ class KritzelTextTool extends KritzelBaseTool {
14895
14919
  text.zIndex = this._core.store.currentZIndex;
14896
14920
  this._core.store.state.objectsMap.insert(text);
14897
14921
  this._core.rerender();
14922
+ text.edit(event);
14898
14923
  }
14899
14924
  }
14900
14925
  handlePointerUp(event) {
14901
14926
  if (event.cancelable) {
14902
14927
  event.preventDefault();
14903
14928
  }
14904
- if (event.pointerType === 'mouse') {
14905
- this._core.store.activeText?.edit(event);
14906
- }
14907
- if (event.pointerType === 'touch') {
14908
- this._core.store.activeText?.edit(event);
14909
- KritzelKeyboardHelper.enableInteractiveWidget();
14910
- }
14929
+ this._core.store.activeText?.edit(event);
14911
14930
  }
14912
14931
  }
14913
14932
 
@@ -31245,7 +31264,7 @@ const DEFAULT_TEXT_CONFIG = {
31245
31264
  ],
31246
31265
  };
31247
31266
 
31248
- export { Doc as $, isNode as A, min$2 as B, pow as C, HocuspocusProviderWebsocket as D, KritzelPath as E, KritzelImage as F, KritzelBrushTool as G, HocuspocusProvider as H, KritzelEraserTool as I, KritzelImageTool as J, KritzelText as K, KritzelTextTool as L, KritzelSelectionTool as M, BroadcastSyncProvider as N, Observable$1 as O, IndexedDBSyncProvider as P, KritzelAppStateMap as Q, KritzelWorkspace as R, DEFAULT_BRUSH_CONFIG as S, DEFAULT_TEXT_CONFIG as T, KritzelMouseButton as U, KritzelKeyboardHelper as V, KritzelBaseHandler as W, KritzelToolRegistry as X, KritzelSelectionBox as Y, KritzelSelectionGroup as Z, KritzelBaseObject as _, createUint8ArrayFromArrayBuffer as a, DEFAULT_SYNC_CONFIG as a0, UndoManager as a1, ObjectHelper as a2, KritzelEventHelper as a3, KritzelBaseTool as a4, offChange as b, create$8 as c, writeVarUint8Array$2 as d, encodeStateVector as e, fromBase64 as f, encodeStateAsUpdate as g, applyUpdate as h, readVarUint8Array$2 as i, readVarString$2 as j, floor$2 as k, getUnixTime$1 as l, equalityDeep$1 as m, writeVarString$2 as n, onChange as o, toUint8Array$1 as p, createEncoder$1 as q, readVarUint$2 as r, setIfUndefined$1 as s, toBase64 as t, createDecoder$1 as u, varStorage as v, writeVarUint$2 as w, map as x, ObservableV2 as y, length$3 as z };
31249
- //# sourceMappingURL=default-text-tool.config-CsZAW1Cu.js.map
31267
+ export { KritzelBaseObject as $, isNode as A, min$2 as B, pow as C, HocuspocusProviderWebsocket as D, KritzelPath as E, KritzelImage as F, KritzelBrushTool as G, HocuspocusProvider as H, KritzelEraserTool as I, KritzelImageTool as J, KritzelText as K, KritzelTextTool as L, KritzelSelectionTool as M, BroadcastSyncProvider as N, Observable$1 as O, IndexedDBSyncProvider as P, KritzelAppStateMap as Q, KritzelWorkspace as R, DEFAULT_BRUSH_CONFIG as S, DEFAULT_TEXT_CONFIG as T, KritzelDevicesHelper as U, KritzelMouseButton as V, KritzelKeyboardHelper as W, KritzelBaseHandler as X, KritzelToolRegistry as Y, KritzelSelectionBox as Z, KritzelSelectionGroup as _, createUint8ArrayFromArrayBuffer as a, Doc as a0, DEFAULT_SYNC_CONFIG as a1, UndoManager as a2, ObjectHelper as a3, KritzelEventHelper as a4, KritzelBaseTool as a5, offChange as b, create$8 as c, writeVarUint8Array$2 as d, encodeStateVector as e, fromBase64 as f, encodeStateAsUpdate as g, applyUpdate as h, readVarUint8Array$2 as i, readVarString$2 as j, floor$2 as k, getUnixTime$1 as l, equalityDeep$1 as m, writeVarString$2 as n, onChange as o, toUint8Array$1 as p, createEncoder$1 as q, readVarUint$2 as r, setIfUndefined$1 as s, toBase64 as t, createDecoder$1 as u, varStorage as v, writeVarUint$2 as w, map as x, ObservableV2 as y, length$3 as z };
31268
+ //# sourceMappingURL=default-text-tool.config-nXXHSTK9.js.map
31250
31269
 
31251
- //# sourceMappingURL=default-text-tool.config-CsZAW1Cu.js.map
31270
+ //# sourceMappingURL=default-text-tool.config-nXXHSTK9.js.map