@paperless/core 1.9.4 → 1.11.0

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 (76) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/build/p-2540301a.entry.js +3 -0
  3. package/dist/build/p-2540301a.entry.js.map +1 -0
  4. package/dist/build/p-2cb55f24.entry.js +2 -0
  5. package/dist/build/p-2cb55f24.entry.js.map +1 -0
  6. package/dist/build/p-fac13366.entry.js +2 -0
  7. package/dist/build/p-fac13366.entry.js.map +1 -0
  8. package/dist/build/paperless.css +1 -1
  9. package/dist/build/paperless.esm.js +1 -1
  10. package/dist/build/paperless.esm.js.map +1 -1
  11. package/dist/cjs/index-1fde8b14.js +4 -0
  12. package/dist/cjs/loader.cjs.js +1 -1
  13. package/dist/cjs/p-cropper.cjs.entry.js +2815 -0
  14. package/dist/cjs/p-cropper.cjs.entry.js.map +1 -0
  15. package/dist/cjs/p-modal-body_4.cjs.entry.js +3 -2
  16. package/dist/cjs/p-modal-body_4.cjs.entry.js.map +1 -1
  17. package/dist/cjs/p-modal.cjs.entry.js +2 -1
  18. package/dist/cjs/p-modal.cjs.entry.js.map +1 -1
  19. package/dist/cjs/paperless.cjs.js +1 -1
  20. package/dist/collection/collection-manifest.json +1 -0
  21. package/dist/collection/components/atoms/modal-body/modal-body.component.css +1 -1
  22. package/dist/collection/components/atoms/modal-body/modal-body.component.js +20 -1
  23. package/dist/collection/components/atoms/modal-body/modal-body.component.js.map +1 -1
  24. package/dist/collection/components/molecules/cropper/cropper.component.css +1 -0
  25. package/dist/collection/components/molecules/cropper/cropper.component.js +235 -0
  26. package/dist/collection/components/molecules/cropper/cropper.component.js.map +1 -0
  27. package/dist/collection/components/molecules/cropper/test/cropper.component.e2e.js +26 -0
  28. package/dist/collection/components/molecules/cropper/test/cropper.component.e2e.js.map +1 -0
  29. package/dist/collection/components/molecules/cropper/test/cropper.component.spec.js +17 -0
  30. package/dist/collection/components/molecules/cropper/test/cropper.component.spec.js.map +1 -0
  31. package/dist/collection/components/organisms/modal/modal.component.js +21 -2
  32. package/dist/collection/components/organisms/modal/modal.component.js.map +1 -1
  33. package/dist/components/modal-body.component.js +5 -3
  34. package/dist/components/modal-body.component.js.map +1 -1
  35. package/dist/components/p-cropper.d.ts +11 -0
  36. package/dist/components/p-cropper.js +2841 -0
  37. package/dist/components/p-cropper.js.map +1 -0
  38. package/dist/components/p-modal.js +3 -1
  39. package/dist/components/p-modal.js.map +1 -1
  40. package/dist/esm/index-7b917f6b.js +4 -0
  41. package/dist/esm/loader.js +1 -1
  42. package/dist/esm/p-cropper.entry.js +2811 -0
  43. package/dist/esm/p-cropper.entry.js.map +1 -0
  44. package/dist/esm/p-modal-body_4.entry.js +3 -2
  45. package/dist/esm/p-modal-body_4.entry.js.map +1 -1
  46. package/dist/esm/p-modal.entry.js +2 -1
  47. package/dist/esm/p-modal.entry.js.map +1 -1
  48. package/dist/esm/paperless.js +1 -1
  49. package/dist/index.html +1 -1
  50. package/dist/paperless/p-2540301a.entry.js +3 -0
  51. package/dist/paperless/p-2540301a.entry.js.map +1 -0
  52. package/dist/paperless/p-2cb55f24.entry.js +2 -0
  53. package/dist/paperless/p-2cb55f24.entry.js.map +1 -0
  54. package/dist/paperless/p-fac13366.entry.js +2 -0
  55. package/dist/paperless/p-fac13366.entry.js.map +1 -0
  56. package/dist/paperless/paperless.css +35 -0
  57. package/dist/paperless/paperless.esm.js +1 -1
  58. package/dist/paperless/paperless.esm.js.map +1 -1
  59. package/dist/style/form/_range.scss +13 -0
  60. package/dist/style/form/index.scss +1 -0
  61. package/dist/sw.js +1 -1
  62. package/dist/sw.js.map +1 -1
  63. package/dist/types/components/atoms/modal-body/modal-body.component.d.ts +4 -0
  64. package/dist/types/components/molecules/cropper/cropper.component.d.ts +38 -0
  65. package/dist/types/components/organisms/modal/modal.component.d.ts +4 -0
  66. package/dist/types/components.d.ts +61 -0
  67. package/hydrate/index.js +2834 -9
  68. package/package.json +3 -1
  69. package/dist/build/p-997962db.entry.js +0 -2
  70. package/dist/build/p-997962db.entry.js.map +0 -1
  71. package/dist/build/p-b7893a63.entry.js +0 -2
  72. package/dist/build/p-b7893a63.entry.js.map +0 -1
  73. package/dist/paperless/p-997962db.entry.js +0 -2
  74. package/dist/paperless/p-997962db.entry.js.map +0 -1
  75. package/dist/paperless/p-b7893a63.entry.js +0 -2
  76. package/dist/paperless/p-b7893a63.entry.js.map +0 -1
package/hydrate/index.js CHANGED
@@ -4949,7 +4949,7 @@ function hydrateFactory($stencilWindow, $stencilHydrateOpts, $stencilHydrateResu
4949
4949
  /*hydrateAppClosure start*/
4950
4950
 
4951
4951
 
4952
- const NAMESPACE = 'paperless';
4952
+ const NAMESPACE$1 = 'paperless';
4953
4953
  const BUILD = /* paperless */ { allRenderFn: true, appendChildSlotFix: false, asyncLoading: true, attachStyles: true, cloneNodeFix: false, cmpDidLoad: true, cmpDidRender: true, cmpDidUnload: false, cmpDidUpdate: true, cmpShouldUpdate: true, cmpWillLoad: true, cmpWillRender: true, cmpWillUpdate: false, connectedCallback: false, constructableCSS: false, cssAnnotations: true, devTools: false, disconnectedCallback: true, element: false, event: true, hasRenderFn: true, hostListener: true, hostListenerTarget: true, hostListenerTargetBody: true, hostListenerTargetDocument: true, hostListenerTargetParent: false, hostListenerTargetWindow: true, hotModuleReplacement: false, hydrateClientSide: true, hydrateServerSide: true, hydratedAttribute: false, hydratedClass: true, isDebug: false, isDev: false, isTesting: false, lazyLoad: true, lifecycle: true, lifecycleDOMEvents: false, member: true, method: false, mode: false, observeAttribute: true, patchPseudoShadowDom: false, profile: false, prop: true, propBoolean: true, propMutable: true, propNumber: true, propString: true, reflect: true, scoped: false, scriptDataOpts: false, shadowDelegatesFocus: false, shadowDom: true, shadowDomShim: true, slot: true, slotChildNodesFix: false, slotRelocation: true, state: true, style: true, svg: false, taskQueue: true, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: true, vdomKey: false, vdomListener: true, vdomPropOrAttr: true, vdomRef: true, vdomRender: true, vdomStyle: true, vdomText: true, vdomXlink: false, watchCallback: true };
4954
4954
 
4955
4955
  function queryNonceMetaTagContent(e) {
@@ -5471,12 +5471,12 @@ const callRender = (e, t, o, n) => {
5471
5471
  BUILD.isDev ), n()) : (e.$flags$ |= 64, addHydratedFlag(o),
5472
5472
  (safeCall(s, "componentDidLoad"),
5473
5473
  BUILD.isDev ), n(), (e.$onReadyResolve$(o), l || appDidLoad())), (e.$onRenderResolve$ && (e.$onRenderResolve$(),
5474
- e.$onRenderResolve$ = void 0), 512 & e.$flags$ && nextTick((() => scheduleUpdate(e, !1))),
5474
+ e.$onRenderResolve$ = void 0), 512 & e.$flags$ && nextTick$1((() => scheduleUpdate(e, !1))),
5475
5475
  e.$flags$ &= -517);
5476
5476
  }, appDidLoad = e => {
5477
- addHydratedFlag(doc.documentElement), nextTick((() => emitEvent(win, "appload", {
5477
+ addHydratedFlag(doc.documentElement), nextTick$1((() => emitEvent(win, "appload", {
5478
5478
  detail: {
5479
- namespace: NAMESPACE
5479
+ namespace: NAMESPACE$1
5480
5480
  }
5481
5481
  }))), BUILD.profile ;
5482
5482
  }, safeCall = (e, t, o) => {
@@ -5746,7 +5746,7 @@ const cmpModules = new Map, getModule = e => {
5746
5746
  consoleError(e);
5747
5747
  }
5748
5748
  }));
5749
- }, resolved = Promise.resolve(), nextTick = e => resolved.then(e), defaultConsoleError = e => {
5749
+ }, resolved = Promise.resolve(), nextTick$1 = e => resolved.then(e), defaultConsoleError = e => {
5750
5750
  null != e && console.error(e.stack || e.message || e);
5751
5751
  }, consoleError = (e, t) => (defaultConsoleError)(e, t), plt = {
5752
5752
  $flags$: 0,
@@ -12240,6 +12240,2826 @@ class Counter {
12240
12240
  }; }
12241
12241
  }
12242
12242
 
