haptic-f6b37aa3.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. 'use strict';
  5. const capacitor = require('./capacitor-c04564bf.js');
  6. exports.ImpactStyle = void 0;
  7. (function (ImpactStyle) {
  8. /**
  9. * A collision between large, heavy user interface elements
  10. *
  11. * @since 1.0.0
  12. */
  13. ImpactStyle["Heavy"] = "HEAVY";
  14. /**
  15. * A collision between moderately sized user interface elements
  16. *
  17. * @since 1.0.0
  18. */
  19. ImpactStyle["Medium"] = "MEDIUM";
  20. /**
  21. * A collision between small, light user interface elements
  22. *
  23. * @since 1.0.0
  24. */
  25. ImpactStyle["Light"] = "LIGHT";
  26. })(exports.ImpactStyle || (exports.ImpactStyle = {}));
  27. var NotificationType;
  28. (function (NotificationType) {
  29. /**
  30. * A notification feedback type indicating that a task has completed successfully
  31. *
  32. * @since 1.0.0
  33. */
  34. NotificationType["Success"] = "SUCCESS";
  35. /**
  36. * A notification feedback type indicating that a task has produced a warning
  37. *
  38. * @since 1.0.0
  39. */
  40. NotificationType["Warning"] = "WARNING";
  41. /**
  42. * A notification feedback type indicating that a task has failed
  43. *
  44. * @since 1.0.0
  45. */
  46. NotificationType["Error"] = "ERROR";
  47. })(NotificationType || (NotificationType = {}));
  48. const HapticEngine = {
  49. getEngine() {
  50. const capacitor$1 = capacitor.getCapacitor();
  51. if (capacitor$1 === null || capacitor$1 === void 0 ? void 0 : capacitor$1.isPluginAvailable('Haptics')) {
  52. // Capacitor
  53. return capacitor$1.Plugins.Haptics;
  54. }
  55. return undefined;
  56. },
  57. available() {
  58. const engine = this.getEngine();
  59. if (!engine) {
  60. return false;
  61. }
  62. const capacitor$1 = capacitor.getCapacitor();
  63. /**
  64. * Developers can manually import the
  65. * Haptics plugin in their app which will cause
  66. * getEngine to return the Haptics engine. However,
  67. * the Haptics engine will throw an error if
  68. * used in a web browser that does not support
  69. * the Vibrate API. This check avoids that error
  70. * if the browser does not support the Vibrate API.
  71. */
  72. if ((capacitor$1 === null || capacitor$1 === void 0 ? void 0 : capacitor$1.getPlatform()) === 'web') {
  73. // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
  74. return typeof navigator !== 'undefined' && navigator.vibrate !== undefined;
  75. }
  76. return true;
  77. },
  78. impact(options) {
  79. const engine = this.getEngine();
  80. if (!engine) {
  81. return;
  82. }
  83. engine.impact({ style: options.style });
  84. },
  85. notification(options) {
  86. const engine = this.getEngine();
  87. if (!engine) {
  88. return;
  89. }
  90. engine.notification({ type: options.type });
  91. },
  92. selection() {
  93. this.impact({ style: exports.ImpactStyle.Light });
  94. },
  95. selectionStart() {
  96. const engine = this.getEngine();
  97. if (!engine) {
  98. return;
  99. }
  100. engine.selectionStart();
  101. },
  102. selectionChanged() {
  103. const engine = this.getEngine();
  104. if (!engine) {
  105. return;
  106. }
  107. engine.selectionChanged();
  108. },
  109. selectionEnd() {
  110. const engine = this.getEngine();
  111. if (!engine) {
  112. return;
  113. }
  114. engine.selectionEnd();
  115. },
  116. };
  117. /**
  118. * Check to see if the Haptic Plugin is available
  119. * @return Returns `true` or false if the plugin is available
  120. */
  121. const hapticAvailable = () => {
  122. return HapticEngine.available();
  123. };
  124. /**
  125. * Trigger a selection changed haptic event. Good for one-time events
  126. * (not for gestures)
  127. */
  128. const hapticSelection = () => {
  129. hapticAvailable() && HapticEngine.selection();
  130. };
  131. /**
  132. * Tell the haptic engine that a gesture for a selection change is starting.
  133. */
  134. const hapticSelectionStart = () => {
  135. hapticAvailable() && HapticEngine.selectionStart();
  136. };
  137. /**
  138. * Tell the haptic engine that a selection changed during a gesture.
  139. */
  140. const hapticSelectionChanged = () => {
  141. hapticAvailable() && HapticEngine.selectionChanged();
  142. };
  143. /**
  144. * Tell the haptic engine we are done with a gesture. This needs to be
  145. * called lest resources are not properly recycled.
  146. */
  147. const hapticSelectionEnd = () => {
  148. hapticAvailable() && HapticEngine.selectionEnd();
  149. };
  150. /**
  151. * Use this to indicate success/failure/warning to the user.
  152. * options should be of the type `{ style: ImpactStyle.LIGHT }` (or `MEDIUM`/`HEAVY`)
  153. */
  154. const hapticImpact = (options) => {
  155. hapticAvailable() && HapticEngine.impact(options);
  156. };
  157. exports.hapticImpact = hapticImpact;
  158. exports.hapticSelection = hapticSelection;
  159. exports.hapticSelectionChanged = hapticSelectionChanged;
  160. exports.hapticSelectionEnd = hapticSelectionEnd;
  161. exports.hapticSelectionStart = hapticSelectionStart;