@plaidev/karte-action-sdk 1.1.267-29071859.db1ade43 → 1.1.267-29082699.18b12594

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.
@@ -1,7 +1,7 @@
1
1
  import { writable, get } from 'svelte/store';
2
2
  import { onMount as onMount$1, onDestroy as onDestroy$1, beforeUpdate as beforeUpdate$1, afterUpdate as afterUpdate$1, tick as tick$1, getContext, setContext, createEventDispatcher } from 'svelte';
3
3
  import { SvelteComponent, init, safe_not_equal, empty, head_selector, detach, append_hydration, noop, component_subscribe, element, claim_element, attr, insert_hydration, create_slot, create_component, space, claim_component, claim_space, mount_component, update_slot_base, get_all_dirty_from_scope, get_slot_changes, transition_in, transition_out, destroy_component, append_styles, group_outros, check_outros, children, null_to_empty, listen, assign, set_attributes, toggle_class, get_spread_update, prevent_default, is_function, add_render_callback, create_in_transition, binding_callbacks, set_style, svg_element, claim_svg_element, destroy_each, text, claim_text, set_data, src_url_equal, set_store_value, run_all, HtmlTagHydration, claim_html_tag, construct_svelte_component, subscribe, set_custom_element_data_map } from 'svelte/internal';
4
- import 'svelte/easing';
4
+ import { linear, elasticOut, cubicOut } from 'svelte/easing';
5
5
 
6
6
  /** @internal */
7
7
  const ACTION_HOOK_LABEL = '__ACTION_HOOK__';
@@ -35,10 +35,14 @@ const KARTE_MODAL_ROOT = 'karte-modal-root';
35
35
  /** @internal */
36
36
  const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused-vars
37
37
  /** @internal */