12243
+ function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;t<e.length;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);else for(t in e)e[t]&&(n&&(n+=" "),n+=t);return n}function clsx(){for(var e,t,f=0,n="";f<arguments.length;)(e=arguments[f++])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
12244
+
12245
+ const IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
12246
+ const WINDOW = IS_BROWSER ? window : {};
12247
+ const IS_TOUCH_DEVICE = IS_BROWSER ? 'ontouchstart' in WINDOW.document.documentElement : false;
12248
+ const HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false;
12249
+ const NAMESPACE = 'cropper';
12250
+ const CROPPER_CANVAS = `${NAMESPACE}-canvas`;
12251
+ const CROPPER_CROSSHAIR = `${NAMESPACE}-crosshair`;
12252
+ const CROPPER_GIRD = `${NAMESPACE}-grid`;
12253
+ const CROPPER_HANDLE = `${NAMESPACE}-handle`;
12254
+ const CROPPER_IMAGE = `${NAMESPACE}-image`;
12255
+ const CROPPER_SELECTION = `${NAMESPACE}-selection`;
12256
+ const CROPPER_SHADE = `${NAMESPACE}-shade`;
12257
+ const CROPPER_VIEWER = `${NAMESPACE}-viewer`;
12258
+ // Actions
12259
+ const ACTION_SELECT = 'select';
12260
+ const ACTION_MOVE = 'move';
12261
+ const ACTION_SCALE = 'scale';
12262
+ const ACTION_ROTATE = 'rotate';
12263
+ const ACTION_TRANSFORM = 'transform';
12264
+ const ACTION_NONE = 'none';
12265
+ const ACTION_RESIZE_NORTH = 'n-resize';
12266
+ const ACTION_RESIZE_EAST = 'e-resize';
12267
+ const ACTION_RESIZE_SOUTH = 's-resize';
12268
+ const ACTION_RESIZE_WEST = 'w-resize';
12269
+ const ACTION_RESIZE_NORTHEAST = 'ne-resize';
12270
+ const ACTION_RESIZE_NORTHWEST = 'nw-resize';
12271
+ const ACTION_RESIZE_SOUTHEAST = 'se-resize';
12272
+ const ACTION_RESIZE_SOUTHWEST = 'sw-resize';
12273
+ // Attributes
12274
+ const ATTRIBUTE_ACTION = 'action';
12275
+ // Native events
12276
+ const EVENT_TOUCH_END = IS_TOUCH_DEVICE ? 'touchend touchcancel' : 'mouseup';
12277
+ const EVENT_TOUCH_MOVE = IS_TOUCH_DEVICE ? 'touchmove' : 'mousemove';
12278
+ const EVENT_TOUCH_START = IS_TOUCH_DEVICE ? 'touchstart' : 'mousedown';
12279
+ const EVENT_POINTER_DOWN = HAS_POINTER_EVENT ? 'pointerdown' : EVENT_TOUCH_START;
12280
+ const EVENT_POINTER_MOVE = HAS_POINTER_EVENT ? 'pointermove' : EVENT_TOUCH_MOVE;
12281
+ const EVENT_POINTER_UP = HAS_POINTER_EVENT ? 'pointerup pointercancel' : EVENT_TOUCH_END;
12282
+ const EVENT_ERROR = 'error';
12283
+ const EVENT_KEYDOWN = 'keydown';
12284
+ const EVENT_LOAD = 'load';
12285
+ const EVENT_WHEEL = 'wheel';
12286
+ // Custom events
12287
+ const EVENT_ACTION = 'action';
12288
+ const EVENT_ACTION_END = 'actionend';
12289
+ const EVENT_ACTION_MOVE = 'actionmove';
12290
+ const EVENT_ACTION_START = 'actionstart';
12291
+ const EVENT_CHANGE = 'change';
12292
+ const EVENT_TRANSFORM = 'transform';
12293
+
12294
+ /**
12295
+ * Check if the given value is a string.
12296
+ * @param {*} value The value to check.
12297
+ * @returns {boolean} Returns `true` if the given value is a string, else `false`.
12298
+ */
12299
+ function isString(value) {
12300
+ return typeof value === 'string';
12301
+ }
12302
+ /**
12303
+ * Check if the given value is not a number.
12304
+ */
12305
+ const isNaN$1 = Number.isNaN || WINDOW.isNaN;
12306
+ /**
12307
+ * Check if the given value is a number.
12308
+ * @param {*} value The value to check.
12309
+ * @returns {boolean} Returns `true` if the given value is a number, else `false`.
12310
+ */
12311
+ function isNumber(value) {
12312
+ return typeof value === 'number' && !isNaN$1(value);
12313
+ }
12314
+ /**
12315
+ * Check if the given value is a positive number.
12316
+ * @param {*} value The value to check.
12317
+ * @returns {boolean} Returns `true` if the given value is a positive number, else `false`.
12318
+ */
12319
+ function isPositiveNumber(value) {
12320
+ return isNumber(value) && value > 0 && value < Infinity;
12321
+ }
12322
+ /**
12323
+ * Check if the given value is undefined.
12324
+ * @param {*} value The value to check.
12325
+ * @returns {boolean} Returns `true` if the given value is undefined, else `false`.
12326
+ */
12327
+ function isUndefined(value) {
12328
+ return typeof value === 'undefined';
12329
+ }
12330
+ /**
12331
+ * Check if the given value is an object.
12332
+ * @param {*} value - The value to check.
12333
+ * @returns {boolean} Returns `true` if the given value is an object, else `false`.
12334
+ */
12335
+ function isObject(value) {
12336
+ return typeof value === 'object' && value !== null;
12337
+ }
12338
+ const { hasOwnProperty } = Object.prototype;
12339
+ /**
12340
+ * Check if the given value is a plain object.
12341
+ * @param {*} value - The value to check.
12342
+ * @returns {boolean} Returns `true` if the given value is a plain object, else `false`.
12343
+ */
12344
+ function isPlainObject(value) {
12345
+ if (!isObject(value)) {
12346
+ return false;
12347
+ }
12348
+ try {
12349
+ const { constructor } = value;
12350
+ const { prototype } = constructor;
12351
+ return constructor && prototype && hasOwnProperty.call(prototype, 'isPrototypeOf');
12352
+ }
12353
+ catch (error) {
12354
+ return false;
12355
+ }
12356
+ }
12357
+ /**
12358
+ * Check if the given value is a function.
12359
+ * @param {*} value The value to check.
12360
+ * @returns {boolean} Returns `true` if the given value is a function, else `false`.
12361
+ */
12362
+ function isFunction$1(value) {
12363
+ return typeof value === 'function';
12364
+ }
12365
+ /**
12366
+ * Check if the given node is an element.
12367
+ * @param {*} node The node to check.
12368
+ * @returns {boolean} Returns `true` if the given node is an element; otherwise, `false`.
12369
+ */
12370
+ function isElement$1(node) {
12371
+ return typeof node === 'object' && node !== null && node.nodeType === 1;
12372
+ }
12373
+ const REGEXP_CAMEL_CASE = /([a-z\d])([A-Z])/g;
12374
+ /**
12375
+ * Transform the given string from camelCase to kebab-case.
12376
+ * @param {string} value The value to transform.
12377
+ * @returns {string} Returns the transformed value.
12378
+ */
12379
+ function toKebabCase(value) {
12380
+ return String(value).replace(REGEXP_CAMEL_CASE, '$1-$2').toLowerCase();
12381
+ }
12382
+ const REGEXP_KEBAB_CASE = /-[A-z\d]/g;
12383
+ /**
12384
+ * Transform the given string from kebab-case to camelCase.
12385
+ * @param {string} value The value to transform.
12386
+ * @returns {string} Returns the transformed value.
12387
+ */
12388
+ function toCamelCase(value) {
12389
+ return value.replace(REGEXP_KEBAB_CASE, (substring) => substring.slice(1).toUpperCase());
12390
+ }
12391
+ const REGEXP_SPACES = /\s\s*/;
12392
+ /**
12393
+ * Remove event listener from the event target.
12394
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener}
12395
+ * @param {EventTarget} target The target of the event.
12396
+ * @param {string} types The types of the event.
12397
+ * @param {EventListenerOrEventListenerObject} listener The listener of the event.
12398
+ * @param {EventListenerOptions} [options] The options specify characteristics about the event listener.
12399
+ */
12400
+ function off(target, types, listener, options) {
12401
+ types.trim().split(REGEXP_SPACES).forEach((type) => {
12402
+ target.removeEventListener(type, listener, options);
12403
+ });
12404
+ }
12405
+ /**
12406
+ * Add event listener to the event target.
12407
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener}
12408
+ * @param {EventTarget} target The target of the event.
12409
+ * @param {string} types The types of the event.
12410
+ * @param {EventListenerOrEventListenerObject} listener The listener of the event.
12411
+ * @param {AddEventListenerOptions} [options] The options specify characteristics about the event listener.
12412
+ */
12413
+ function on(target, types, listener, options) {
12414
+ types.trim().split(REGEXP_SPACES).forEach((type) => {
12415
+ target.addEventListener(type, listener, options);
12416
+ });
12417
+ }
12418
+ /**
12419
+ * Add once event listener to the event target.
12420
+ * @param {EventTarget} target The target of the event.
12421
+ * @param {string} types The types of the event.
12422
+ * @param {EventListenerOrEventListenerObject} listener The listener of the event.
12423
+ * @param {AddEventListenerOptions} [options] The options specify characteristics about the event listener.
12424
+ */
12425
+ function once(target, types, listener, options) {
12426
+ on(target, types, listener, Object.assign(Object.assign({}, options), { once: true }));
12427
+ }
12428
+ const defaultEventOptions = {
12429
+ bubbles: true,
12430
+ cancelable: true,
12431
+ composed: true,
12432
+ };
12433
+ /**
12434
+ * Dispatch event on the event target.
12435
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/dispatchEvent}
12436
+ * @param {EventTarget} target The target of the event.
12437
+ * @param {string} type The name of the event.
12438
+ * @param {*} [detail] The data passed when initializing the event.
12439
+ * @param {CustomEventInit} [options] The other event options.
12440
+ * @returns {boolean} Returns the result value.
12441
+ */
12442
+ function emit(target, type, detail, options) {
12443
+ return target.dispatchEvent(new CustomEvent(type, Object.assign(Object.assign(Object.assign({}, defaultEventOptions), { detail }), options)));
12444
+ }
12445
+ const resolvedPromise = Promise.resolve();
12446
+ /**
12447
+ * Defers the callback to be executed after the next DOM update cycle.
12448
+ * @param {*} [context] The `this` context.
12449
+ * @param {Function} [callback] The callback to execute after the next DOM update cycle.
12450
+ * @returns {Promise} A promise that resolves to nothing.
12451
+ */
12452
+ function nextTick(context, callback) {
12453
+ return callback
12454
+ ? resolvedPromise.then(context ? callback.bind(context) : callback)
12455
+ : resolvedPromise;
12456
+ }
12457
+ /**
12458
+ * Get the offset base on the document.
12459
+ * @param {Element} element The target element.
12460
+ * @returns {object} The offset data.
12461
+ */
12462
+ function getOffset(element) {
12463
+ const { documentElement } = element.ownerDocument;
12464
+ const box = element.getBoundingClientRect();
12465
+ return {
12466
+ left: box.left + (WINDOW.pageXOffset - documentElement.clientLeft),
12467
+ top: box.top + (WINDOW.pageYOffset - documentElement.clientTop),
12468
+ };
12469
+ }
12470
+ const REGEXP_ANGLE_UNIT = /deg|g?rad|turn$/i;
12471
+ /**
12472
+ * Convert an angle to a radian number.
12473
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/angle}
12474
+ * @param {number|string} angle The angle to convert.
12475
+ * @returns {number} Returns the radian number.
12476
+ */
12477
+ function toAngleInRadian(angle) {
12478
+ const value = parseFloat(angle) || 0;
12479
+ if (value !== 0) {
12480
+ const [unit = 'rad'] = String(angle).match(REGEXP_ANGLE_UNIT) || [];
12481
+ switch (unit.toLowerCase()) {
12482
+ case 'deg':
12483
+ return (value / 360) * (Math.PI * 2);
12484
+ case 'grad':
12485
+ return (value / 400) * (Math.PI * 2);
12486
+ case 'turn':
12487
+ return value * (Math.PI * 2);
12488
+ }
12489
+ }
12490
+ return value;
12491
+ }
12492
+ const SIZE_ADJUSTMENT_TYPE_CONTAIN = 'contain';
12493
+ const SIZE_ADJUSTMENT_TYPE_COVER = 'cover';
12494
+ /**
12495
+ * Get the max sizes in a rectangle under the given aspect ratio.
12496
+ * @param {object} data The original sizes.
12497
+ * @param {string} [type] The adjust type.
12498
+ * @returns {object} Returns the result sizes.
12499
+ */
12500
+ function getAdjustedSizes(data, type = SIZE_ADJUSTMENT_TYPE_CONTAIN) {
12501
+ const { aspectRatio } = data;
12502
+ let { width, height } = data;
12503
+ const isValidWidth = isPositiveNumber(width);
12504
+ const isValidHeight = isPositiveNumber(height);
12505
+ if (isValidWidth && isValidHeight) {
12506
+ const adjustedWidth = height * aspectRatio;
12507
+ if ((type === SIZE_ADJUSTMENT_TYPE_CONTAIN && adjustedWidth > width)
12508
+ || (type === SIZE_ADJUSTMENT_TYPE_COVER && adjustedWidth < width)) {
12509
+ height = width / aspectRatio;
12510
+ }
12511
+ else {
12512
+ width = height * aspectRatio;
12513
+ }
12514
+ }
12515
+ else if (isValidWidth) {
12516
+ height = width / aspectRatio;
12517
+ }
12518
+ else if (isValidHeight) {
12519
+ width = height * aspectRatio;
12520
+ }
12521
+ return {
12522
+ width,
12523
+ height,
12524
+ };
12525
+ }
12526
+ /**
12527
+ * Multiply multiple matrices.
12528
+ * @param {Array} matrix The first matrix.
12529
+ * @param {Array} args The rest matrices.
12530
+ * @returns {Array} Returns the result matrix.
12531
+ */
12532
+ function multiplyMatrices(matrix, ...args) {
12533
+ if (args.length === 0) {
12534
+ return matrix;
12535
+ }
12536
+ const [a1, b1, c1, d1, e1, f1] = matrix;
12537
+ const [a2, b2, c2, d2, e2, f2] = args[0];
12538
+ // ┌ a1 c1 e1 ┐ ┌ a2 c2 e2 ┐
12539
+ // │ b1 d1 f1 │ × │ b2 d2 f2 │
12540
+ // └ 0 0 1 ┘ └ 0 0 1 ┘
12541
+ matrix = [
12542
+ a1 * a2 + c1 * b2 /* + e1 * 0 */,
12543
+ b1 * a2 + d1 * b2 /* + f1 * 0 */,
12544
+ a1 * c2 + c1 * d2 /* + e1 * 0 */,
12545
+ b1 * c2 + d1 * d2 /* + f1 * 0 */,
12546
+ a1 * e2 + c1 * f2 + e1 /* * 1 */,
12547
+ b1 * e2 + d1 * f2 + f1 /* * 1 */,
12548
+ ];
12549
+ return multiplyMatrices(matrix, ...args.slice(1));
12550
+ }
12551
+
12552
+ var style$8 = `:host([hidden]){display:none!important}`;
12553
+
12554
+ const REGEXP_SUFFIX = /left|top|width|height/i;
12555
+ const DEFAULT_SHADOW_ROOT_MODE = 'open';
12556
+ const shadowRoots = new WeakMap();
12557
+ const styleSheets = new WeakMap();
12558
+ const tagNames = new Map();
12559
+ const supportsAdoptedStyleSheets = WINDOW.document && Array.isArray(WINDOW.document.adoptedStyleSheets) && 'replaceSync' in WINDOW.CSSStyleSheet.prototype;
12560
+ class CropperElement extends HTMLElement {
12561
+ get $sharedStyle() {
12562
+ return `${this.themeColor ? `:host{--theme-color: ${this.themeColor};}` : ''}${style$8}`;
12563
+ }
12564
+ constructor() {
12565
+ var _a, _b;
12566
+ super();
12567
+ this.shadowRootMode = DEFAULT_SHADOW_ROOT_MODE;
12568
+ this.slottable = true;
12569
+ const name = (_b = (_a = Object.getPrototypeOf(this)) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.$name;
12570
+ if (name) {
12571
+ tagNames.set(name, this.tagName.toLowerCase());
12572
+ }
12573
+ }
12574
+ static get observedAttributes() {
12575
+ return [
12576
+ 'shadow-root-mode',
12577
+ 'slottable',
12578
+ 'theme-color',
12579
+ ];
12580
+ }
12581
+ // Convert attribute to property
12582
+ attributeChangedCallback(name, oldValue, newValue) {
12583
+ if (Object.is(newValue, oldValue)) {
12584
+ return;
12585
+ }
12586
+ const propertyName = toCamelCase(name);
12587
+ const oldPropertyValue = this[propertyName];
12588
+ let newPropertyValue = newValue;
12589
+ switch (typeof oldPropertyValue) {
12590
+ case 'boolean':
12591
+ newPropertyValue = newValue !== null && newValue !== 'false';
12592
+ break;
12593
+ case 'number':
12594
+ newPropertyValue = Number(newValue);
12595
+ break;
12596
+ }
12597
+ this[propertyName] = newPropertyValue;
12598
+ switch (name) {
12599
+ case 'theme-color': {
12600
+ const styleSheet = styleSheets.get(this);
12601
+ const styles = this.$sharedStyle;
12602
+ if (styleSheet && styles) {
12603
+ if (supportsAdoptedStyleSheets) {
12604
+ styleSheet.replaceSync(styles);
12605
+ }
12606
+ else {
12607
+ styleSheet.textContent = styles;
12608
+ }
12609
+ }
12610
+ break;
12611
+ }
12612
+ }
12613
+ }
12614
+ // Convert property to attribute
12615
+ $propertyChangedCallback(name, oldValue, newValue) {
12616
+ if (Object.is(newValue, oldValue)) {
12617
+ return;
12618
+ }
12619
+ name = toKebabCase(name);
12620
+ switch (typeof newValue) {
12621
+ case 'boolean':
12622
+ if (newValue === true) {
12623
+ if (!this.hasAttribute(name)) {
12624
+ this.setAttribute(name, '');
12625
+ }
12626
+ }
12627
+ else {
12628
+ this.removeAttribute(name);
12629
+ }
12630
+ break;
12631
+ case 'number':
12632
+ if (isNaN$1(newValue)) {
12633
+ newValue = '';
12634
+ }
12635
+ else {
12636
+ newValue = String(newValue);
12637
+ }
12638
+ // Fall through
12639
+ // case 'string':
12640
+ // eslint-disable-next-line no-fallthrough
12641
+ default:
12642
+ if (newValue) {
12643
+ if (this.getAttribute(name) !== newValue) {
12644
+ this.setAttribute(name, newValue);
12645
+ }
12646
+ }
12647
+ else {
12648
+ this.removeAttribute(name);
12649
+ }
12650
+ }
12651
+ }
12652
+ connectedCallback() {
12653
+ // Observe properties after observed attributes
12654
+ Object.getPrototypeOf(this).constructor.observedAttributes.forEach((attribute) => {
12655
+ const property = toCamelCase(attribute);
12656
+ let value = this[property];
12657
+ if (!isUndefined(value)) {
12658
+ this.$propertyChangedCallback(property, undefined, value);
12659
+ }
12660
+ Object.defineProperty(this, property, {
12661
+ enumerable: true,
12662
+ configurable: true,
12663
+ get() {
12664
+ return value;
12665
+ },
12666
+ set(newValue) {
12667
+ const oldValue = value;
12668
+ value = newValue;
12669
+ this.$propertyChangedCallback(property, oldValue, newValue);
12670
+ },
12671
+ });
12672
+ });
12673
+ const shadow = this.attachShadow({
12674
+ mode: this.shadowRootMode || DEFAULT_SHADOW_ROOT_MODE,
12675
+ });
12676
+ if (!this.shadowRoot) {
12677
+ shadowRoots.set(this, shadow);
12678
+ }
12679
+ styleSheets.set(this, this.$addStyles(this.$sharedStyle));
12680
+ if (this.$style) {
12681
+ this.$addStyles(this.$style);
12682
+ }
12683
+ if (this.$template) {
12684
+ const template = document.createElement('template');
12685
+ template.innerHTML = this.$template;
12686
+ shadow.appendChild(template.content);
12687
+ }
12688
+ if (this.slottable) {
12689
+ const slot = document.createElement('slot');
12690
+ shadow.appendChild(slot);
12691
+ }
12692
+ }
12693
+ disconnectedCallback() {
12694
+ if (styleSheets.has(this)) {
12695
+ styleSheets.delete(this);
12696
+ }
12697
+ if (shadowRoots.has(this)) {
12698
+ shadowRoots.delete(this);
12699
+ }
12700
+ }
12701
+ // eslint-disable-next-line class-methods-use-this
12702
+ $getTagNameOf(name) {
12703
+ var _a;
12704
+ return (_a = tagNames.get(name)) !== null && _a !== void 0 ? _a : name;
12705
+ }
12706
+ $setStyles(properties) {
12707
+ Object.keys(properties).forEach((property) => {
12708
+ let value = properties[property];
12709
+ if (isNumber(value)) {
12710
+ if (value !== 0 && REGEXP_SUFFIX.test(property)) {
12711
+ value = `${value}px`;
12712
+ }
12713
+ else {
12714
+ value = String(value);
12715
+ }
12716
+ }
12717
+ this.style[property] = value;
12718
+ });
12719
+ return this;
12720
+ }
12721
+ /**
12722
+ * Outputs the shadow root of the element.
12723
+ * @returns {ShadowRoot} Returns the shadow root.
12724
+ */
12725
+ $getShadowRoot() {
12726
+ return this.shadowRoot || shadowRoots.get(this);
12727
+ }
12728
+ /**
12729
+ * Adds styles to the shadow root.
12730
+ * @param {string} styles The styles to add.
12731
+ * @returns {CSSStyleSheet|HTMLStyleElement} Returns the generated style sheet.
12732
+ */
12733
+ $addStyles(styles) {
12734
+ let styleSheet;
12735
+ const shadow = this.$getShadowRoot();
12736
+ if (supportsAdoptedStyleSheets) {
12737
+ styleSheet = new CSSStyleSheet();
12738
+ styleSheet.replaceSync(styles);
12739
+ shadow.adoptedStyleSheets = shadow.adoptedStyleSheets.concat(styleSheet);
12740
+ }
12741
+ else {
12742
+ styleSheet = document.createElement('style');
12743
+ styleSheet.textContent = styles;
12744
+ shadow.appendChild(styleSheet);
12745
+ }
12746
+ return styleSheet;
12747
+ }
12748
+ /**
12749
+ * Dispatches an event at the element.
12750
+ * @param {string} type The name of the event.
12751
+ * @param {*} [detail] The data passed when initializing the event.
12752
+ * @param {CustomEventInit} [options] The other event options.
12753
+ * @returns {boolean} Returns the result value.
12754
+ */
12755
+ $emit(type, detail, options) {
12756
+ return emit(this, type, detail, options);
12757
+ }
12758
+ /**
12759
+ * Defers the callback to be executed after the next DOM update cycle.
12760
+ * @param {Function} [callback] The callback to execute after the next DOM update cycle.
12761
+ * @returns {Promise} A promise that resolves to nothing.
12762
+ */
12763
+ $nextTick(callback) {
12764
+ return nextTick(this, callback);
12765
+ }
12766
+ /**
12767
+ * Defines the constructor as a new custom element.
12768
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define}
12769
+ * @param {string|object} [name] The element name.
12770
+ * @param {object} [options] The element definition options.
12771
+ */
12772
+ static $define(name, options) {
12773
+ if (isObject(name)) {
12774
+ options = name;
12775
+ name = '';
12776
+ }
12777
+ if (!name) {
12778
+ name = this.$name || this.name;
12779
+ }
12780
+ name = toKebabCase(name);
12781
+ if (IS_BROWSER && WINDOW.customElements && !WINDOW.customElements.get(name)) {
12782
+ customElements.define(name, this, options);
12783
+ }
12784
+ }
12785
+ }
12786
+ CropperElement.$version = '2.0.0-beta.4';
12787
+
12788
+ var style$7 = `:host{display:block;min-height:100px;min-width:200px;overflow:hidden;position:relative;touch-action:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}:host([background]){background-color:#fff;background-image:repeating-linear-gradient(45deg,#ccc 25%,transparent 0,transparent 75%,#ccc 0,#ccc),repeating-linear-gradient(45deg,#ccc 25%,transparent 0,transparent 75%,#ccc 0,#ccc);background-image:repeating-conic-gradient(#ccc 0 25%,#fff 0 50%);background-position:0 0,.5rem .5rem;background-size:1rem 1rem}:host([disabled]){pointer-events:none}:host([disabled]):after{bottom:0;content:"";cursor:not-allowed;display:block;left:0;pointer-events:none;position:absolute;right:0;top:0}`;
12789
+
12790
+ class CropperCanvas extends CropperElement {
12791
+ constructor() {
12792
+ super(...arguments);
12793
+ this.$onPointerDown = null;
12794
+ this.$onPointerMove = null;
12795
+ this.$onPointerUp = null;
12796
+ this.$onWheel = null;
12797
+ this.$wheeling = false;
12798
+ this.$pointers = new Map();
12799
+ this.$style = style$7;
12800
+ this.$action = ACTION_NONE;
12801
+ this.background = false;
12802
+ this.disabled = false;
12803
+ this.scaleStep = 0.1;
12804
+ this.themeColor = '#39f';
12805
+ }
12806
+ static get observedAttributes() {
12807
+ return super.observedAttributes.concat([
12808
+ 'background',
12809
+ 'disabled',
12810
+ 'scale-step',
12811
+ ]);
12812
+ }
12813
+ connectedCallback() {
12814
+ super.connectedCallback();
12815
+ if (!this.disabled) {
12816
+ this.$bind();
12817
+ }
12818
+ }
12819
+ disconnectedCallback() {
12820
+ if (!this.disabled) {
12821
+ this.$unbind();
12822
+ }
12823
+ super.disconnectedCallback();
12824
+ }
12825
+ $propertyChangedCallback(name, oldValue, newValue) {
12826
+ if (Object.is(newValue, oldValue)) {
12827
+ return;
12828
+ }
12829
+ super.$propertyChangedCallback(name, oldValue, newValue);
12830
+ switch (name) {
12831
+ case 'disabled':
12832
+ if (newValue) {
12833
+ this.$unbind();
12834
+ }
12835
+ else {
12836
+ this.$bind();
12837
+ }
12838
+ break;
12839
+ }
12840
+ }
12841
+ $bind() {
12842
+ if (!this.$onPointerDown) {
12843
+ this.$onPointerDown = this.$handlePointerDown.bind(this);
12844
+ on(this, EVENT_POINTER_DOWN, this.$onPointerDown);
12845
+ }
12846
+ if (!this.$onPointerMove) {
12847
+ this.$onPointerMove = this.$handlePointerMove.bind(this);
12848
+ on(this.ownerDocument, EVENT_POINTER_MOVE, this.$onPointerMove);
12849
+ }
12850
+ if (!this.$onPointerUp) {
12851
+ this.$onPointerUp = this.$handlePointerUp.bind(this);
12852
+ on(this.ownerDocument, EVENT_POINTER_UP, this.$onPointerUp);
12853
+ }
12854
+ if (!this.$onWheel) {
12855
+ this.$onWheel = this.$handleWheel.bind(this);
12856
+ on(this, EVENT_WHEEL, this.$onWheel, {
12857
+ passive: false,
12858
+ capture: true,
12859
+ });
12860
+ }
12861
+ }
12862
+ $unbind() {
12863
+ if (this.$onPointerDown) {
12864
+ off(this, EVENT_POINTER_DOWN, this.$onPointerDown);
12865
+ this.$onPointerDown = null;
12866
+ }
12867
+ if (this.$onPointerMove) {
12868
+ off(this.ownerDocument, EVENT_POINTER_MOVE, this.$onPointerMove);
12869
+ this.$onPointerMove = null;
12870
+ }
12871
+ if (this.$onPointerUp) {
12872
+ off(this.ownerDocument, EVENT_POINTER_UP, this.$onPointerUp);
12873
+ this.$onPointerUp = null;
12874
+ }
12875
+ if (this.$onWheel) {
12876
+ off(this, EVENT_WHEEL, this.$onWheel, {
12877
+ capture: true,
12878
+ });
12879
+ this.$onWheel = null;
12880
+ }
12881
+ }
12882
+ $handlePointerDown(event) {
12883
+ const { buttons, button, type } = event;
12884
+ if (this.disabled || (
12885
+ // Handle pointer or mouse event, and ignore touch event
12886
+ ((type === 'pointerdown' && event.pointerType === 'mouse') || type === 'mousedown') && (
12887
+ // No primary button (Usually the left button)
12888
+ (isNumber(buttons) && buttons !== 1) || (isNumber(button) && button !== 0)
12889
+ // Open context menu
12890
+ || event.ctrlKey))) {
12891
+ return;
12892
+ }
12893
+ const { $pointers } = this;
12894
+ let action = '';
12895
+ if (event.changedTouches) {
12896
+ Array.from(event.changedTouches).forEach(({ identifier, pageX, pageY, }) => {
12897
+ $pointers.set(identifier, {
12898
+ startX: pageX,
12899
+ startY: pageY,
12900
+ endX: pageX,
12901
+ endY: pageY,
12902
+ });
12903
+ });
12904
+ }
12905
+ else {
12906
+ const { pointerId = 0, pageX, pageY } = event;
12907
+ $pointers.set(pointerId, {
12908
+ startX: pageX,
12909
+ startY: pageY,
12910
+ endX: pageX,
12911
+ endY: pageY,
12912
+ });
12913
+ }
12914
+ if ($pointers.size > 1) {
12915
+ action = ACTION_TRANSFORM;
12916
+ }
12917
+ else if (isElement$1(event.target)) {
12918
+ action = event.target.action || event.target.getAttribute(ATTRIBUTE_ACTION) || '';
12919
+ }
12920
+ if (this.$emit(EVENT_ACTION_START, {
12921
+ action,
12922
+ relatedEvent: event,
12923
+ }) === false) {
12924
+ return;
12925
+ }
12926
+ // Prevent page zooming in the browsers for iOS.
12927
+ event.preventDefault();
12928
+ this.$action = action;
12929
+ this.style.willChange = 'transform';
12930
+ }
12931
+ $handlePointerMove(event) {
12932
+ const { $action, $pointers } = this;
12933
+ if (this.disabled || $action === ACTION_NONE || $pointers.size === 0) {
12934
+ return;
12935
+ }
12936
+ if (this.$emit(EVENT_ACTION_MOVE, {
12937
+ action: $action,
12938
+ relatedEvent: event,
12939
+ }) === false) {
12940
+ return;
12941
+ }
12942
+ // Prevent page scrolling.
12943
+ event.preventDefault();
12944
+ if (event.changedTouches) {
12945
+ Array.from(event.changedTouches).forEach(({ identifier, pageX, pageY, }) => {
12946
+ const pointer = $pointers.get(identifier);
12947
+ if (pointer) {
12948
+ Object.assign(pointer, {
12949
+ endX: pageX,
12950
+ endY: pageY,
12951
+ });
12952
+ }
12953
+ });
12954
+ }
12955
+ else {
12956
+ const { pointerId = 0, pageX, pageY } = event;
12957
+ const pointer = $pointers.get(pointerId);
12958
+ if (pointer) {
12959
+ Object.assign(pointer, {
12960
+ endX: pageX,
12961
+ endY: pageY,
12962
+ });
12963
+ }
12964
+ }
12965
+ const detail = {
12966
+ action: $action,
12967
+ relatedEvent: event,
12968
+ };
12969
+ if ($action === ACTION_TRANSFORM) {
12970
+ const pointers2 = new Map($pointers);
12971
+ let maxRotateRate = 0;
12972
+ let maxScaleRate = 0;
12973
+ let rotate = 0;
12974
+ let scale = 0;
12975
+ let centerX = event.pageX;
12976
+ let centerY = event.pageY;
12977
+ $pointers.forEach((pointer, pointerId) => {
12978
+ pointers2.delete(pointerId);
12979
+ pointers2.forEach((pointer2) => {
12980
+ let x1 = pointer2.startX - pointer.startX;
12981
+ let y1 = pointer2.startY - pointer.startY;
12982
+ let x2 = pointer2.endX - pointer.endX;
12983
+ let y2 = pointer2.endY - pointer.endY;
12984
+ let z1 = 0;
12985
+ let z2 = 0;
12986
+ let a1 = 0;
12987
+ let a2 = 0;
12988
+ if (x1 === 0) {
12989
+ if (y1 < 0) {
12990
+ a1 = Math.PI * 2;
12991
+ }
12992
+ else if (y1 > 0) {
12993
+ a1 = Math.PI;
12994
+ }
12995
+ }
12996
+ else if (x1 > 0) {
12997
+ a1 = (Math.PI / 2) + Math.atan(y1 / x1);
12998
+ }
12999
+ else if (x1 < 0) {
13000
+ a1 = (Math.PI * 1.5) + Math.atan(y1 / x1);
13001
+ }
13002
+ if (x2 === 0) {
13003
+ if (y2 < 0) {
13004
+ a2 = Math.PI * 2;
13005
+ }
13006
+ else if (y2 > 0) {
13007
+ a2 = Math.PI;
13008
+ }
13009
+ }
13010
+ else if (x2 > 0) {
13011
+ a2 = (Math.PI / 2) + Math.atan(y2 / x2);
13012
+ }
13013
+ else if (x2 < 0) {
13014
+ a2 = (Math.PI * 1.5) + Math.atan(y2 / x2);
13015
+ }
13016
+ if (a2 > 0 || a1 > 0) {
13017
+ const rotateRate = a2 - a1;
13018
+ const absRotateRate = Math.abs(rotateRate);
13019
+ if (absRotateRate > maxRotateRate) {
13020
+ maxRotateRate = absRotateRate;
13021
+ rotate = rotateRate;
13022
+ centerX = (pointer.startX + pointer2.startX) / 2;
13023
+ centerY = (pointer.startY + pointer2.startY) / 2;
13024
+ }
13025
+ }
13026
+ x1 = Math.abs(x1);
13027
+ y1 = Math.abs(y1);
13028
+ x2 = Math.abs(x2);
13029
+ y2 = Math.abs(y2);
13030
+ if (x1 > 0 && y1 > 0) {
13031
+ z1 = Math.sqrt((x1 * x1) + (y1 * y1));
13032
+ }
13033
+ else if (x1 > 0) {
13034
+ z1 = x1;
13035
+ }
13036
+ else if (y1 > 0) {
13037
+ z1 = y1;
13038
+ }
13039
+ if (x2 > 0 && y2 > 0) {
13040
+ z2 = Math.sqrt((x2 * x2) + (y2 * y2));
13041
+ }
13042
+ else if (x2 > 0) {
13043
+ z2 = x2;
13044
+ }
13045
+ else if (y2 > 0) {
13046
+ z2 = y2;
13047
+ }
13048
+ if (z1 > 0 && z2 > 0) {
13049
+ const scaleRate = (z2 - z1) / z1;
13050
+ const absScaleRate = Math.abs(scaleRate);
13051
+ if (absScaleRate > maxScaleRate) {
13052
+ maxScaleRate = absScaleRate;
13053
+ scale = scaleRate;
13054
+ centerX = (pointer.startX + pointer2.startX) / 2;
13055
+ centerY = (pointer.startY + pointer2.startY) / 2;
13056
+ }
13057
+ }
13058
+ });
13059
+ });
13060
+ const rotatable = maxRotateRate > 0;
13061
+ const scalable = maxScaleRate > 0;
13062
+ if (rotatable && scalable) {
13063
+ detail.rotate = rotate;
13064
+ detail.scale = scale;
13065
+ detail.centerX = centerX;
13066
+ detail.centerY = centerY;
13067
+ }
13068
+ else if (rotatable) {
13069
+ detail.action = ACTION_ROTATE;
13070
+ detail.rotate = rotate;
13071
+ detail.centerX = centerX;
13072
+ detail.centerY = centerY;
13073
+ }
13074
+ else if (scalable) {
13075
+ detail.action = ACTION_SCALE;
13076
+ detail.scale = scale;
13077
+ detail.centerX = centerX;
13078
+ detail.centerY = centerY;
13079
+ }
13080
+ else {
13081
+ detail.action = ACTION_NONE;
13082
+ }
13083
+ }
13084
+ else {
13085
+ const [pointer] = Array.from($pointers.values());
13086
+ Object.assign(detail, pointer);
13087
+ }
13088
+ // Override the starting coordinate
13089
+ $pointers.forEach((pointer) => {
13090
+ pointer.startX = pointer.endX;
13091
+ pointer.startY = pointer.endY;
13092
+ });
13093
+ if (detail.action !== ACTION_NONE) {
13094
+ this.$emit(EVENT_ACTION, detail, {
13095
+ cancelable: false,
13096
+ });
13097
+ }
13098
+ }
13099
+ $handlePointerUp(event) {
13100
+ const { $action, $pointers } = this;
13101
+ if (this.disabled || $action === ACTION_NONE) {
13102
+ return;
13103
+ }
13104
+ if (this.$emit(EVENT_ACTION_END, {
13105
+ action: $action,
13106
+ relatedEvent: event,
13107
+ }) === false) {
13108
+ return;
13109
+ }
13110
+ event.preventDefault();
13111
+ if (event.changedTouches) {
13112
+ Array.from(event.changedTouches).forEach(({ identifier, }) => {
13113
+ $pointers.delete(identifier);
13114
+ });
13115
+ }
13116
+ else {
13117
+ const { pointerId = 0 } = event;
13118
+ $pointers.delete(pointerId);
13119
+ }
13120
+ if ($pointers.size === 0) {
13121
+ this.style.willChange = '';
13122
+ this.$action = ACTION_NONE;
13123
+ }
13124
+ }
13125
+ $handleWheel(event) {
13126
+ if (this.disabled) {
13127
+ return;
13128
+ }
13129
+ event.preventDefault();
13130
+ // Limit wheel speed to prevent zoom too fast (#21)
13131
+ if (this.$wheeling) {
13132
+ return;
13133
+ }
13134
+ this.$wheeling = true;
13135
+ // Debounce by 50ms
13136
+ setTimeout(() => {
13137
+ this.$wheeling = false;
13138
+ }, 50);
13139
+ const delta = event.deltaY > 0 ? -1 : 1;
13140
+ const scale = delta * this.scaleStep;
13141
+ this.$emit(EVENT_ACTION, {
13142
+ action: ACTION_SCALE,
13143
+ scale,
13144
+ relatedEvent: event,
13145
+ }, {
13146
+ cancelable: false,
13147
+ });
13148
+ }
13149
+ /**
13150
+ * Changes the current action to a new one.
13151
+ * @param {string} action The new action.
13152
+ * @returns {CropperCanvas} Returns `this` for chaining.
13153
+ */
13154
+ $setAction(action) {
13155
+ if (isString(action)) {
13156
+ this.$action = action;
13157
+ }
13158
+ return this;
13159
+ }
13160
+ /**
13161
+ * Generates a real canvas element, with the image draw into if there is one.
13162
+ * @param {object} [options] The available options.
13163
+ * @param {number} [options.width] The width of the canvas.
13164
+ * @param {number} [options.height] The height of the canvas.
13165
+ * @param {Function} [options.beforeDraw] The function called before drawing the image onto the canvas.
13166
+ * @returns {Promise} Returns a promise that resolves to the generated canvas element.
13167
+ */
13168
+ $toCanvas(options) {
13169
+ return new Promise((resolve, reject) => {
13170
+ if (!this.isConnected) {
13171
+ reject(new Error('The current element is not connected to the DOM.'));
13172
+ return;
13173
+ }
13174
+ const canvas = document.createElement('canvas');
13175
+ let width = this.offsetWidth;
13176
+ let height = this.offsetHeight;
13177
+ let scale = 1;
13178
+ if (isPlainObject(options)
13179
+ && (isPositiveNumber(options.width) || isPositiveNumber(options.height))) {
13180
+ ({ width, height } = getAdjustedSizes({
13181
+ aspectRatio: width / height,
13182
+ width: options.width,
13183
+ height: options.height,
13184
+ }));
13185
+ scale = width / this.offsetWidth;
13186
+ }
13187
+ canvas.width = width;
13188
+ canvas.height = height;
13189
+ const cropperImage = this.querySelector(this.$getTagNameOf(CROPPER_IMAGE));
13190
+ if (!cropperImage) {
13191
+ resolve(canvas);
13192
+ return;
13193
+ }
13194
+ cropperImage.$ready().then((image) => {
13195
+ const context = canvas.getContext('2d');
13196
+ if (context) {
13197
+ const [a, b, c, d, e, f] = cropperImage.$getTransform();
13198
+ let newE = e;
13199
+ let newF = f;
13200
+ let destWidth = image.naturalWidth;
13201
+ let destHeight = image.naturalHeight;
13202
+ if (scale !== 1) {
13203
+ newE *= scale;
13204
+ newF *= scale;
13205
+ destWidth *= scale;
13206
+ destHeight *= scale;
13207
+ }
13208
+ const centerX = destWidth / 2;
13209
+ const centerY = destHeight / 2;
13210
+ context.fillStyle = 'transparent';
13211
+ context.fillRect(0, 0, width, height);
13212
+ if (isPlainObject(options) && isFunction$1(options.beforeDraw)) {
13213
+ options.beforeDraw.call(this, context, canvas);
13214
+ }
13215
+ context.save();
13216
+ // Move the transform origin to the center of the image.
13217
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin
13218
+ context.translate(centerX, centerY);
13219
+ context.transform(a, b, c, d, newE, newF);
13220
+ // Reset the transform origin to the top-left of the image.
13221
+ context.translate(-centerX, -centerY);
13222
+ context.drawImage(image, 0, 0, destWidth, destHeight);
13223
+ context.restore();
13224
+ }
13225
+ resolve(canvas);
13226
+ }).catch(reject);
13227
+ });
13228
+ }
13229
+ }
13230
+ CropperCanvas.$name = CROPPER_CANVAS;
13231
+ CropperCanvas.$version = '2.0.0-beta.4';
13232
+
13233
+ var style$6 = `:host{display:inline-block}img{display:block;height:100%;max-height:none!important;max-width:none!important;min-height:0!important;min-width:0!important;width:100%}`;
13234
+
13235
+ const canvasCache$2 = new WeakMap();
13236
+ const NATIVE_ATTRIBUTES = [
13237
+ 'alt',
13238
+ 'crossorigin',
13239
+ 'decoding',
13240
+ 'importance',
13241
+ 'loading',
13242
+ 'referrerpolicy',
13243
+ 'sizes',
13244
+ 'src',
13245
+ 'srcset',
13246
+ ];
13247
+ class CropperImage extends CropperElement {
13248
+ constructor() {
13249
+ super(...arguments);
13250
+ this.$matrix = [1, 0, 0, 1, 0, 0];
13251
+ this.$onLoad = null;
13252
+ this.$onCanvasAction = null;
13253
+ this.$onCanvasActionEnd = null;
13254
+ this.$onCanvasActionStart = null;
13255
+ this.$actionStartTarget = null;
13256
+ this.$style = style$6;
13257
+ this.$image = new Image();
13258
+ this.rotatable = true;
13259
+ this.scalable = true;
13260
+ this.skewable = true;
13261
+ this.slottable = false;
13262
+ this.translatable = true;
13263
+ }
13264
+ set $canvas(element) {
13265
+ canvasCache$2.set(this, element);
13266
+ }
13267
+ get $canvas() {
13268
+ return canvasCache$2.get(this);
13269
+ }
13270
+ static get observedAttributes() {
13271
+ return super.observedAttributes.concat(NATIVE_ATTRIBUTES, [
13272
+ 'rotatable',
13273
+ 'scalable',
13274
+ 'skewable',
13275
+ 'translatable',
13276
+ ]);
13277
+ }
13278
+ attributeChangedCallback(name, oldValue, newValue) {
13279
+ if (Object.is(newValue, oldValue)) {
13280
+ return;
13281
+ }
13282
+ super.attributeChangedCallback(name, oldValue, newValue);
13283
+ // Inherits the native attributes
13284
+ if (NATIVE_ATTRIBUTES.includes(name)) {
13285
+ this.$image.setAttribute(name, newValue);
13286
+ }
13287
+ }
13288
+ connectedCallback() {
13289
+ super.connectedCallback();
13290
+ const { $image } = this;
13291
+ const $canvas = this.closest(this.$getTagNameOf(CROPPER_CANVAS));
13292
+ if ($canvas) {
13293
+ this.$canvas = $canvas;
13294
+ this.$setStyles({
13295
+ // Make it a block element to avoid side effects (#1074).
13296
+ display: 'block',
13297
+ position: 'absolute',
13298
+ });
13299
+ this.$onCanvasActionStart = (event) => {
13300
+ var _a, _b;
13301
+ this.$actionStartTarget = (_b = (_a = event.detail) === null || _a === void 0 ? void 0 : _a.relatedEvent) === null || _b === void 0 ? void 0 : _b.target;
13302
+ };
13303
+ this.$onCanvasActionEnd = () => {
13304
+ this.$actionStartTarget = null;
13305
+ };
13306
+ this.$onCanvasAction = this.$handleAction.bind(this);
13307
+ on($canvas, EVENT_ACTION_START, this.$onCanvasActionStart);
13308
+ on($canvas, EVENT_ACTION_END, this.$onCanvasActionEnd);
13309
+ on($canvas, EVENT_ACTION, this.$onCanvasAction);
13310
+ }
13311
+ this.$onLoad = this.$handleLoad.bind(this);
13312
+ on($image, EVENT_LOAD, this.$onLoad);
13313
+ this.$getShadowRoot().appendChild($image);
13314
+ }
13315
+ disconnectedCallback() {
13316
+ const { $image, $canvas } = this;
13317
+ if ($canvas) {
13318
+ if (this.$onCanvasActionStart) {
13319
+ off($canvas, EVENT_ACTION_START, this.$onCanvasActionStart);
13320
+ this.$onCanvasActionStart = null;
13321
+ }
13322
+ if (this.$onCanvasActionEnd) {
13323
+ off($canvas, EVENT_ACTION_END, this.$onCanvasActionEnd);
13324
+ this.$onCanvasActionEnd = null;
13325
+ }
13326
+ if (this.$onCanvasAction) {
13327
+ off($canvas, EVENT_ACTION, this.$onCanvasAction);
13328
+ this.$onCanvasAction = null;
13329
+ }
13330
+ }
13331
+ if ($image && this.$onLoad) {
13332
+ off($image, EVENT_LOAD, this.$onLoad);
13333
+ this.$onLoad = null;
13334
+ }
13335
+ this.$getShadowRoot().removeChild($image);
13336
+ super.disconnectedCallback();
13337
+ }
13338
+ $handleLoad() {
13339
+ const { $image } = this;
13340
+ this.$setStyles({
13341
+ width: $image.naturalWidth,
13342
+ height: $image.naturalHeight,
13343
+ });
13344
+ if (this.$canvas) {
13345
+ this.$center('cover');
13346
+ }
13347
+ }
13348
+ $handleAction(event) {
13349
+ if (this.hidden || !(this.rotatable || this.scalable || this.translatable)) {
13350
+ return;
13351
+ }
13352
+ const { $canvas } = this;
13353
+ const { detail } = event;
13354
+ if (detail) {
13355
+ const { relatedEvent } = detail;
13356
+ let { action } = detail;
13357
+ if (action === ACTION_TRANSFORM && (!this.rotatable || !this.scalable)) {
13358
+ if (this.rotatable) {
13359
+ action = ACTION_ROTATE;
13360
+ }
13361
+ else if (this.scalable) {
13362
+ action = ACTION_SCALE;
13363
+ }
13364
+ else {
13365
+ action = ACTION_NONE;
13366
+ }
13367
+ }
13368
+ switch (action) {
13369
+ case ACTION_MOVE:
13370
+ if (this.translatable) {
13371
+ const cropperSelectionTagName = this.$getTagNameOf(CROPPER_SELECTION);
13372
+ let selection = $canvas.querySelector(cropperSelectionTagName);
13373
+ if (selection && selection.multiple && !selection.active) {
13374
+ selection = $canvas.querySelector(`${cropperSelectionTagName}[active]`);
13375
+ }
13376
+ if (!selection || selection.hidden || !selection.movable
13377
+ || !(this.$actionStartTarget && selection.contains(this.$actionStartTarget))) {
13378
+ this.$move(detail.endX - detail.startX, detail.endY - detail.startY);
13379
+ }
13380
+ }
13381
+ break;
13382
+ case ACTION_ROTATE:
13383
+ if (this.rotatable) {
13384
+ if (relatedEvent) {
13385
+ const { x, y } = this.getBoundingClientRect();
13386
+ this.$rotate(detail.rotate, relatedEvent.clientX - x, relatedEvent.clientY - y);
13387
+ }
13388
+ else {
13389
+ this.$rotate(detail.rotate);
13390
+ }
13391
+ }
13392
+ break;
13393
+ case ACTION_SCALE:
13394
+ if (this.scalable) {
13395
+ if (relatedEvent) {
13396
+ const { x, y } = this.getBoundingClientRect();
13397
+ this.$zoom(detail.scale, relatedEvent.clientX - x, relatedEvent.clientY - y);
13398
+ }
13399
+ else {
13400
+ this.$zoom(detail.scale);
13401
+ }
13402
+ }
13403
+ break;
13404
+ case ACTION_TRANSFORM:
13405
+ if (this.rotatable && this.scalable) {
13406
+ const { rotate } = detail;
13407
+ let { scale } = detail;
13408
+ if (scale < 0) {
13409
+ scale = 1 / (1 - scale);
13410
+ }
13411
+ else {
13412
+ scale += 1;
13413
+ }
13414
+ const cos = Math.cos(rotate);
13415
+ const sin = Math.sin(rotate);
13416
+ const [scaleX, skewY, skewX, scaleY] = [
13417
+ cos * scale,
13418
+ sin * scale,
13419
+ -sin * scale,
13420
+ cos * scale,
13421
+ ];
13422
+ if (relatedEvent) {
13423
+ const clientRect = this.getBoundingClientRect();
13424
+ const x = relatedEvent.clientX - clientRect.x;
13425
+ const y = relatedEvent.clientY - clientRect.y;
13426
+ const [a, b, c, d] = this.$matrix;
13427
+ const originX = clientRect.width / 2;
13428
+ const originY = clientRect.height / 2;
13429
+ const moveX = x - originX;
13430
+ const moveY = y - originY;
13431
+ const translateX = ((moveX * d) - (c * moveY)) / ((a * d) - (c * b));
13432
+ const translateY = (moveY - (b * translateX)) / d;
13433
+ /**
13434
+ * Equals to
13435
+ * this.$rotate(rotate, x, y);
13436
+ * this.$scale(scale, x, y);
13437
+ */
13438
+ this.$transform(scaleX, skewY, skewX, scaleY, translateX * (1 - scaleX) + translateY * skewX, translateY * (1 - scaleY) + translateX * skewY);
13439
+ }
13440
+ else {
13441
+ /**
13442
+ * Equals to
13443
+ * this.$rotate(rotate);
13444
+ * this.$scale(scale);
13445
+ */
13446
+ this.$transform(scaleX, skewY, skewX, scaleY, 0, 0);
13447
+ }
13448
+ }
13449
+ break;
13450
+ }
13451
+ }
13452
+ }
13453
+ /**
13454
+ * Defers the callback to execute after successfully loading the image.
13455
+ * @param {Function} [callback] The callback to execute after successfully loading the image.
13456
+ * @returns {Promise} Returns a promise that resolves to the image element.
13457
+ */
13458
+ $ready(callback) {
13459
+ const { $image } = this;
13460
+ const promise = new Promise((resolve, reject) => {
13461
+ const error = new Error('Failed to load the image source');
13462
+ if ($image.complete) {
13463
+ if ($image.naturalWidth > 0 && $image.naturalHeight > 0) {
13464
+ resolve($image);
13465
+ }
13466
+ else {
13467
+ reject(error);
13468
+ }
13469
+ }
13470
+ else {
13471
+ const onLoad = () => {
13472
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
13473
+ off($image, EVENT_ERROR, onError);
13474
+ resolve($image);
13475
+ };
13476
+ const onError = () => {
13477
+ off($image, EVENT_LOAD, onLoad);
13478
+ reject(error);
13479
+ };
13480
+ once($image, EVENT_LOAD, onLoad);
13481
+ once($image, EVENT_ERROR, onError);
13482
+ }
13483
+ });
13484
+ if (isFunction$1(callback)) {
13485
+ promise.then((image) => {
13486
+ callback(image);
13487
+ return image;
13488
+ });
13489
+ }
13490
+ return promise;
13491
+ }
13492
+ /**
13493
+ * Aligns the image to the center of its parent element.
13494
+ * @param {string} [size] The size of the image.
13495
+ * @returns {CropperImage} Returns `this` for chaining.
13496
+ */
13497
+ $center(size) {
13498
+ const { parentElement } = this;
13499
+ if (!parentElement) {
13500
+ return this;
13501
+ }
13502
+ const container = parentElement.getBoundingClientRect();
13503
+ const containerWidth = container.width;
13504
+ const containerHeight = container.height;
13505
+ const { x, y, width, height, } = this.getBoundingClientRect();
13506
+ const startX = x + (width / 2);
13507
+ const startY = y + (height / 2);
13508
+ const endX = container.x + (containerWidth / 2);
13509
+ const endY = container.y + (containerHeight / 2);
13510
+ this.$move(endX - startX, endY - startY);
13511
+ if (size && (width !== containerWidth || height !== containerHeight)) {
13512
+ const scaleX = containerWidth / width;
13513
+ const scaleY = containerHeight / height;
13514
+ switch (size) {
13515
+ case 'cover':
13516
+ this.$scale(Math.max(scaleX, scaleY));
13517
+ break;
13518
+ case 'contain':
13519
+ this.$scale(Math.min(scaleX, scaleY));
13520
+ break;
13521
+ }
13522
+ }
13523
+ return this;
13524
+ }
13525
+ /**
13526
+ * Moves the image.
13527
+ * @param {number} x The moving distance in the horizontal direction.
13528
+ * @param {number} [y] The moving distance in the vertical direction.
13529
+ * @returns {CropperImage} Returns `this` for chaining.
13530
+ */
13531
+ $move(x, y = x) {
13532
+ if (this.translatable && isNumber(x) && isNumber(y)) {
13533
+ const [a, b, c, d] = this.$matrix;
13534
+ const e = ((x * d) - (c * y)) / ((a * d) - (c * b));
13535
+ const f = (y - (b * e)) / d;
13536
+ this.$translate(e, f);
13537
+ }
13538
+ return this;
13539
+ }
13540
+ /**
13541
+ * Moves the image to a specific position.
13542
+ * @param {number} x The new position in the horizontal direction.
13543
+ * @param {number} [y] The new position in the vertical direction.
13544
+ * @returns {CropperImage} Returns `this` for chaining.
13545
+ */
13546
+ $moveTo(x, y = x) {
13547
+ if (this.translatable && isNumber(x) && isNumber(y)) {
13548
+ const [a, b, c, d] = this.$matrix;
13549
+ const e = ((x * d) - (c * y)) / ((a * d) - (c * b));
13550
+ const f = (y - (b * e)) / d;
13551
+ this.$setTransform(a, b, c, d, e, f);
13552
+ }
13553
+ return this;
13554
+ }
13555
+ /**
13556
+ * Rotates the image.
13557
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotate}
13558
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/rotate}
13559
+ * @param {number|string} angle The rotation angle (in radians).
13560
+ * @param {number} [x] The rotation origin in the horizontal, defaults to the center of the image.
13561
+ * @param {number} [y] The rotation origin in the vertical, defaults to the center of the image.
13562
+ * @returns {CropperImage} Returns `this` for chaining.
13563
+ */
13564
+ $rotate(angle, x, y) {
13565
+ if (this.rotatable) {
13566
+ const radian = toAngleInRadian(angle);
13567
+ const cos = Math.cos(radian);
13568
+ const sin = Math.sin(radian);
13569
+ const [scaleX, skewY, skewX, scaleY] = [cos, sin, -sin, cos];
13570
+ if (isNumber(x) && isNumber(y)) {
13571
+ const [a, b, c, d] = this.$matrix;
13572
+ const { width, height } = this.getBoundingClientRect();
13573
+ const originX = width / 2;
13574
+ const originY = height / 2;
13575
+ const moveX = x - originX;
13576
+ const moveY = y - originY;
13577
+ const translateX = ((moveX * d) - (c * moveY)) / ((a * d) - (c * b));
13578
+ const translateY = (moveY - (b * translateX)) / d;
13579
+ /**
13580
+ * Equals to
13581
+ * this.$translate(translateX, translateX);
13582
+ * this.$rotate(angle);
13583
+ * this.$translate(-translateX, -translateX);
13584
+ */
13585
+ this.$transform(scaleX, skewY, skewX, scaleY, translateX * (1 - scaleX) - translateY * skewX, translateY * (1 - scaleY) - translateX * skewY);
13586
+ }
13587
+ else {
13588
+ this.$transform(scaleX, skewY, skewX, scaleY, 0, 0);
13589
+ }
13590
+ }
13591
+ return this;
13592
+ }
13593
+ /**
13594
+ * Zooms the image.
13595
+ * @param {number} scale The zoom factor. Positive numbers for zooming in, and negative numbers for zooming out.
13596
+ * @param {number} [x] The zoom origin in the horizontal, defaults to the center of the image.
13597
+ * @param {number} [y] The zoom origin in the vertical, defaults to the center of the image.
13598
+ * @returns {CropperImage} Returns `this` for chaining.
13599
+ */
13600
+ $zoom(scale, x, y) {
13601
+ if (!this.scalable || scale === 0) {
13602
+ return this;
13603
+ }
13604
+ if (scale < 0) {
13605
+ scale = 1 / (1 - scale);
13606
+ }
13607
+ else {
13608
+ scale += 1;
13609
+ }
13610
+ if (isNumber(x) && isNumber(y)) {
13611
+ const [a, b, c, d] = this.$matrix;
13612
+ const { width, height } = this.getBoundingClientRect();
13613
+ const originX = width / 2;
13614
+ const originY = height / 2;
13615
+ const moveX = x - originX;
13616
+ const moveY = y - originY;
13617
+ const translateX = ((moveX * d) - (c * moveY)) / ((a * d) - (c * b));
13618
+ const translateY = (moveY - (b * translateX)) / d;
13619
+ /**
13620
+ * Equals to
13621
+ * this.$translate(translateX, translateX);
13622
+ * this.$scale(scale);
13623
+ * this.$translate(-translateX, -translateX);
13624
+ */
13625
+ this.$transform(scale, 0, 0, scale, translateX * (1 - scale), translateY * (1 - scale));
13626
+ }
13627
+ else {
13628
+ this.$scale(scale);
13629
+ }
13630
+ return this;
13631
+ }
13632
+ /**
13633
+ * Scales the image.
13634
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/scale}
13635
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/scale}
13636
+ * @param {number} x The scaling factor in the horizontal direction.
13637
+ * @param {number} [y] The scaling factor in the vertical direction.
13638
+ * @returns {CropperImage} Returns `this` for chaining.
13639
+ */
13640
+ $scale(x, y = x) {
13641
+ if (this.scalable) {
13642
+ this.$transform(x, 0, 0, y, 0, 0);
13643
+ }
13644
+ return this;
13645
+ }
13646
+ /**
13647
+ * Skews the image.
13648
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/skew}
13649
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/transform}
13650
+ * @param {number|string} x The skewing angle in the horizontal direction.
13651
+ * @param {number|string} [y] The skewing angle in the vertical direction.
13652
+ * @returns {CropperImage} Returns `this` for chaining.
13653
+ */
13654
+ $skew(x, y = 0) {
13655
+ if (this.skewable) {
13656
+ const radianX = toAngleInRadian(x);
13657
+ const radianY = toAngleInRadian(y);
13658
+ this.$transform(1, Math.tan(radianY), Math.tan(radianX), 1, 0, 0);
13659
+ }
13660
+ return this;
13661
+ }
13662
+ /**
13663
+ * Translates the image.
13664
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/translate}
13665
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/translate}
13666
+ * @param {number} x The translating distance in the horizontal direction.
13667
+ * @param {number} [y] The translating distance in the vertical direction.
13668
+ * @returns {CropperImage} Returns `this` for chaining.
13669
+ */
13670
+ $translate(x, y = x) {
13671
+ if (this.translatable && isNumber(x) && isNumber(y)) {
13672
+ this.$transform(1, 0, 0, 1, x, y);
13673
+ }
13674
+ return this;
13675
+ }
13676
+ /**
13677
+ * Transforms the image.
13678
+ * {@link https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix}
13679
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/transform}
13680
+ * @param {number} a The scaling factor in the horizontal direction.
13681
+ * @param {number} b The skewing angle in the vertical direction.
13682
+ * @param {number} c The skewing angle in the horizontal direction.
13683
+ * @param {number} d The scaling factor in the vertical direction.
13684
+ * @param {number} e The translating distance in the horizontal direction.
13685
+ * @param {number} f The translating distance in the vertical direction.
13686
+ * @returns {CropperImage} Returns `this` for chaining.
13687
+ */
13688
+ $transform(a, b, c, d, e, f) {
13689
+ if (isNumber(a)
13690
+ && isNumber(b)
13691
+ && isNumber(c)
13692
+ && isNumber(d)
13693
+ && isNumber(e)
13694
+ && isNumber(f)) {
13695
+ return this.$setTransform(multiplyMatrices(this.$matrix, [a, b, c, d, e, f]));
13696
+ }
13697
+ return this;
13698
+ }
13699
+ /**
13700
+ * Resets (overrides) the current transform to the specific identity matrix.
13701
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setTransform}
13702
+ * @param {number|Array} a The scaling factor in the horizontal direction.
13703
+ * @param {number} b The skewing angle in the vertical direction.
13704
+ * @param {number} c The skewing angle in the horizontal direction.
13705
+ * @param {number} d The scaling factor in the vertical direction.
13706
+ * @param {number} e The translating distance in the horizontal direction.
13707
+ * @param {number} f The translating distance in the vertical direction.
13708
+ * @returns {CropperImage} Returns `this` for chaining.
13709
+ */
13710
+ $setTransform(a, b, c, d, e, f) {
13711
+ if (this.rotatable || this.scalable || this.skewable || this.translatable) {
13712
+ if (Array.isArray(a)) {
13713
+ [a, b, c, d, e, f] = a;
13714
+ }
13715
+ if (isNumber(a)
13716
+ && isNumber(b)
13717
+ && isNumber(c)
13718
+ && isNumber(d)
13719
+ && isNumber(e)
13720
+ && isNumber(f)) {
13721
+ const newMatrix = [a, b, c, d, e, f];
13722
+ if (this.$emit(EVENT_TRANSFORM, {
13723
+ matrix: newMatrix,
13724
+ oldMatrix: this.$matrix,
13725
+ }) === false) {
13726
+ return this;
13727
+ }
13728
+ this.$matrix = newMatrix;
13729
+ this.style.transform = `matrix(${newMatrix.join(', ')})`;
13730
+ }
13731
+ }
13732
+ return this;
13733
+ }
13734
+ /**
13735
+ * Retrieves the current transformation matrix being applied to the element.
13736
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getTransform}
13737
+ * @returns {Array} Returns the readonly transformation matrix.
13738
+ */
13739
+ $getTransform() {
13740
+ return this.$matrix.slice();
13741
+ }
13742
+ /**
13743
+ * Resets the current transform to the initial identity matrix.
13744
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/resetTransform}
13745
+ * @returns {CropperImage} Returns `this` for chaining.
13746
+ */
13747
+ $resetTransform() {
13748
+ return this.$setTransform([1, 0, 0, 1, 0, 0]);
13749
+ }
13750
+ }
13751
+ CropperImage.$name = CROPPER_IMAGE;
13752
+ CropperImage.$version = '2.0.0-beta.4';
13753
+
13754
+ var style$5 = `:host{display:block;height:0;left:0;outline:var(--theme-color) solid 1px;position:relative;top:0;width:0}:host([transparent]){outline-color:transparent}`;
13755
+
13756
+ const canvasCache$1 = new WeakMap();
13757
+ class CropperShade extends CropperElement {
13758
+ constructor() {
13759
+ super(...arguments);
13760
+ this.$onCanvasChange = null;
13761
+ this.$onCanvasActionEnd = null;
13762
+ this.$onCanvasActionStart = null;
13763
+ this.$style = style$5;
13764
+ this.x = 0;
13765
+ this.y = 0;
13766
+ this.width = 0;
13767
+ this.height = 0;
13768
+ this.slottable = false;
13769
+ this.themeColor = 'rgba(0, 0, 0, 0.65)';
13770
+ }
13771
+ set $canvas(element) {
13772
+ canvasCache$1.set(this, element);
13773
+ }
13774
+ get $canvas() {
13775
+ return canvasCache$1.get(this);
13776
+ }
13777
+ static get observedAttributes() {
13778
+ return super.observedAttributes.concat([
13779
+ 'height',
13780
+ 'width',
13781
+ 'x',
13782
+ 'y',
13783
+ ]);
13784
+ }
13785
+ connectedCallback() {
13786
+ super.connectedCallback();
13787
+ const $canvas = this.closest(this.$getTagNameOf(CROPPER_CANVAS));
13788
+ if ($canvas) {
13789
+ this.$canvas = $canvas;
13790
+ this.style.position = 'absolute';
13791
+ const $selection = $canvas.querySelector(this.$getTagNameOf(CROPPER_SELECTION));
13792
+ if ($selection) {
13793
+ this.$onCanvasActionStart = (event) => {
13794
+ if ($selection.hidden && event.detail.action === ACTION_SELECT) {
13795
+ this.hidden = false;
13796
+ }
13797
+ };
13798
+ this.$onCanvasActionEnd = (event) => {
13799
+ if ($selection.hidden && event.detail.action === ACTION_SELECT) {
13800
+ this.hidden = true;
13801
+ }
13802
+ };
13803
+ this.$onCanvasChange = (event) => {
13804
+ const { x, y, width, height, } = event.detail;
13805
+ this.$change(x, y, width, height);
13806
+ if ($selection.hidden || (x === 0 && y === 0 && width === 0 && height === 0)) {
13807
+ this.hidden = true;
13808
+ }
13809
+ };
13810
+ on($canvas, EVENT_ACTION_START, this.$onCanvasActionStart);
13811
+ on($canvas, EVENT_ACTION_END, this.$onCanvasActionEnd);
13812
+ on($canvas, EVENT_CHANGE, this.$onCanvasChange);
13813
+ }
13814
+ }
13815
+ this.$render();
13816
+ }
13817
+ disconnectedCallback() {
13818
+ const { $canvas } = this;
13819
+ if ($canvas) {
13820
+ if (this.$onCanvasActionStart) {
13821
+ off($canvas, EVENT_ACTION_START, this.$onCanvasActionStart);
13822
+ this.$onCanvasActionStart = null;
13823
+ }
13824
+ if (this.$onCanvasActionEnd) {
13825
+ off($canvas, EVENT_ACTION_END, this.$onCanvasActionEnd);
13826
+ this.$onCanvasActionEnd = null;
13827
+ }
13828
+ if (this.$onCanvasChange) {
13829
+ off($canvas, EVENT_CHANGE, this.$onCanvasChange);
13830
+ this.$onCanvasChange = null;
13831
+ }
13832
+ }
13833
+ super.disconnectedCallback();
13834
+ }
13835
+ /**
13836
+ * Changes the position and/or size of the shade.
13837
+ * @param {number} x The new position in the horizontal direction.
13838
+ * @param {number} y The new position in the vertical direction.
13839
+ * @param {number} [width] The new width.
13840
+ * @param {number} [height] The new height.
13841
+ * @returns {CropperShade} Returns `this` for chaining.
13842
+ */
13843
+ $change(x, y, width = this.width, height = this.height) {
13844
+ if (!isNumber(x)
13845
+ || !isNumber(y)
13846
+ || !isNumber(width)
13847
+ || !isNumber(height)
13848
+ || (x === this.x && y === this.y && width === this.width && height === this.height)) {
13849
+ return this;
13850
+ }
13851
+ if (this.hidden) {
13852
+ this.hidden = false;
13853
+ }
13854
+ this.x = x;
13855
+ this.y = y;
13856
+ this.width = width;
13857
+ this.height = height;
13858
+ return this.$render();
13859
+ }
13860
+ /**
13861
+ * Resets the shade to its initial position and size.
13862
+ * @returns {CropperShade} Returns `this` for chaining.
13863
+ */
13864
+ $reset() {
13865
+ return this.$change(0, 0, 0, 0);
13866
+ }
13867
+ /**
13868
+ * Refreshes the position or size of the shade.
13869
+ * @returns {CropperShade} Returns `this` for chaining.
13870
+ */
13871
+ $render() {
13872
+ return this.$setStyles({
13873
+ transform: `translate(${this.x}px, ${this.y}px)`,
13874
+ width: this.width,
13875
+ height: this.height,
13876
+ outlineWidth: WINDOW.innerWidth,
13877
+ });
13878
+ }
13879
+ }
13880
+ CropperShade.$name = CROPPER_SHADE;
13881
+ CropperShade.$version = '2.0.0-beta.4';
13882
+
13883
+ var style$4 = `:host{background-color:var(--theme-color);display:block}:host([action=move]),:host([action=select]){height:100%;left:0;position:absolute;top:0;width:100%}:host([action=move]){cursor:move}:host([action=select]){cursor:crosshair}:host([action$=-resize]){background-color:transparent;height:15px;position:absolute;width:15px}:host([action$=-resize]):after{background-color:var(--theme-color);content:"";display:block;height:5px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%);width:5px}:host([action=n-resize]),:host([action=s-resize]){cursor:ns-resize;left:50%;transform:translateX(-50%);width:100%}:host([action=n-resize]){top:-8px}:host([action=s-resize]){bottom:-8px}:host([action=e-resize]),:host([action=w-resize]){cursor:ew-resize;height:100%;top:50%;transform:translateY(-50%)}:host([action=e-resize]){right:-8px}:host([action=w-resize]){left:-8px}:host([action=ne-resize]){cursor:nesw-resize;right:-8px;top:-8px}:host([action=nw-resize]){cursor:nwse-resize;left:-8px;top:-8px}:host([action=se-resize]){bottom:-8px;cursor:nwse-resize;right:-8px}:host([action=se-resize]):after{height:15px;width:15px}@media (pointer:coarse){:host([action=se-resize]):after{height:10px;width:10px}}@media (pointer:fine){:host([action=se-resize]):after{height:5px;width:5px}}:host([action=sw-resize]){bottom:-8px;cursor:nesw-resize;left:-8px}:host([plain]){background-color:transparent}`;
13884
+
13885
+ class CropperHandle extends CropperElement {
13886
+ constructor() {
13887
+ super(...arguments);
13888
+ this.$onCanvasCropEnd = null;
13889
+ this.$onCanvasCropStart = null;
13890
+ this.$style = style$4;
13891
+ this.action = ACTION_NONE;
13892
+ this.plain = false;
13893
+ this.slottable = false;
13894
+ this.themeColor = 'rgba(51, 153, 255, 0.5)';
13895
+ }
13896
+ static get observedAttributes() {
13897
+ return super.observedAttributes.concat([
13898
+ 'action',
13899
+ 'plain',
13900
+ ]);
13901
+ }
13902
+ }
13903
+ CropperHandle.$name = CROPPER_HANDLE;
13904
+ CropperHandle.$version = '2.0.0-beta.4';
13905
+
13906
+ var style$3 = `:host{display:block;left:0;position:relative;right:0}:host([outlined]){outline:1px solid var(--theme-color)}:host([multiple]){outline:1px dashed hsla(0,0%,100%,.5)}:host([multiple]):after{bottom:0;content:"";cursor:pointer;display:block;left:0;position:absolute;right:0;top:0}:host([multiple][active]){outline-color:var(--theme-color);z-index:1}:host([multiple])>*{visibility:hidden}:host([multiple][active])>*{visibility:visible}:host([multiple][active]):after{display:none}`;
13907
+
13908
+ const canvasCache = new WeakMap();
13909
+ class CropperSelection extends CropperElement {
13910
+ constructor() {
13911
+ super(...arguments);
13912
+ this.$onCanvasAction = null;
13913
+ this.$onCanvasActionStart = null;
13914
+ this.$onCanvasActionEnd = null;
13915
+ this.$onDocumentKeyDown = null;
13916
+ this.$action = '';
13917
+ this.$actionStartTarget = null;
13918
+ this.$style = style$3;
13919
+ this.x = 0;
13920
+ this.y = 0;
13921
+ this.width = 0;
13922
+ this.height = 0;
13923
+ this.aspectRatio = NaN;
13924
+ this.initialAspectRatio = NaN;
13925
+ this.initialCoverage = NaN;
13926
+ this.active = false;
13927
+ this.movable = false;
13928
+ this.resizable = false;
13929
+ this.zoomable = false;
13930
+ this.multiple = false;
13931
+ this.keyboard = false;
13932
+ this.outlined = false;
13933
+ this.precise = false;
13934
+ }
13935
+ set $canvas(element) {
13936
+ canvasCache.set(this, element);
13937
+ }
13938
+ get $canvas() {
13939
+ return canvasCache.get(this);
13940
+ }
13941
+ static get observedAttributes() {
13942
+ return super.observedAttributes.concat([
13943
+ 'active',
13944
+ 'aspect-ratio',
13945
+ 'height',
13946
+ 'initial-aspect-ratio',
13947
+ 'initial-coverage',
13948
+ 'keyboard',
13949
+ 'movable',
13950
+ 'multiple',
13951
+ 'outlined',
13952
+ 'precise',
13953
+ 'resizable',
13954
+ 'width',
13955
+ 'x',
13956
+ 'y',
13957
+ 'zoomable',
13958
+ ]);
13959
+ }
13960
+ $propertyChangedCallback(name, oldValue, newValue) {
13961
+ if (Object.is(newValue, oldValue)) {
13962
+ return;
13963
+ }
13964
+ super.$propertyChangedCallback(name, oldValue, newValue);
13965
+ switch (name) {
13966
+ case 'aspectRatio':
13967
+ if (!isPositiveNumber(newValue)) {
13968
+ this.aspectRatio = NaN;
13969
+ }
13970
+ break;
13971
+ case 'initialAspectRatio':
13972
+ if (!isPositiveNumber(newValue)) {
13973
+ this.initialAspectRatio = NaN;
13974
+ }
13975
+ break;
13976
+ case 'initialCoverage':
13977
+ if (!isPositiveNumber(newValue) || newValue > 1) {
13978
+ this.initialCoverage = NaN;
13979
+ }
13980
+ break;
13981
+ case 'keyboard':
13982
+ this.$nextTick(() => {
13983
+ if (this.$canvas) {
13984
+ if (newValue) {
13985
+ if (!this.$onDocumentKeyDown) {
13986
+ this.$onDocumentKeyDown = this.$handleKeyDown.bind(this);
13987
+ on(this.ownerDocument, EVENT_KEYDOWN, this.$onDocumentKeyDown);
13988
+ }
13989
+ }
13990
+ else if (this.$onDocumentKeyDown) {
13991
+ off(this.ownerDocument, EVENT_KEYDOWN, this.$onDocumentKeyDown);
13992
+ this.$onDocumentKeyDown = null;
13993
+ }
13994
+ }
13995
+ });
13996
+ break;
13997
+ case 'multiple':
13998
+ this.$nextTick(() => {
13999
+ if (this.$canvas) {
14000
+ const selections = this.$getSelections();
14001
+ if (newValue) {
14002
+ selections.forEach((selection) => {
14003
+ selection.active = false;
14004
+ });
14005
+ this.active = true;
14006
+ this.$emit(EVENT_CHANGE, {
14007
+ x: this.x,
14008
+ y: this.y,
14009
+ width: this.width,
14010
+ height: this.height,
14011
+ });
14012
+ }
14013
+ else {
14014
+ this.active = false;
14015
+ selections.slice(1).forEach((selection) => {
14016
+ this.$removeSelection(selection);
14017
+ });
14018
+ }
14019
+ }
14020
+ });
14021
+ break;
14022
+ }
14023
+ }
14024
+ connectedCallback() {
14025
+ super.connectedCallback();
14026
+ const $canvas = this.closest(this.$getTagNameOf(CROPPER_CANVAS));
14027
+ if ($canvas) {
14028
+ this.$canvas = $canvas;
14029
+ this.$setStyles({
14030
+ position: 'absolute',
14031
+ transform: `translate(${this.x}px, ${this.y}px)`,
14032
+ });
14033
+ if (!this.hidden) {
14034
+ this.$render();
14035
+ }
14036
+ const { initialCoverage, parentElement } = this;
14037
+ if (isPositiveNumber(initialCoverage) && parentElement) {
14038
+ const aspectRatio = this.aspectRatio || this.initialAspectRatio;
14039
+ const { offsetWidth, offsetHeight } = parentElement;
14040
+ let width = offsetWidth * initialCoverage;
14041
+ let height = offsetHeight * initialCoverage;
14042
+ if (isPositiveNumber(aspectRatio)) {
14043
+ ({ width, height } = getAdjustedSizes({ aspectRatio, width, height }));
14044
+ }
14045
+ this.$change(this.x, this.y, width, height);
14046
+ this.$center();
14047
+ }
14048
+ this.$onCanvasActionStart = this.$handleActionStart.bind(this);
14049
+ this.$onCanvasActionEnd = this.$handleActionEnd.bind(this);
14050
+ this.$onCanvasAction = this.$handleAction.bind(this);
14051
+ on($canvas, EVENT_ACTION_START, this.$onCanvasActionStart);
14052
+ on($canvas, EVENT_ACTION_END, this.$onCanvasActionStart);
14053
+ on($canvas, EVENT_ACTION, this.$onCanvasAction);
14054
+ }
14055
+ else {
14056
+ this.$render();
14057
+ }
14058
+ }
14059
+ disconnectedCallback() {
14060
+ const { $canvas } = this;
14061
+ if ($canvas) {
14062
+ if (this.$onCanvasActionStart) {
14063
+ off($canvas, EVENT_ACTION_START, this.$onCanvasActionStart);
14064
+ this.$onCanvasActionStart = null;
14065
+ }
14066
+ if (this.$onCanvasActionEnd) {
14067
+ off($canvas, EVENT_ACTION_END, this.$onCanvasActionEnd);
14068
+ this.$onCanvasActionEnd = null;
14069
+ }
14070
+ if (this.$onCanvasAction) {
14071
+ off($canvas, EVENT_ACTION, this.$onCanvasAction);
14072
+ this.$onCanvasAction = null;
14073
+ }
14074
+ }
14075
+ super.disconnectedCallback();
14076
+ }
14077
+ $getSelections() {
14078
+ let selections = [];
14079
+ if (this.parentElement) {
14080
+ selections = Array.from(this.parentElement.querySelectorAll(this.$getTagNameOf(CROPPER_SELECTION)));
14081
+ }
14082
+ return selections;
14083
+ }
14084
+ $createSelection() {
14085
+ const newSelection = this.cloneNode(true);
14086
+ if (this.hasAttribute('id')) {
14087
+ newSelection.removeAttribute('id');
14088
+ }
14089
+ this.active = false;
14090
+ if (this.parentElement) {
14091
+ this.parentElement.insertBefore(newSelection, this.nextSibling);
14092
+ }
14093
+ return newSelection;
14094
+ }
14095
+ $removeSelection(selection = this) {
14096
+ if (this.parentElement) {
14097
+ const selections = this.$getSelections();
14098
+ if (selections.length > 1) {
14099
+ const index = selections.indexOf(selection);
14100
+ const activeSelection = selections[index + 1] || selections[index - 1];
14101
+ if (activeSelection) {
14102
+ selection.active = false;
14103
+ this.parentElement.removeChild(selection);
14104
+ activeSelection.active = true;
14105
+ activeSelection.$emit(EVENT_CHANGE, {
14106
+ x: activeSelection.x,
14107
+ y: activeSelection.y,
14108
+ width: activeSelection.width,
14109
+ height: activeSelection.height,
14110
+ });
14111
+ }
14112
+ }
14113
+ else {
14114
+ this.$reset();
14115
+ this.hidden = true;
14116
+ }
14117
+ }
14118
+ }
14119
+ $handleActionStart(event) {
14120
+ var _a, _b;
14121
+ const relatedTarget = (_b = (_a = event.detail) === null || _a === void 0 ? void 0 : _a.relatedEvent) === null || _b === void 0 ? void 0 : _b.target;
14122
+ this.$action = '';
14123
+ this.$actionStartTarget = relatedTarget;
14124
+ if (!this.hidden
14125
+ && this.multiple
14126
+ && !this.active
14127
+ && relatedTarget === this
14128
+ && this.parentElement) {
14129
+ this.$getSelections().forEach((selection) => {
14130
+ selection.active = false;
14131
+ });
14132
+ this.active = true;
14133
+ this.$emit(EVENT_CHANGE, {
14134
+ x: this.x,
14135
+ y: this.y,
14136
+ width: this.width,
14137
+ height: this.height,
14138
+ });
14139
+ }
14140
+ }
14141
+ $handleAction(event) {
14142
+ const { currentTarget, detail } = event;
14143
+ if (currentTarget && detail) {
14144
+ const { relatedEvent } = detail;
14145
+ let { action } = detail;
14146
+ // Switching to another selection
14147
+ if (!action && this.multiple) {
14148
+ // Get the `action` property from the focusing in selection
14149
+ action = this.$action || (relatedEvent === null || relatedEvent === void 0 ? void 0 : relatedEvent.target.action);
14150
+ this.$action = action;
14151
+ }
14152
+ if (!action
14153
+ || (this.hidden && action !== ACTION_SELECT)
14154
+ || (this.multiple && !this.active && action !== ACTION_SCALE)) {
14155
+ return;
14156
+ }
14157
+ const moveX = detail.endX - detail.startX;
14158
+ const moveY = detail.endY - detail.startY;
14159
+ const { width, height } = this;
14160
+ let { aspectRatio } = this;
14161
+ // Locking aspect ratio by holding shift key
14162
+ if (!isPositiveNumber(aspectRatio) && event.shiftKey) {
14163
+ aspectRatio = isPositiveNumber(width) && isPositiveNumber(height) ? width / height : 1;
14164
+ }
14165
+ switch (action) {
14166
+ case ACTION_SELECT: {
14167
+ const { $canvas } = this;
14168
+ const offset = getOffset(currentTarget);
14169
+ (this.multiple && !this.hidden ? this.$createSelection() : this).$change(detail.startX - offset.left, detail.startY - offset.top, moveX, moveY, aspectRatio);
14170
+ action = ACTION_RESIZE_SOUTHEAST;
14171
+ if (moveX < 0) {
14172
+ if (moveY > 0) {
14173
+ action = ACTION_RESIZE_SOUTHWEST;
14174
+ }
14175
+ else if (moveY < 0) {
14176
+ action = ACTION_RESIZE_NORTHWEST;
14177
+ }
14178
+ }
14179
+ else if (moveX > 0) {
14180
+ if (moveY < 0) {
14181
+ action = ACTION_RESIZE_NORTHEAST;
14182
+ }
14183
+ }
14184
+ if ($canvas) {
14185
+ $canvas.$action = action;
14186
+ }
14187
+ break;
14188
+ }
14189
+ case ACTION_MOVE:
14190
+ if (this.movable
14191
+ && (this.$actionStartTarget && this.contains(this.$actionStartTarget))) {
14192
+ this.$move(moveX, moveY);
14193
+ }
14194
+ break;
14195
+ case ACTION_SCALE:
14196
+ if (relatedEvent && this.zoomable) {
14197
+ const offset = getOffset(currentTarget);
14198
+ this.$zoom(detail.scale, relatedEvent.pageX - offset.left, relatedEvent.pageY - offset.top);
14199
+ }
14200
+ break;
14201
+ default:
14202
+ this.$resize(action, moveX, moveY, aspectRatio);
14203
+ }
14204
+ }
14205
+ }
14206
+ $handleActionEnd() {
14207
+ this.$action = '';
14208
+ this.$actionStartTarget = null;
14209
+ }
14210
+ $handleKeyDown(event) {
14211
+ if (this.hidden
14212
+ || !this.keyboard
14213
+ || (this.multiple && !this.active)
14214
+ || event.defaultPrevented) {
14215
+ return;
14216
+ }
14217
+ switch (event.key) {
14218
+ case 'Backspace':
14219
+ if (event.metaKey) {
14220
+ event.preventDefault();
14221
+ this.$removeSelection();
14222
+ }
14223
+ break;
14224
+ case 'Delete':
14225
+ event.preventDefault();
14226
+ this.$removeSelection();
14227
+ break;
14228
+ // Move to the left
14229
+ case 'ArrowLeft':
14230
+ event.preventDefault();
14231
+ this.$move(-1, 0);
14232
+ break;
14233
+ // Move to the right
14234
+ case 'ArrowRight':
14235
+ event.preventDefault();
14236
+ this.$move(1, 0);
14237
+ break;
14238
+ // Move to the top
14239
+ case 'ArrowUp':
14240
+ event.preventDefault();
14241
+ this.$move(0, -1);
14242
+ break;
14243
+ // Move to the bottom
14244
+ case 'ArrowDown':
14245
+ event.preventDefault();
14246
+ this.$move(0, 1);
14247
+ break;
14248
+ case '+':
14249
+ event.preventDefault();
14250
+ this.$zoom(0.1);
14251
+ break;
14252
+ case '-':
14253
+ event.preventDefault();
14254
+ this.$zoom(-0.1);
14255
+ break;
14256
+ }
14257
+ }
14258
+ /**
14259
+ * Aligns the selection to the center of its parent element.
14260
+ * @returns {CropperSelection} Returns `this` for chaining.
14261
+ */
14262
+ $center() {
14263
+ const { parentElement } = this;
14264
+ if (!parentElement) {
14265
+ return this;
14266
+ }
14267
+ const x = (parentElement.offsetWidth - this.width) / 2;
14268
+ const y = (parentElement.offsetHeight - this.height) / 2;
14269
+ return this.$change(x, y);
14270
+ }
14271
+ /**
14272
+ * Moves the selection.
14273
+ * @param {number} x The moving distance in the horizontal direction.
14274
+ * @param {number} [y] The moving distance in the vertical direction.
14275
+ * @returns {CropperSelection} Returns `this` for chaining.
14276
+ */
14277
+ $move(x, y = x) {
14278
+ return this.$moveTo(this.x + x, this.y + y);
14279
+ }
14280
+ /**
14281
+ * Moves the selection to a specific position.
14282
+ * @param {number} x The new position in the horizontal direction.
14283
+ * @param {number} [y] The new position in the vertical direction.
14284
+ * @returns {CropperSelection} Returns `this` for chaining.
14285
+ */
14286
+ $moveTo(x, y = x) {
14287
+ if (!this.movable) {
14288
+ return this;
14289
+ }
14290
+ return this.$change(x, y);
14291
+ }
14292
+ /**
14293
+ * Adjusts the size the selection on a specific side or corner.
14294
+ * @param {string} action Indicates the side or corner to resize.
14295
+ * @param {number} [offsetX] The horizontal offset of the specific side or corner.
14296
+ * @param {number} [offsetY] The vertical offset of the specific side or corner.
14297
+ * @param {number} [aspectRatio] The aspect ratio for computing the new size if it is necessary.
14298
+ * @returns {CropperSelection} Returns `this` for chaining.
14299
+ */
14300
+ $resize(action, offsetX = 0, offsetY = 0, aspectRatio = this.aspectRatio) {
14301
+ if (!this.resizable) {
14302
+ return this;
14303
+ }
14304
+ const hasValidAspectRatio = isPositiveNumber(aspectRatio);
14305
+ const { $canvas } = this;
14306
+ let { x, y, width, height, } = this;
14307
+ switch (action) {
14308
+ case ACTION_RESIZE_NORTH:
14309
+ y += offsetY;
14310
+ height -= offsetY;
14311
+ if (height < 0) {
14312
+ action = ACTION_RESIZE_SOUTH;
14313
+ height = -height;
14314
+ y -= height;
14315
+ }
14316
+ if (hasValidAspectRatio) {
14317
+ offsetX = offsetY * aspectRatio;
14318
+ x += offsetX / 2;
14319
+ width -= offsetX;
14320
+ if (width < 0) {
14321
+ width = -width;
14322
+ x -= width;
14323
+ }
14324
+ }
14325
+ break;
14326
+ case ACTION_RESIZE_EAST:
14327
+ width += offsetX;
14328
+ if (width < 0) {
14329
+ action = ACTION_RESIZE_WEST;
14330
+ width = -width;
14331
+ x -= width;
14332
+ }
14333
+ if (hasValidAspectRatio) {
14334
+ offsetY = offsetX / aspectRatio;
14335
+ y -= offsetY / 2;
14336
+ height += offsetY;
14337
+ if (height < 0) {
14338
+ height = -height;
14339
+ y -= height;
14340
+ }
14341
+ }
14342
+ break;
14343
+ case ACTION_RESIZE_SOUTH:
14344
+ height += offsetY;
14345
+ if (height < 0) {
14346
+ action = ACTION_RESIZE_NORTH;
14347
+ height = -height;
14348
+ y -= height;
14349
+ }
14350
+ if (hasValidAspectRatio) {
14351
+ offsetX = offsetY * aspectRatio;
14352
+ x -= offsetX / 2;
14353
+ width += offsetX;
14354
+ if (width < 0) {
14355
+ width = -width;
14356
+ x -= width;
14357
+ }
14358
+ }
14359
+ break;
14360
+ case ACTION_RESIZE_WEST:
14361
+ x += offsetX;
14362
+ width -= offsetX;
14363
+ if (width < 0) {
14364
+ action = ACTION_RESIZE_EAST;
14365
+ width = -width;
14366
+ x -= width;
14367
+ }
14368
+ if (hasValidAspectRatio) {
14369
+ offsetY = offsetX / aspectRatio;
14370
+ y += offsetY / 2;
14371
+ height -= offsetY;
14372
+ if (height < 0) {
14373
+ height = -height;
14374
+ y -= height;
14375
+ }
14376
+ }
14377
+ break;
14378
+ case ACTION_RESIZE_NORTHEAST:
14379
+ if (hasValidAspectRatio) {
14380
+ offsetY = -offsetX / aspectRatio;
14381
+ }
14382
+ y += offsetY;
14383
+ height -= offsetY;
14384
+ width += offsetX;
14385
+ if (width < 0 && height < 0) {
14386
+ action = ACTION_RESIZE_SOUTHWEST;
14387
+ width = -width;
14388
+ height = -height;
14389
+ x -= width;
14390
+ y -= height;
14391
+ }
14392
+ else if (width < 0) {
14393
+ action = ACTION_RESIZE_NORTHWEST;
14394
+ width = -width;
14395
+ x -= width;
14396
+ }
14397
+ else if (height < 0) {
14398
+ action = ACTION_RESIZE_SOUTHEAST;
14399
+ height = -height;
14400
+ y -= height;
14401
+ }
14402
+ break;
14403
+ case ACTION_RESIZE_NORTHWEST:
14404
+ if (hasValidAspectRatio) {
14405
+ offsetY = offsetX / aspectRatio;
14406
+ }
14407
+ x += offsetX;
14408
+ y += offsetY;
14409
+ width -= offsetX;
14410
+ height -= offsetY;
14411
+ if (width < 0 && height < 0) {
14412
+ action = ACTION_RESIZE_SOUTHEAST;
14413
+ width = -width;
14414
+ height = -height;
14415
+ x -= width;
14416
+ y -= height;
14417
+ }
14418
+ else if (width < 0) {
14419
+ action = ACTION_RESIZE_NORTHEAST;
14420
+ width = -width;
14421
+ x -= width;
14422
+ }
14423
+ else if (height < 0) {
14424
+ action = ACTION_RESIZE_SOUTHWEST;
14425
+ height = -height;
14426
+ y -= height;
14427
+ }
14428
+ break;
14429
+ case ACTION_RESIZE_SOUTHEAST:
14430
+ if (hasValidAspectRatio) {
14431
+ offsetY = offsetX / aspectRatio;
14432
+ }
14433
+ width += offsetX;
14434
+ height += offsetY;
14435
+ if (width < 0 && height < 0) {
14436
+ action = ACTION_RESIZE_NORTHWEST;
14437
+ width = -width;
14438
+ height = -height;
14439
+ x -= width;
14440
+ y -= height;
14441
+ }
14442
+ else if (width < 0) {
14443
+ action = ACTION_RESIZE_SOUTHWEST;
14444
+ width = -width;
14445
+ x -= width;
14446
+ }
14447
+ else if (height < 0) {
14448
+ action = ACTION_RESIZE_NORTHEAST;
14449
+ height = -height;
14450
+ y -= height;
14451
+ }
14452
+ break;
14453
+ case ACTION_RESIZE_SOUTHWEST:
14454
+ if (hasValidAspectRatio) {
14455
+ offsetY = -offsetX / aspectRatio;
14456
+ }
14457
+ x += offsetX;
14458
+ width -= offsetX;
14459
+ height += offsetY;
14460
+ if (width < 0 && height < 0) {
14461
+ action = ACTION_RESIZE_NORTHEAST;
14462
+ width = -width;
14463
+ height = -height;
14464
+ x -= width;
14465
+ y -= height;
14466
+ }
14467
+ else if (width < 0) {
14468
+ action = ACTION_RESIZE_SOUTHEAST;
14469
+ width = -width;
14470
+ x -= width;
14471
+ }
14472
+ else if (height < 0) {
14473
+ action = ACTION_RESIZE_NORTHWEST;
14474
+ height = -height;
14475
+ y -= height;
14476
+ }
14477
+ break;
14478
+ }
14479
+ if ($canvas) {
14480
+ $canvas.$setAction(action);
14481
+ }
14482
+ return this.$change(x, y, width, height);
14483
+ }
14484
+ /**
14485
+ * Zooms the selection.
14486
+ * @param {number} scale The zoom factor. Positive numbers for zooming in, and negative numbers for zooming out.
14487
+ * @param {number} [x] The zoom origin in the horizontal, defaults to the center of the selection.
14488
+ * @param {number} [y] The zoom origin in the vertical, defaults to the center of the selection.
14489
+ * @returns {CropperSelection} Returns `this` for chaining.
14490
+ */
14491
+ $zoom(scale, x, y) {
14492
+ if (!this.zoomable || scale === 0) {
14493
+ return this;
14494
+ }
14495
+ if (scale < 0) {
14496
+ scale = 1 / (1 - scale);
14497
+ }
14498
+ else {
14499
+ scale += 1;
14500
+ }
14501
+ const { width, height } = this;
14502
+ const newWidth = width * scale;
14503
+ const newHeight = height * scale;
14504
+ let newX = this.x;
14505
+ let newY = this.y;
14506
+ if (isNumber(x) && isNumber(y)) {
14507
+ newX -= (newWidth - width) * ((x - this.x) / width);
14508
+ newY -= (newHeight - height) * ((y - this.y) / height);
14509
+ }
14510
+ else {
14511
+ // Zoom from the center of the selection
14512
+ newX -= (newWidth - width) / 2;
14513
+ newY -= (newHeight - height) / 2;
14514
+ }
14515
+ return this.$change(newX, newY, newWidth, newHeight);
14516
+ }
14517
+ /**
14518
+ * Changes the position and/or size of the selection.
14519
+ * @param {number} x The new position in the horizontal direction.
14520
+ * @param {number} y The new position in the vertical direction.
14521
+ * @param {number} [width] The new width.
14522
+ * @param {number} [height] The new height.
14523
+ * @param {number} [aspectRatio] The new aspect ratio for this change only.
14524
+ * @returns {CropperSelection} Returns `this` for chaining.
14525
+ */
14526
+ $change(x, y, width = this.width, height = this.height, aspectRatio = this.aspectRatio) {
14527
+ if (!isNumber(x) || !isNumber(y) || !isNumber(width) || !isNumber(height)) {
14528
+ return this;
14529
+ }
14530
+ if (!this.precise) {
14531
+ x = Math.round(x);
14532
+ y = Math.round(y);
14533
+ width = Math.round(width);
14534
+ height = Math.round(height);
14535
+ }
14536
+ if (x === this.x && y === this.y && width === this.width && height === this.height) {
14537
+ return this;
14538
+ }
14539
+ if (this.hidden) {
14540
+ this.hidden = false;
14541
+ }
14542
+ if (isPositiveNumber(aspectRatio)) {
14543
+ ({ width, height } = getAdjustedSizes({ aspectRatio, width, height }, 'cover'));
14544
+ }
14545
+ if (this.$emit(EVENT_CHANGE, {
14546
+ x,
14547
+ y,
14548
+ width,
14549
+ height,
14550
+ }) === false) {
14551
+ return this;
14552
+ }
14553
+ this.x = x;
14554
+ this.y = y;
14555
+ this.width = width;
14556
+ this.height = height;
14557
+ return this.$render();
14558
+ }
14559
+ /**
14560
+ * Resets the selection to its initial position and size.
14561
+ * @returns {CropperSelection} Returns `this` for chaining.
14562
+ */
14563
+ $reset() {
14564
+ return this.$change(0, 0, 0, 0);
14565
+ }
14566
+ /**
14567
+ * Refreshes the position or size of the selection.
14568
+ * @returns {CropperSelection} Returns `this` for chaining.
14569
+ */
14570
+ $render() {
14571
+ return this.$setStyles({
14572
+ transform: `translate(${this.x}px, ${this.y}px)`,
14573
+ width: this.width,
14574
+ height: this.height,
14575
+ });
14576
+ }
14577
+ /**
14578
+ * Generates a real canvas element, with the image (selected area only) draw into if there is one.
14579
+ * @param {object} [options] The available options.
14580
+ * @param {number} [options.width] The width of the canvas.
14581
+ * @param {number} [options.height] The height of the canvas.
14582
+ * @param {Function} [options.beforeDraw] The function called before drawing the image onto the canvas.
14583
+ * @returns {Promise} Returns a promise that resolves to the generated canvas element.
14584
+ */
14585
+ $toCanvas(options) {
14586
+ return new Promise((resolve, reject) => {
14587
+ if (!this.isConnected) {
14588
+ reject(new Error('The current element is not connected to the DOM.'));
14589
+ return;
14590
+ }
14591
+ const canvas = document.createElement('canvas');
14592
+ let { width, height } = this;
14593
+ let scale = 1;
14594
+ if (isPlainObject(options)
14595
+ && (isPositiveNumber(options.width) || isPositiveNumber(options.height))) {
14596
+ ({ width, height } = getAdjustedSizes({
14597
+ aspectRatio: width / height,
14598
+ width: options.width,
14599
+ height: options.height,
14600
+ }));
14601
+ scale = width / this.width;
14602
+ }
14603
+ canvas.width = width;
14604
+ canvas.height = height;
14605
+ if (!this.$canvas) {
14606
+ resolve(canvas);
14607
+ return;
14608
+ }
14609
+ const cropperImage = this.$canvas.querySelector(this.$getTagNameOf(CROPPER_IMAGE));
14610
+ if (!cropperImage) {
14611
+ resolve(canvas);
14612
+ return;
14613
+ }
14614
+ cropperImage.$ready().then((image) => {
14615
+ const context = canvas.getContext('2d');
14616
+ if (context) {
14617
+ const [a, b, c, d, e, f] = cropperImage.$getTransform();
14618
+ const offsetX = -this.x;
14619
+ const offsetY = -this.y;
14620
+ const translateX = ((offsetX * d) - (c * offsetY)) / ((a * d) - (c * b));
14621
+ const translateY = (offsetY - (b * translateX)) / d;
14622
+ let newE = a * translateX + c * translateY + e;
14623
+ let newF = b * translateX + d * translateY + f;
14624
+ let destWidth = image.naturalWidth;
14625
+ let destHeight = image.naturalHeight;
14626
+ if (scale !== 1) {
14627
+ newE *= scale;
14628
+ newF *= scale;
14629
+ destWidth *= scale;
14630
+ destHeight *= scale;
14631
+ }
14632
+ const centerX = destWidth / 2;
14633
+ const centerY = destHeight / 2;
14634
+ context.fillStyle = 'transparent';
14635
+ context.fillRect(0, 0, width, height);
14636
+ if (isPlainObject(options) && isFunction$1(options.beforeDraw)) {
14637
+ options.beforeDraw.call(this, context, canvas);
14638
+ }
14639
+ context.save();
14640
+ // Move the transform origin to the center of the image.
14641
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/transform-origin
14642
+ context.translate(centerX, centerY);
14643
+ context.transform(a, b, c, d, newE, newF);
14644
+ // Move the transform origin to the top-left of the image.
14645
+ context.translate(-centerX, -centerY);
14646
+ context.drawImage(image, 0, 0, destWidth, destHeight);
14647
+ context.restore();
14648
+ }
14649
+ resolve(canvas);
14650
+ }).catch(reject);
14651
+ });
14652
+ }
14653
+ }
14654
+ CropperSelection.$name = CROPPER_SELECTION;
14655
+ CropperSelection.$version = '2.0.0-beta.4';
14656
+
14657
+ var style$2 = `:host{display:flex;flex-direction:column;position:relative;touch-action:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}:host([bordered]){border:1px dashed var(--theme-color)}:host([covered]){bottom:0;left:0;position:absolute;right:0;top:0}:host>span{display:flex;flex:1}:host>span+span{border-top:1px dashed var(--theme-color)}:host>span>span{flex:1}:host>span>span+span{border-left:1px dashed var(--theme-color)}`;
14658
+
14659
+ class CropperGrid extends CropperElement {
14660
+ constructor() {
14661
+ super(...arguments);
14662
+ this.$style = style$2;
14663
+ this.bordered = false;
14664
+ this.columns = 3;
14665
+ this.covered = false;
14666
+ this.rows = 3;
14667
+ this.slottable = false;
14668
+ this.themeColor = 'rgba(238, 238, 238, 0.5)';
14669
+ }
14670
+ static get observedAttributes() {
14671
+ return super.observedAttributes.concat([
14672
+ 'bordered',
14673
+ 'columns',
14674
+ 'covered',
14675
+ 'rows',
14676
+ ]);
14677
+ }
14678
+ $propertyChangedCallback(name, oldValue, newValue) {
14679
+ if (Object.is(newValue, oldValue)) {
14680
+ return;
14681
+ }
14682
+ super.$propertyChangedCallback(name, oldValue, newValue);
14683
+ if (name === 'rows' || name === 'columns') {
14684
+ this.$render();
14685
+ }
14686
+ }
14687
+ connectedCallback() {
14688
+ super.connectedCallback();
14689
+ this.$render();
14690
+ }
14691
+ $render() {
14692
+ const shadow = this.$getShadowRoot();
14693
+ const fragment = document.createDocumentFragment();
14694
+ for (let i = 0; i < this.rows; i += 1) {
14695
+ const row = document.createElement('span');
14696
+ row.setAttribute('role', 'row');
14697
+ for (let j = 0; j < this.columns; j += 1) {
14698
+ const column = document.createElement('span');
14699
+ column.setAttribute('role', 'gridcell');
14700
+ row.appendChild(column);
14701
+ }
14702
+ fragment.appendChild(row);
14703
+ }
14704
+ if (shadow) {
14705
+ shadow.innerHTML = '';
14706
+ shadow.appendChild(fragment);
14707
+ }
14708
+ }
14709
+ }
14710
+ CropperGrid.$name = CROPPER_GIRD;
14711
+ CropperGrid.$version = '2.0.0-beta.4';
14712
+
14713
+ var style$1 = `:host{display:inline-block;height:1em;position:relative;touch-action:none;-webkit-user-select:none;-moz-user-select:none;user-select:none;vertical-align:middle;width:1em}:host:after,:host:before{background-color:var(--theme-color);content:"";display:block;position:absolute}:host:before{height:1px;left:0;top:50%;transform:translateY(-50%);width:100%}:host:after{height:100%;left:50%;top:0;transform:translateX(-50%);width:1px}:host([centered]){left:50%;position:absolute;top:50%;transform:translate(-50%,-50%)}`;
14714
+
14715
+ class CropperCrosshair extends CropperElement {
14716
+ constructor() {
14717
+ super(...arguments);
14718
+ this.$style = style$1;
14719
+ this.centered = false;
14720
+ this.slottable = false;
14721
+ this.themeColor = 'rgba(238, 238, 238, 0.5)';
14722
+ }
14723
+ static get observedAttributes() {
14724
+ return super.observedAttributes.concat([
14725
+ 'centered',
14726
+ ]);
14727
+ }
14728
+ }
14729
+ CropperCrosshair.$name = CROPPER_CROSSHAIR;
14730
+ CropperCrosshair.$version = '2.0.0-beta.4';
14731
+
14732
+ var style = `:host{display:block;height:100%;overflow:hidden;position:relative;width:100%}`;
14733
+
14734
+ const imageCache = new WeakMap();
14735
+ const selectionCache = new WeakMap();
14736
+ const sourceImageCache = new WeakMap();
14737
+ const RESIZE_BOTH = 'both';
14738
+ const RESIZE_HORIZONTAL = 'horizontal';
14739
+ const RESIZE_VERTICAL = 'vertical';
14740
+ const RESIZE_NONE = 'none';
14741
+ class CropperViewer extends CropperElement {
14742
+ constructor() {
14743
+ super(...arguments);
14744
+ this.$onSelectionChange = null;
14745
+ this.$onSourceImageLoad = null;
14746
+ this.$onSourceImageTransform = null;
14747
+ this.$scale = 1;
14748
+ this.$style = style;
14749
+ this.resize = RESIZE_VERTICAL;
14750
+ this.selection = '';
14751
+ this.slottable = false;
14752
+ }
14753
+ set $image(element) {
14754
+ imageCache.set(this, element);
14755
+ }
14756
+ get $image() {
14757
+ return imageCache.get(this);
14758
+ }
14759
+ set $sourceImage(element) {
14760
+ sourceImageCache.set(this, element);
14761
+ }
14762
+ get $sourceImage() {
14763
+ return sourceImageCache.get(this);
14764
+ }
14765
+ set $selection(element) {
14766
+ selectionCache.set(this, element);
14767
+ }
14768
+ get $selection() {
14769
+ return selectionCache.get(this);
14770
+ }
14771
+ static get observedAttributes() {
14772
+ return super.observedAttributes.concat([
14773
+ 'resize',
14774
+ 'selection',
14775
+ ]);
14776
+ }
14777
+ connectedCallback() {
14778
+ super.connectedCallback();
14779
+ let $selection = null;
14780
+ if (this.selection) {
14781
+ $selection = this.ownerDocument.querySelector(this.selection);
14782
+ }
14783
+ else {
14784
+ $selection = this.closest(this.$getTagNameOf(CROPPER_SELECTION));
14785
+ }
14786
+ if (isElement$1($selection)) {
14787
+ this.$selection = $selection;
14788
+ this.$onSelectionChange = this.$handleSelectionChange.bind(this);
14789
+ on($selection, EVENT_CHANGE, this.$onSelectionChange);
14790
+ const $canvas = $selection.closest(this.$getTagNameOf(CROPPER_CANVAS));
14791
+ if ($canvas) {
14792
+ const $sourceImage = $canvas.querySelector(this.$getTagNameOf(CROPPER_IMAGE));
14793
+ if ($sourceImage) {
14794
+ this.$sourceImage = $sourceImage;
14795
+ this.$image = $sourceImage.cloneNode(true);
14796
+ this.$getShadowRoot().appendChild(this.$image);
14797
+ this.$onSourceImageLoad = this.$handleSourceImageLoad.bind(this);
14798
+ this.$onSourceImageTransform = this.$handleSourceImageTransform.bind(this);
14799
+ on($sourceImage.$image, EVENT_LOAD, this.$onSourceImageLoad);
14800
+ on($sourceImage, EVENT_TRANSFORM, this.$onSourceImageTransform);
14801
+ }
14802
+ }
14803
+ this.$render();
14804
+ }
14805
+ }
14806
+ disconnectedCallback() {
14807
+ const { $selection, $sourceImage } = this;
14808
+ if ($selection && this.$onSelectionChange) {
14809
+ off($selection, EVENT_CHANGE, this.$onSelectionChange);
14810
+ this.$onSelectionChange = null;
14811
+ }
14812
+ if ($sourceImage && this.$onSourceImageLoad) {
14813
+ off($sourceImage.$image, EVENT_LOAD, this.$onSourceImageLoad);
14814
+ this.$onSourceImageLoad = null;
14815
+ }
14816
+ if ($sourceImage && this.$onSourceImageTransform) {
14817
+ off($sourceImage, EVENT_TRANSFORM, this.$onSourceImageTransform);
14818
+ this.$onSourceImageTransform = null;
14819
+ }
14820
+ super.disconnectedCallback();
14821
+ }
14822
+ $handleSelectionChange(event) {
14823
+ this.$render(event.detail);
14824
+ }
14825
+ $handleSourceImageLoad() {
14826
+ const { $image, $sourceImage } = this;
14827
+ const oldSrc = $image.getAttribute('src');
14828
+ const newSrc = $sourceImage.getAttribute('src');
14829
+ if (newSrc && newSrc !== oldSrc) {
14830
+ $image.setAttribute('src', newSrc);
14831
+ $image.$ready(() => {
14832
+ setTimeout(() => {
14833
+ const { x, y } = this.$selection;
14834
+ this.$transformImageByOffset($sourceImage.$getTransform(), -x, -y);
14835
+ });
14836
+ });
14837
+ }
14838
+ }
14839
+ $handleSourceImageTransform(event) {
14840
+ const { x, y } = this.$selection;
14841
+ this.$transformImageByOffset(event.detail.matrix, -x, -y);
14842
+ }
14843
+ $render(selection) {
14844
+ const { x, y, width, height, } = selection || this.$selection;
14845
+ const styles = {};
14846
+ const { clientWidth, clientHeight } = this;
14847
+ let newWidth = clientWidth;
14848
+ let newHeight = clientHeight;
14849
+ let scale = NaN;
14850
+ switch (this.resize) {
14851
+ case RESIZE_BOTH:
14852
+ scale = 1;
14853
+ newWidth = width;
14854
+ newHeight = height;
14855
+ styles.width = width;
14856
+ styles.height = height;
14857
+ break;
14858
+ case RESIZE_HORIZONTAL:
14859
+ scale = clientHeight / height;
14860
+ newWidth = width * scale;
14861
+ styles.width = newWidth;
14862
+ break;
14863
+ case RESIZE_VERTICAL:
14864
+ scale = clientWidth / width;
14865
+ newHeight = height * scale;
14866
+ styles.height = newHeight;
14867
+ break;
14868
+ case RESIZE_NONE:
14869
+ default:
14870
+ if (clientWidth > 0) {
14871
+ scale = clientWidth / width;
14872
+ }
14873
+ else if (clientHeight > 0) {
14874
+ scale = clientHeight / height;
14875
+ }
14876
+ }
14877
+ this.$scale = scale;
14878
+ this.$setStyles(styles);
14879
+ if (this.$sourceImage) {
14880
+ this.$transformImageByOffset(this.$sourceImage.$getTransform(), -x, -y);
14881
+ }
14882
+ }
14883
+ $transformImageByOffset(matrix, x, y) {
14884
+ const { $image, $scale, $sourceImage, } = this;
14885
+ if ($sourceImage && $image && $scale > 0) {
14886
+ const [a, b, c, d, e, f] = matrix;
14887
+ const translateX = ((x * d) - (c * y)) / ((a * d) - (c * b));
14888
+ const translateY = (y - (b * translateX)) / d;
14889
+ const newE = a * translateX + c * translateY + e;
14890
+ const newF = b * translateX + d * translateY + f;
14891
+ $image.$ready((image) => {
14892
+ this.$setStyles.call($image, {
14893
+ width: image.naturalWidth * $scale,
14894
+ height: image.naturalHeight * $scale,
14895
+ });
14896
+ });
14897
+ $image.$setTransform(a, b, c, d, newE * $scale, newF * $scale);
14898
+ }
14899
+ }
14900
+ }
14901
+ CropperViewer.$name = CROPPER_VIEWER;
14902
+ CropperViewer.$version = '2.0.0-beta.4';
14903
+
14904
+ /*! Cropper.js v2.0.0-beta.4 | (c) 2015-present Chen Fengyuan | MIT */
14905
+ CropperCanvas.$define();
14906
+ CropperCrosshair.$define();
14907
+ CropperGrid.$define();
14908
+ CropperHandle.$define();
14909
+ CropperImage.$define();
14910
+ CropperSelection.$define();
14911
+ CropperShade.$define();
14912
+ CropperViewer.$define();
14913
+
14914
+ const cropperComponentCss = "/*!@.relative*/.relative.sc-p-cropper{position:relative!important}/*!@.mb-6*/.mb-6.sc-p-cropper{margin-bottom:1.5rem!important}/*!@.flex*/.flex.sc-p-cropper{display:flex!important}/*!@.h-4*/.h-4.sc-p-cropper{height:1rem!important}/*!@.h-\\[2px\\]*/.h-\\[2px\\].sc-p-cropper{height:2px!important}/*!@.w-4*/.w-4.sc-p-cropper{width:1rem!important}/*!@.w-full*/.w-full.sc-p-cropper{width:100%!important}/*!@.appearance-none*/.appearance-none.sc-p-cropper{-webkit-appearance:none!important;-moz-appearance:none!important;appearance:none!important}/*!@.flex-col*/.flex-col.sc-p-cropper{flex-direction:column!important}/*!@.items-center*/.items-center.sc-p-cropper{align-items:center!important}/*!@.justify-between*/.justify-between.sc-p-cropper{justify-content:space-between!important}/*!@.rounded-round*/.rounded-round.sc-p-cropper{border-radius:100%!important}/*!@.border-0*/.border-0.sc-p-cropper{border-width:0!important}/*!@**/*.sc-p-cropper{box-sizing:border-box}/*!@:host*/.sc-p-cropper-h{align-items:center;display:flex;flex-direction:column;gap:1.5rem;justify-content:space-between;margin-bottom:1.5rem;width:100%}/*!@:host .p-input[type=range]*/.sc-p-cropper-h .p-input[type=range].sc-p-cropper{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:transparent;position:relative}/*!@:host .p-input[type=range]::-moz-range-track,:host .p-input[type=range]::-webkit-slider-runnable-track*/.sc-p-cropper-h .p-input[type=range].sc-p-cropper::-moz-range-track,.sc-p-cropper-h .p-input[type=range].sc-p-cropper::-webkit-slider-runnable-track{--tw-bg-opacity:1;background-color:rgb(218 230 240/var(--tw-bg-opacity));height:2px}/*!@:host .p-input[type=range]::-moz-range-thumb,:host .p-input[type=range]::-webkit-slider-thumb*/.sc-p-cropper-h .p-input[type=range].sc-p-cropper::-moz-range-thumb,.sc-p-cropper-h .p-input[type=range].sc-p-cropper::-webkit-slider-thumb{--tw-bg-opacity:1;background-color:rgb(82 138 250/var(--tw-bg-opacity));border-radius:100%;border-width:0;height:1rem;width:1rem}/*!@.static*/.static.sc-p-cropper{position:static!important}/*!@.hidden*/.hidden.sc-p-cropper{display:none!important}/*!@.h-\\[17\\.5rem\\]*/.h-\\[17\\.5rem\\].sc-p-cropper{height:17.5rem!important}/*!@.transform*/.transform.sc-p-cropper{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))!important}/*!@.resize*/.resize.sc-p-cropper{resize:both!important}/*!@.gap-2*/.gap-2.sc-p-cropper{gap:.5rem!important}/*!@.rounded*/.rounded.sc-p-cropper{border-radius:.25rem!important}/*!@.border-b*/.border-b.sc-p-cropper{border-bottom-width:1px!important}/*!@.border-solid*/.border-solid.sc-p-cropper{border-style:solid!important}/*!@.border-mystic-medium*/.border-mystic-medium.sc-p-cropper{--tw-border-opacity:1!important;border-color:rgb(227 236 243/var(--tw-border-opacity))!important}/*!@.bg-white*/.bg-white.sc-p-cropper{--tw-bg-opacity:1!important;background-color:rgb(255 255 255/var(--tw-bg-opacity))!important}/*!@.px-14*/.px-14.sc-p-cropper{padding-left:3.5rem!important;padding-right:3.5rem!important}/*!@.text-storm-vague*/.text-storm-vague.sc-p-cropper{--tw-text-opacity:1!important;color:rgb(152 154 183/var(--tw-text-opacity))!important}@media (min-width:40rem){/*!@.tablet\\:max-w-xs*/.tablet\\:max-w-xs.sc-p-cropper{max-width:20rem!important}/*!@.tablet\\:px-1*/.tablet\\:px-1.sc-p-cropper{padding-left:.25rem!important;padding-right:.25rem!important}}";
14915
+
14916
+ class Cropper {
14917
+ constructor(hostRef) {
14918
+ registerInstance(this, hostRef);
14919
+ this.valueChange = createEvent(this, "valueChange", 3);
14920
+ this._maxScale = 0;
14921
+ this._minScale = 0;
14922
+ this.variant = 'user';
14923
+ this.value = undefined;
14924
+ this.returnType = 'base64';
14925
+ this._loaded = false;
14926
+ this._currentScale = 0;
14927
+ }
14928
+ onResize() {
14929
+ if (this._resizeDebounceTimeout) {
14930
+ clearTimeout(this._resizeDebounceTimeout);
14931
+ }
14932
+ this._resizeDebounceTimeout = setTimeout(() => {
14933
+ this._selectionRef.$center();
14934
+ this._imageRef.$center();
14935
+ }, 200);
14936
+ }
14937
+ componentDidLoad() {
14938
+ setTimeout(() => {
14939
+ this._loaded = true;
14940
+ }, 200);
14941
+ }
14942
+ render() {
14943
+ return (hAsync(Host, { class: "p-cropper" }, this._loaded && (hAsync("cropper-canvas", { class: "h-[17.5rem] w-full border-0 border-b border-solid border-mystic-medium bg-white", onAction: () => this._onAction() }, hAsync("cropper-image", { src: this.value, alt: "Picture", ref: (ref) => this._setImageRef(ref), scalable: true, crossorigin: "anonymous" }), hAsync("cropper-shade", { class: clsx({
14944
+ 'rounded-round': this.variant === 'user',
14945
+ rounded: this.variant === 'company',
14946
+ }), "theme-color": "rgba(255, 255, 255, 0.5)", hidden: true }), hAsync("cropper-selection", { "initial-coverage": "0.7", "aspect-ratio": "1", ref: (ref) => (this._selectionRef = ref) }), hAsync("cropper-handle", { action: "move", plain: true }))), hAsync("div", { class: "flex w-full items-center gap-2 px-14 text-storm-vague tablet:max-w-xs tablet:px-1" }, hAsync("p-icon", { variant: "minus" }), hAsync("input", { class: "p-input w-full", type: "range", min: "0", max: "100", value: this._currentScale, onInput: (ev) => this._onInput(ev.target.value), step: "0.5" }), hAsync("p-icon", { variant: "plus" }))));
14947
+ }
14948
+ _setImageRef(ref) {
14949
+ if (this._imageRef) {
14950
+ return;
14951
+ }
14952
+ this._imageRef = ref;
14953
+ this._imageRef.$ready((image) => setTimeout(() => this._setInitialState(image), 200));
14954
+ }
14955
+ _setInitialState(image) {
14956
+ let scale;
14957
+ if (image.naturalWidth > image.naturalHeight) {
14958
+ // set scale by height
14959
+ scale = 200 / image.naturalHeight;
14960
+ }
14961
+ if (image.naturalHeight >= image.naturalWidth) {
14962
+ // set scale by width
14963
+ scale = 200 / image.naturalWidth;
14964
+ }
14965
+ const current = this._imageRef.$getTransform();
14966
+ this._minScale = scale;
14967
+ this._maxScale = current[0];
14968
+ this._selectionRef.$resize('nw-resize', 200, 200, 1);
14969
+ this._selectionRef.$center();
14970
+ this._setScale(scale);
14971
+ this._toCanvas();
14972
+ }
14973
+ _onAction() {
14974
+ this._setCurrentScale();
14975
+ this._toCanvas();
14976
+ }
14977
+ _setScale(scale, setCenter = true, setCurrentScale = true) {
14978
+ const transform = this._imageRef.$getTransform();
14979
+ this._imageRef.$setTransform([
14980
+ scale,
14981
+ 0,
14982
+ 0,
14983
+ scale,
14984
+ transform[4],
14985
+ transform[5],
14986
+ ]);
14987
+ if (setCenter) {
14988
+ this._imageRef.$center();
14989
+ }
14990
+ if (setCurrentScale) {
14991
+ this._setCurrentScale();
14992
+ }
14993
+ }
14994
+ _setCurrentScale() {
14995
+ const transform = this._imageRef.$getTransform();
14996
+ const current = transform[0];
14997
+ if (current < this._minScale) {
14998
+ this._setScale(this._minScale, true, false);
14999
+ this._currentScale = 0;
15000
+ return;
15001
+ }
15002
+ if (current > this._maxScale) {
15003
+ this._setScale(this._maxScale, true, false);
15004
+ this._currentScale = 100;
15005
+ return;
15006
+ }
15007
+ if (current === this._minScale) {
15008
+ this._currentScale = 0;
15009
+ return;
15010
+ }
15011
+ if (current === this._maxScale) {
15012
+ this._currentScale = 100;
15013
+ return;
15014
+ }
15015
+ const minMaxDiff = this._maxScale - this._minScale;
15016
+ const currentDiff = current - this._minScale;
15017
+ const percentage = (currentDiff / minMaxDiff) * 100;
15018
+ this._currentScale = percentage;
15019
+ }
15020
+ _onInput(value) {
15021
+ const transform = this._imageRef.$getTransform();
15022
+ const current = transform[0];
15023
+ const minMaxDiff = this._maxScale - this._minScale;
15024
+ const toSet = minMaxDiff * (value / 100);
15025
+ if (toSet === current) {
15026
+ return;
15027
+ }
15028
+ this._setScale(toSet + this._minScale, false, false);
15029
+ this._currentScale = value;
15030
+ this._toCanvas();
15031
+ }
15032
+ _toCanvas() {
15033
+ if (this._toCanvasDebounceTimeout) {
15034
+ clearTimeout(this._toCanvasDebounceTimeout);
15035
+ }
15036
+ this._toCanvasDebounceTimeout = setTimeout(async () => {
15037
+ const canvas = await this._selectionRef.$toCanvas();
15038
+ if (this.returnType === 'canvas') {
15039
+ this.valueChange.emit(canvas);
15040
+ return;
15041
+ }
15042
+ const data = canvas.toDataURL('image/png');
15043
+ this.valueChange.emit(data);
15044
+ }, 200);
15045
+ }
15046
+ static get style() { return cropperComponentCss; }
15047
+ static get cmpMeta() { return {
15048
+ "$flags$": 9,
15049
+ "$tagName$": "p-cropper",
15050
+ "$members$": {
15051
+ "variant": [513],
15052
+ "value": [8],
15053
+ "returnType": [1, "return-type"],
15054
+ "_loaded": [32],
15055
+ "_currentScale": [32]
15056
+ },
15057
+ "$listeners$": [[9, "resize", "onResize"]],
15058
+ "$lazyBundleId$": "-",
15059
+ "$attrsToReflect$": [["variant", "variant"]]
15060
+ }; }
15061
+ }
15062
+
12243
15063
  const childOf = (c, p) => {
12244
15064
  while ((c = c.parentNode) && c !== p)
12245
15065
  ;
@@ -17224,6 +20044,7 @@ class Modal {
17224
20044
  this.showMobileFooter = false;
17225
20045
  this.backdropClickClose = true;
17226
20046
  this.scrollLock = true;
20047
+ this.padding = true;
17227
20048
  this._closing = false;
17228
20049
  }
17229
20050
  componentWillLoad() {
@@ -17240,7 +20061,7 @@ class Modal {
17240
20061
  const footerContent = hAsync("slot", { name: "footer" });
17241
20062
  return (hAsync(Host, { class: "p-modal" }, hAsync("p-backdrop", { applyBlur: this.applyBlur, onClicked: (ev) => this._backdropClick(ev.detail), closing: this._closing, scrollLock: this.scrollLock }, hAsync("p-modal-container", { size: this.size, closing: this._closing }, (((_a = this.header) === null || _a === void 0 ? void 0 : _a.length) || this._hasHeaderSlot) && (hAsync("p-modal-header", { showClose: this.showClose, onClose: (ev) => this.close(ev.detail) }, this._hasHeaderSlot
17242
20063
  ? headerContent
17243
- : this.header)), hAsync("p-modal-body", { variant: this.variant, rounded: !this._hasFooterSlot }, bodyContent), this._hasFooterSlot && (hAsync("p-modal-footer", null, footerContent))))));
20064
+ : this.header)), hAsync("p-modal-body", { variant: this.variant, rounded: !this._hasFooterSlot, padding: this.padding }, bodyContent), this._hasFooterSlot && (hAsync("p-modal-footer", null, footerContent))))));
17244
20065
  }
17245
20066
  _backdropClick(ev) {
17246
20067
  if (!this.backdropClickClose) {
@@ -17271,6 +20092,7 @@ class Modal {
17271
20092
  "showMobileFooter": [4, "show-mobile-footer"],
17272
20093
  "backdropClickClose": [4, "backdrop-click-close"],
17273
20094
  "scrollLock": [4, "scroll-lock"],
20095
+ "padding": [4],
17274
20096
  "_closing": [32]
17275
20097
  },
17276
20098
  "$listeners$": undefined,
@@ -17302,16 +20124,17 @@ class ModalBody$1 {
17302
20124
  }; }
17303
20125
  }
17304
20126
 
17305
- const modalBodyComponentCss = "/*!@.rounded-b-none*/.rounded-b-none.sc-p-modal-body{border-bottom-left-radius:0!important;border-bottom-right-radius:0!important}/*!@.px-6*/.px-6.sc-p-modal-body{padding-left:1.5rem!important;padding-right:1.5rem!important}/*!@**/*.sc-p-modal-body{box-sizing:border-box}/*!@:host*/.sc-p-modal-body-h{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity));padding:1.5rem}@media (min-width:40rem){/*!@:host*/.sc-p-modal-body-h{padding-left:2.5rem;padding-right:2.5rem}}@media (min-width:64rem){/*!@:host*/.sc-p-modal-body-h{padding-left:3.5rem;padding-right:3.5rem}}/*!@:host(.variant-table)*/.variant-table.sc-p-modal-body-h{padding-left:1.5rem;padding-right:1.5rem}/*!@:host(.is-rounded)*/.is-rounded.sc-p-modal-body-h{border-bottom-left-radius:0;border-bottom-right-radius:0}@media (min-width:64rem){/*!@:host(.is-rounded)*/.is-rounded.sc-p-modal-body-h{border-bottom-left-radius:.75rem;border-bottom-right-radius:.75rem}}@media (min-width:40rem){/*!@.tablet\\:px-10*/.tablet\\:px-10.sc-p-modal-body{padding-left:2.5rem!important;padding-right:2.5rem!important}}@media (min-width:64rem){/*!@.desktop-xs\\:px-14*/.desktop-xs\\:px-14.sc-p-modal-body{padding-left:3.5rem!important;padding-right:3.5rem!important}}/*!@.static*/.static.sc-p-modal-body{position:static!important}/*!@.rounded*/.rounded.sc-p-modal-body{border-radius:.25rem!important}";
20127
+ const modalBodyComponentCss = "/*!@.rounded-b-none*/.rounded-b-none.sc-p-modal-body{border-bottom-left-radius:0!important;border-bottom-right-radius:0!important}/*!@.px-6*/.px-6.sc-p-modal-body{padding-left:1.5rem!important;padding-right:1.5rem!important}/*!@.py-6*/.py-6.sc-p-modal-body{padding-bottom:1.5rem!important;padding-top:1.5rem!important}/*!@**/*.sc-p-modal-body{box-sizing:border-box}/*!@:host*/.sc-p-modal-body-h{--tw-bg-opacity:1;background-color:rgb(255 255 255/var(--tw-bg-opacity));padding:1.5rem}@media (min-width:40rem){/*!@:host*/.sc-p-modal-body-h{padding-left:2.5rem;padding-right:2.5rem}}@media (min-width:64rem){/*!@:host*/.sc-p-modal-body-h{padding-left:3.5rem;padding-right:3.5rem}}/*!@:host(.variant-table)*/.variant-table.sc-p-modal-body-h{padding-left:1.5rem;padding-right:1.5rem}/*!@:host(.is-rounded)*/.is-rounded.sc-p-modal-body-h{border-bottom-left-radius:0;border-bottom-right-radius:0}@media (min-width:64rem){/*!@:host(.is-rounded)*/.is-rounded.sc-p-modal-body-h{border-bottom-left-radius:.75rem;border-bottom-right-radius:.75rem}}/*!@:host(.no-padding)*/.no-padding.sc-p-modal-body-h{padding:0}@media (min-width:40rem){/*!@.tablet\\:px-10*/.tablet\\:px-10.sc-p-modal-body{padding-left:2.5rem!important;padding-right:2.5rem!important}}/*!@.static*/.static.sc-p-modal-body{position:static!important}/*!@.rounded*/.rounded.sc-p-modal-body{border-radius:.25rem!important}";
17306
20128
 