38
- const isPreview = () => {
39
- return true;
40
- };
41
- const isCanvasPreview = () => (document.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') === 'true';
38
+ const isPreview = () => (true);
39
+ const isCanvasPreview = () => typeof document !== 'undefined'
40
+ ? (document?.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') ===
41
+ 'true'
42
+ : false;
43
+ const isOnSite = () => typeof document !== 'undefined'
44
+ ? (document?.querySelector('#preview')?.getAttribute('data-on-site') ?? 'true') === 'true'
45
+ : true;
42
46
  /** @internal */
43
47
  const setPreviousFocus = () => {
44
48
  const previously_focused = typeof document !== 'undefined' && document.activeElement;
@@ -3382,6 +3386,54 @@ const execOnClickOperation = (onClickOperation) => {
3382
3386
  const haveFunction = (onClickOperation) => {
3383
3387
  return onClickOperation.operation !== 'none';
3384
3388
  };
3389
+ function getAnimation(animation) {
3390
+ switch (animation.type) {
3391
+ case 'fade':
3392
+ return `opacity: ${animation.progress}`;
3393
+ case 'bounce': {
3394
+ const translateX = animation.x;
3395
+ const translateY = animation.y;
3396
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0) scale(${animation.progress});`;
3397
+ }
3398
+ case 'slide-down': {
3399
+ const translateX = animation.x;
3400
+ const translateY = animation.y - 100 * (1 - animation.progress);
3401
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
3402
+ }
3403
+ case 'slide-up': {
3404
+ const translateX = animation.x;
3405
+ const translateY = animation.y + 100 * (1 - animation.progress);
3406
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
3407
+ }
3408
+ case 'slide-left': {
3409
+ const translateX = animation.x + 100 * (1 - animation.progress);
3410
+ const translateY = animation.y;
3411
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
3412
+ }
3413
+ case 'slide-right': {
3414
+ const translateX = animation.x - 100 * (1 - animation.progress);
3415
+ const translateY = animation.y;
3416
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
3417
+ }
3418
+ case 'none': {
3419
+ const translateX = animation.x;
3420
+ const translateY = animation.y;
3421
+ return `transform: translate3d(${translateX}%, ${translateY}%, 0);`;
3422
+ }
3423
+ default:
3424
+ console.warn(`[action-sdk] invalid '${animation}', so we use 'transform: none' instead`);
3425
+ return 'transform: none';
3426
+ }
3427
+ }
3428
+ const EASING = {
3429
+ fade: linear,
3430
+ bounce: elasticOut,
3431
+ 'slide-down': cubicOut,
3432
+ 'slide-up': cubicOut,
3433
+ 'slide-left': cubicOut,
3434
+ 'slide-right': cubicOut,
3435
+ none: linear,
3436
+ };
3385
3437
  /**
3386
3438
  * The function to activate svelte animation.
3387
3439
  *
@@ -3393,9 +3445,23 @@ const haveFunction = (onClickOperation) => {
3393
3445
  * @internal
3394
3446
  */
3395
3447
  function customAnimation(node, { transforms, animationStyle, delay = 0, duration = 1000 }) {
3396
- {
3448
+ if (!isOnSite()) {
3397
3449
  return {};
3398
3450
  }
3451
+ let [x, y] = [0, 0];
3452
+ for (const { query, x: tx, y: ty } of transforms) {
3453
+ if (query == null || window.matchMedia(query).matches) {
3454
+ x = tx;
3455
+ y = ty;
3456
+ break;
3457
+ }
3458
+ }
3459
+ return {
3460
+ delay,
3461
+ duration,
3462
+ easing: EASING[animationStyle],
3463
+ css: (progress) => getAnimation({ type: animationStyle, x, y, progress }),
3464
+ };
3399
3465
  }
3400
3466
 
3401
3467
  /* src/components/BackgroundOverlay.svelte generated by Svelte v3.53.1 */
@@ -21092,7 +21158,7 @@ function getActionRoot() {
21092
21158
  return root.shadowRoot;
21093
21159
  }
21094
21160
  /** @internal */
21095
- function ensureActionRoot() {
21161
+ function ensureActionRoot(useShadow = true) {
21096
21162
  const systemConfig = getSystem();
21097
21163
  const rootAttrs = {
21098
21164
  class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
@@ -21107,7 +21173,7 @@ function ensureActionRoot() {
21107
21173
  el = h('div', rootAttrs);
21108
21174
  document.body.appendChild(el);
21109
21175
  }
21110
- const isShadow = !!document.body.attachShadow;
21176
+ const isShadow = !!document.body.attachShadow && useShadow;
21111
21177
  if (isShadow) {
21112
21178
  return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
21113
21179
  }
@@ -21176,7 +21242,7 @@ function createApp(App, options = {
21176
21242
  },
21177
21243
  },
21178
21244
  };
21179
- const win = ensureModalRoot();
21245
+ const win = ensureModalRoot(true);
21180
21246
  appArgs.target = win;
21181
21247
  return {
21182
21248
  close,
package/dist/index.es.js CHANGED
@@ -35,10 +35,14 @@ const KARTE_MODAL_ROOT = 'karte-modal-root';
35
35
  /** @internal */
36
36
  const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused-vars
37
37
  /** @internal */
38
- const isPreview = () => {
39
- return false;
40
- };
41
- const isCanvasPreview = () => (document.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') === 'true';
38
+ const isPreview = () => (false);
39
+ const isCanvasPreview = () => typeof document !== 'undefined'
40
+ ? (document?.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') ===
41
+ 'true'
42
+ : false;
43
+ const isOnSite = () => typeof document !== 'undefined'
44
+ ? (document?.querySelector('#preview')?.getAttribute('data-on-site') ?? 'true') === 'true'
45
+ : true;
42
46
  /** @internal */
43
47
  const setPreviousFocus = () => {
44
48
  const previously_focused = typeof document !== 'undefined' && document.activeElement;
@@ -3465,6 +3469,9 @@ const EASING = {
3465
3469
  * @internal
3466
3470
  */
3467
3471
  function customAnimation(node, { transforms, animationStyle, delay = 0, duration = 1000 }) {
3472
+ if (!isOnSite()) {
3473
+ return {};
3474
+ }
3468
3475
  let [x, y] = [0, 0];
3469
3476
  for (const { query, x: tx, y: ty } of transforms) {
3470
3477
  if (query == null || window.matchMedia(query).matches) {
@@ -19544,7 +19551,7 @@ function getActionRoot() {
19544
19551
  return root.shadowRoot;
19545
19552
  }
19546
19553
  /** @internal */
19547
- function ensureActionRoot() {
19554
+ function ensureActionRoot(useShadow = true) {
19548
19555
  const systemConfig = getSystem();
19549
19556
  const rootAttrs = {
19550
19557
  class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
@@ -19559,7 +19566,7 @@ function ensureActionRoot() {
19559
19566
  el = h('div', rootAttrs);
19560
19567
  document.body.appendChild(el);
19561
19568
  }
19562
- const isShadow = !!document.body.attachShadow;
19569
+ const isShadow = !!document.body.attachShadow && useShadow;
19563
19570
  if (isShadow) {
19564
19571
  return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
19565
19572
  }
@@ -19628,7 +19635,7 @@ function createApp(App, options = {
19628
19635
  },
19629
19636
  },
19630
19637
  };
19631
- const win = ensureModalRoot();
19638
+ const win = ensureModalRoot(true);
19632
19639
  appArgs.target = win;
19633
19640
  return {
19634
19641
  close,
@@ -1419,7 +1419,7 @@ declare function getCssVariables(data: {
1419
1419
  */
1420
1420
  declare function getActionRoot(): ShadowRoot | null;
1421
1421
  /** @internal */
1422
- declare function ensureActionRoot(): ShadowRoot | HTMLElement;
1422
+ declare function ensureActionRoot(useShadow?: boolean): ShadowRoot | HTMLElement;
1423
1423
  /**
1424
1424
  * 非推奨
1425
1425
  *
@@ -38,11 +38,15 @@ const KARTE_MODAL_ROOT = 'karte-modal-root';
38
38
  /** @internal */
39
39
  const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused-vars
40
40
  /** @internal */
41
- const isPreview = () => {
42
- return !isOnSite() ;
43
- };
44
- const isCanvasPreview = () => (document.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') === 'true';
45
- const isOnSite = () => (document.querySelector('#preview')?.getAttribute('data-on-site') ?? 'true') === 'true';
41
+ const isPreview = () => (isInFrame() );
42
+ const isCanvasPreview = () => typeof document !== 'undefined'
43
+ ? (document?.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') ===
44
+ 'true'
45
+ : false;
46
+ const isOnSite = () => typeof document !== 'undefined'
47
+ ? (document?.querySelector('#preview')?.getAttribute('data-on-site') ?? 'true') === 'true'
48
+ : true;
49
+ const isInFrame = () => window && window.self !== window.top;
46
50
  /** @internal */
47
51
  const setPreviousFocus = () => {
48
52
  const previously_focused = typeof document !== 'undefined' && document.activeElement;
@@ -2269,7 +2273,7 @@ function getActionRoot() {
2269
2273
  return root.shadowRoot;
2270
2274
  }
2271
2275
  /** @internal */
2272
- function ensureActionRoot() {
2276
+ function ensureActionRoot(useShadow = true) {
2273
2277
  const systemConfig = getSystem();
2274
2278
  const rootAttrs = {
2275
2279
  class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
@@ -2284,7 +2288,7 @@ function ensureActionRoot() {
2284
2288
  el = h('div', rootAttrs);
2285
2289
  document.body.appendChild(el);
2286
2290
  }
2287
- const isShadow = !!document.body.attachShadow;
2291
+ const isShadow = !!document.body.attachShadow && useShadow;
2288
2292
  if (isShadow) {
2289
2293
  return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
2290
2294
  }
@@ -2353,7 +2357,7 @@ function createApp(App, options = {
2353
2357
  },
2354
2358
  },
2355
2359
  };
2356
- const win = ensureModalRoot();
2360
+ const win = ensureModalRoot(true);
2357
2361
  appArgs.target = win;
2358
2362
  return {
2359
2363
  close,
@@ -3447,7 +3451,7 @@ const EASING = {
3447
3451
  * @internal
3448
3452
  */
3449
3453
  function customAnimation(node, { transforms, animationStyle, delay = 0, duration = 1000 }) {
3450
- if (isPreview()) {
3454
+ if (!isOnSite()) {
3451
3455
  return {};
3452
3456
  }
3453
3457
  let [x, y] = [0, 0];
@@ -1419,7 +1419,7 @@ declare function getCssVariables(data: {
1419
1419
  */
1420
1420
  declare function getActionRoot(): ShadowRoot | null;
1421
1421
  /** @internal */
1422
- declare function ensureActionRoot(): ShadowRoot | HTMLElement;
1422
+ declare function ensureActionRoot(useShadow?: boolean): ShadowRoot | HTMLElement;
1423
1423
  /**
1424
1424
  * 非推奨
1425
1425
  *
@@ -38,11 +38,15 @@ const KARTE_MODAL_ROOT = 'karte-modal-root';
38
38
  /** @internal */
39
39
  const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused-vars
40
40
  /** @internal */
41
- const isPreview = () => {
42
- return !isOnSite() ;
43
- };
44
- const isCanvasPreview = () => (document.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') === 'true';
45
- const isOnSite = () => (document.querySelector('#preview')?.getAttribute('data-on-site') ?? 'true') === 'true';
41
+ const isPreview = () => (isInFrame() );
42
+ const isCanvasPreview = () => typeof document !== 'undefined'
43
+ ? (document?.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') ===
44
+ 'true'
45
+ : false;
46
+ const isOnSite = () => typeof document !== 'undefined'
47
+ ? (document?.querySelector('#preview')?.getAttribute('data-on-site') ?? 'true') === 'true'
48
+ : true;
49
+ const isInFrame = () => window && window.self !== window.top;
46
50
  /** @internal */
47
51
  const setPreviousFocus = () => {
48
52
  const previously_focused = typeof document !== 'undefined' && document.activeElement;
@@ -2310,7 +2314,7 @@ function getActionRoot() {
2310
2314
  return root.shadowRoot;
2311
2315
  }
2312
2316
  /** @internal */
2313
- function ensureActionRoot() {
2317
+ function ensureActionRoot(useShadow = true) {
2314
2318
  const systemConfig = getSystem();
2315
2319
  const rootAttrs = {
2316
2320
  class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
@@ -2325,7 +2329,7 @@ function ensureActionRoot() {
2325
2329
  el = h('div', rootAttrs);
2326
2330
  document.body.appendChild(el);
2327
2331
  }
2328
- const isShadow = !!document.body.attachShadow;
2332
+ const isShadow = !!document.body.attachShadow && useShadow;
2329
2333
  if (isShadow) {
2330
2334
  return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
2331
2335
  }
@@ -2394,7 +2398,7 @@ function createApp(App, options = {
2394
2398
  },
2395
2399
  },
2396
2400
  };
2397
- const win = ensureModalRoot();
2401
+ const win = ensureModalRoot(true);
2398
2402
  appArgs.target = win;
2399
2403
  return {
2400
2404
  close,
@@ -3488,7 +3492,7 @@ const EASING = {
3488
3492
  * @internal
3489
3493
  */
3490
3494
  function customAnimation(node, { transforms, animationStyle, delay = 0, duration = 1000 }) {
3491
- if (isPreview()) {
3495
+ if (!isOnSite()) {
3492
3496
  return {};
3493
3497
  }
3494
3498
  let [x, y] = [0, 0];
@@ -38,11 +38,15 @@ const KARTE_MODAL_ROOT = 'karte-modal-root';
38
38
  /** @internal */
39
39
  const NOOP = (_args) => { }; // eslint-disable-line @typescript-eslint/no-unused-vars
40
40
  /** @internal */
41
- const isPreview = () => {
42
- return !isOnSite() ;
43
- };
44
- const isCanvasPreview = () => (document.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') === 'true';
45
- const isOnSite = () => (document.querySelector('#preview')?.getAttribute('data-on-site') ?? 'true') === 'true';
41
+ const isPreview = () => (isInFrame() );
42
+ const isCanvasPreview = () => typeof document !== 'undefined'
43
+ ? (document?.querySelector('#preview')?.getAttribute('data-canvas-preview') ?? 'false') ===
44
+ 'true'
45
+ : false;
46
+ const isOnSite = () => typeof document !== 'undefined'
47
+ ? (document?.querySelector('#preview')?.getAttribute('data-on-site') ?? 'true') === 'true'
48
+ : true;
49
+ const isInFrame = () => window && window.self !== window.top;
46
50
  /** @internal */
47
51
  const setPreviousFocus = () => {
48
52
  const previously_focused = typeof document !== 'undefined' && document.activeElement;
@@ -2310,7 +2314,7 @@ function getActionRoot() {
2310
2314
  return root.shadowRoot;
2311
2315
  }
2312
2316
  /** @internal */
2313
- function ensureActionRoot() {
2317
+ function ensureActionRoot(useShadow = true) {
2314
2318
  const systemConfig = getSystem();
2315
2319
  const rootAttrs = {
2316
2320
  class: `${KARTE_ACTION_ROOT} ${KARTE_MODAL_ROOT}`,
@@ -2325,7 +2329,7 @@ function ensureActionRoot() {
2325
2329
  el = h('div', rootAttrs);
2326
2330
  document.body.appendChild(el);
2327
2331
  }
2328
- const isShadow = !!document.body.attachShadow;
2332
+ const isShadow = !!document.body.attachShadow && useShadow;
2329
2333
  if (isShadow) {
2330
2334
  return el.shadowRoot ?? el.attachShadow({ mode: 'open' });
2331
2335
  }
@@ -2394,7 +2398,7 @@ function createApp(App, options = {
2394
2398
  },
2395
2399
  },
2396
2400
  };
2397
- const win = ensureModalRoot();
2401
+ const win = ensureModalRoot(true);
2398
2402
  appArgs.target = win;
2399
2403
  return {
2400
2404
  close,
@@ -3488,7 +3492,7 @@ const EASING = {
3488
3492
  * @internal
3489
3493
  */
3490
3494
  function customAnimation(node, { transforms, animationStyle, delay = 0, duration = 1000 }) {
3491
- if (isPreview()) {
3495
+ if (!isOnSite()) {
3492
3496
  return {};
3493
3497
  }
3494
3498
  let [x, y] = [0, 0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaidev/karte-action-sdk",
3
- "version": "1.1.267-29071859.db1ade43",
3
+ "version": "1.1.267-29082699.18b12594",
4
4
  "author": "Plaid Inc.",
5
5
  "license": "Apache-2.0",
6
6
  "module": "./dist/index.es.js",