17307
20129
  class ModalBody {
17308
20130
  constructor(hostRef) {
17309
20131
  registerInstance(this, hostRef);
17310
20132
  this.variant = 'default';
17311
20133
  this.rounded = false;
20134
+ this.padding = true;
17312
20135
  }
17313
20136
  render() {
17314
- return (hAsync(Host, { class: `p-modal-body variant-${this.variant} ${this.rounded && 'is-rounded'}` }, hAsync("slot", null)));
20137
+ return (hAsync(Host, { class: `p-modal-body variant-${this.variant} ${this.rounded && 'is-rounded'} ${!this.padding && 'no-padding'}` }, hAsync("slot", null)));
17315
20138
  }
17316
20139
  static get style() { return modalBodyComponentCss; }
17317
20140
  static get cmpMeta() { return {
@@ -17319,7 +20142,8 @@ class ModalBody {
17319
20142
  "$tagName$": "p-modal-body",
17320
20143
  "$members$": {
17321
20144
  "variant": [1],
17322
- "rounded": [4]
20145
+ "rounded": [4],
20146
+ "padding": [4]
17323
20147
  },
17324
20148
  "$listeners$": undefined,
17325
20149
  "$lazyBundleId$": "-",
@@ -20346,6 +23170,7 @@ registerComponents([
20346
23170
  CardHeader,
20347
23171
  ContentSlider,
20348
23172
  Counter,
23173
+ Cropper,
20349
23174
  Datepicker,
20350
23175
  Divider,
20351
23176
  Drawer,