@lvce-editor/renderer-process 15.5.0 → 16.0.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.
@@ -286,7 +286,10 @@ const Option = 64;
286
286
  const Code$2 = 65;
287
287
  const Label = 66;
288
288
  const Dt = 67;
289
- const getElementTag = type => {
289
+ const VirtualDomElements = {
290
+ __proto__: null,
291
+ Text: Text$1};
292
+ const getElementTag$1 = type => {
290
293
  switch (type) {
291
294
  case Audio$2:
292
295
  return Audio$1$1;
@@ -400,6 +403,13 @@ const getElementTag = type => {
400
403
  throw new Error(`element tag not found ${type}`);
401
404
  }
402
405
  };
406
+ const ElementTagMap = {
407
+ __proto__: null,
408
+ getElementTag: getElementTag$1
409
+ };
410
+ const {
411
+ getElementTag
412
+ } = ElementTagMap;
403
413
  const getEventListenerOptions$1 = (eventName, value) => {
404
414
  if (value.passive) {
405
415
  return {
@@ -618,6 +628,9 @@ const setProps = ($Element, props, eventMap, newEventMap) => {
618
628
  setProp($Element, key, props[key], eventMap, newEventMap);
619
629
  }
620
630
  };
631
+ const {
632
+ Text: Text$2
633
+ } = VirtualDomElements;
621
634
  const renderDomTextNode = element => {
622
635
  return document.createTextNode(element.text);
623
636
  };
@@ -629,7 +642,7 @@ const renderDomElement = (element, eventMap, newEventMap) => {
629
642
  };
630
643
  const render$1 = (element, eventMap, newEventMap) => {
631
644
  switch (element.type) {
632
- case Text$1:
645
+ case Text$2:
633
646
  return renderDomTextNode(element);
634
647
  default:
635
648
  return renderDomElement(element, eventMap, newEventMap);
@@ -2713,8 +2726,10 @@ const measureTextBlockHeight = (text, fontSize, fontFamily, lineHeight, width) =
2713
2726
  $Measure.style.left = '-9999px';
2714
2727
  $Measure.style.fontSize = `${fontSize}px`;
2715
2728
  $Measure.style.lineHeight = lineHeight;
2729
+ $Measure.style.whiteSpace = 'pre';
2716
2730
  $Measure.textContent = text;
2717
- return getElementHeight($Measure);
2731
+ const height = getElementHeight($Measure);
2732
+ return height;
2718
2733
  };
2719
2734
 
2720
2735
  const measureTextHeight = (text, fontSize, fontFamily) => {
@@ -3421,42 +3436,6 @@ const start = async (id, options) => {
3421
3436
  }
3422
3437
  };
3423
3438
 
3424
- const getTimeStamp = () => {
3425
- return performance.now();
3426
- };
3427
-
3428
- const waitForMutation = async maxDelay => {
3429
- const disposables = [];
3430
- await Promise.race([new Promise(resolve => {
3431
- const timeout = setTimeout(resolve, maxDelay);
3432
- // @ts-expect-error
3433
- disposables.push(() => {
3434
- clearTimeout(timeout);
3435
- });
3436
- }), new Promise(resolve => {
3437
- const callback = mutations => {
3438
- resolve(undefined);
3439
- };
3440
- const observer = new MutationObserver(callback);
3441
- observer.observe(document.body, {
3442
- childList: true,
3443
- attributes: true,
3444
- characterData: true,
3445
- subtree: true,
3446
- attributeOldValue: true,
3447
- characterDataOldValue: true
3448
- });
3449
- // @ts-expect-error
3450
- disposables.push(() => {
3451
- observer.disconnect();
3452
- });
3453
- })]);
3454
- for (const disposable of disposables) {
3455
- // @ts-expect-error
3456
- disposable();
3457
- }
3458
- };
3459
-
3460
3439
  const getEventClass = eventType => {
3461
3440
  switch (eventType) {
3462
3441
  case Wheel:
@@ -3528,32 +3507,6 @@ const ElementActions = {
3528
3507
  type
3529
3508
  };
3530
3509
 
3531
- const press = options => {
3532
- const element = document.activeElement;
3533
- keyDown(element, options);
3534
- keyUp(element, options);
3535
- };
3536
-
3537
- const KeyBoardActions = {
3538
- __proto__: null,
3539
- press
3540
- };
3541
-
3542
- const toHaveCount$1 = (elements, {
3543
- count
3544
- }) => {
3545
- return elements.length === count;
3546
- };
3547
- const toBeHidden = elements => {
3548
- return elements.length === 0;
3549
- };
3550
-
3551
- const MultiElementConditions = {
3552
- __proto__: null,
3553
- toBeHidden,
3554
- toHaveCount: toHaveCount$1
3555
- };
3556
-
3557
3510
  const htmlElements = ['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdo', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'command', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link', 'map', 'mark', 'menu', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'pre', 'progress', 'q', 'rp', 'rt', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr'];
3558
3511
 
3559
3512
  const querySelectorByText = (root, text) => {
@@ -3629,81 +3582,23 @@ const querySelectorWithOptions = (selector, {
3629
3582
  return element;
3630
3583
  };
3631
3584
 
3632
- const toBeVisible = element => {
3633
- if (typeof element.isVisible === 'function') {
3634
- return element.isVisible();
3635
- }
3636
- return element.isConnected;
3637
- };
3638
- const toHaveValue = (element, {
3639
- value
3640
- }) => {
3641
- return element.value === value;
3642
- };
3643
- const toHaveText$1 = (element, {
3644
- text
3645
- }) => {
3646
- return element.textContent === text;
3647
- };
3648
- const toContainText = (element, {
3649
- text
3650
- }) => {
3651
- return element.textContent.includes(text);
3652
- };
3653
- const toHaveAttribute$1 = (element, {
3654
- key,
3655
- value
3656
- }) => {
3657
- const attribute = element.getAttribute(key);
3658
- return attribute === value;
3659
- };
3660
- const toHaveJSProperty$1 = (element, {
3661
- key,
3662
- value
3663
- }) => {
3664
- const attribute = element[key];
3665
- return attribute === value;
3666
- };
3667
- const toBeFocused$1 = element => {
3668
- return element === document.activeElement;
3669
- };
3670
- const toHaveClass$1 = (element, {
3671
- className
3672
- }) => {
3673
- return element.classList.contains(className);
3674
- };
3675
- const toHaveId$1 = (element, {
3676
- id
3677
- }) => {
3678
- return element.id === id;
3679
- };
3680
- const toHaveCss$1 = (element, {
3681
- key,
3682
- value
3683
- }) => {
3684
- const style = getComputedStyle(element);
3685
- const actualValue = style[key];
3686
- if (value instanceof RegExp) {
3687
- return value.test(actualValue);
3585
+ const performAction2 = async (locator, fnName, options) => {
3586
+ object(locator);
3587
+ string(fnName);
3588
+ object(options);
3589
+ const fn = ElementActions[fnName];
3590
+ const element = querySelectorWithOptions(locator._selector, {
3591
+ hasText: locator._hasText,
3592
+ nth: locator._nth
3593
+ });
3594
+ if (!element) {
3595
+ throw new Error(`element not found`);
3688
3596
  }
3689
- return actualValue === value;
3690
- };
3691
-
3692
- const SingleElementConditions = {
3693
- __proto__: null,
3694
- toBeFocused: toBeFocused$1,
3695
- toBeVisible,
3696
- toContainText,
3697
- toHaveAttribute: toHaveAttribute$1,
3698
- toHaveClass: toHaveClass$1,
3699
- toHaveCss: toHaveCss$1,
3700
- toHaveId: toHaveId$1,
3701
- toHaveJSProperty: toHaveJSProperty$1,
3702
- toHaveText: toHaveText$1,
3703
- toHaveValue
3597
+ fn(element, options);
3598
+ return;
3704
3599
  };
3705
3600
 
3706
- const toHaveText = locator => {
3601
+ const toHaveText$1 = locator => {
3707
3602
  const element = querySelectorWithOptions(locator._selector, {
3708
3603
  nth: locator._nth,
3709
3604
  hasText: locator._hasText
@@ -3719,7 +3614,7 @@ const toHaveText = locator => {
3719
3614
  actual: element.textContent
3720
3615
  };
3721
3616
  };
3722
- const toHaveAttribute = (locator, {
3617
+ const toHaveAttribute$1 = (locator, {
3723
3618
  key,
3724
3619
  value
3725
3620
  }) => {
@@ -3739,7 +3634,7 @@ const toHaveAttribute = (locator, {
3739
3634
  actual
3740
3635
  };
3741
3636
  };
3742
- const toHaveCount = locator => {
3637
+ const toHaveCount$1 = locator => {
3743
3638
  const elements = querySelector(locator._selector);
3744
3639
  const actualCount = elements.length;
3745
3640
  return {
@@ -3758,14 +3653,14 @@ const stringifyElement = element => {
3758
3653
  }
3759
3654
  return element.tagName;
3760
3655
  };
3761
- const toBeFocused = locator => {
3656
+ const toBeFocused$1 = locator => {
3762
3657
  const activeElement = document.activeElement;
3763
3658
  const stringifiedActiveElement = stringifyElement(activeElement);
3764
3659
  return {
3765
3660
  actual: stringifiedActiveElement
3766
3661
  };
3767
3662
  };
3768
- const toHaveClass = (locator, {
3663
+ const toHaveClass$1 = (locator, {
3769
3664
  className
3770
3665
  }) => {
3771
3666
  const [element] = querySelector(locator._selector);
@@ -3780,7 +3675,7 @@ const toHaveClass = (locator, {
3780
3675
  actual: className
3781
3676
  };
3782
3677
  };
3783
- const toHaveId = locator => {
3678
+ const toHaveId$1 = locator => {
3784
3679
  const [element] = querySelector(locator._selector);
3785
3680
  if (!element) {
3786
3681
  return {
@@ -3793,7 +3688,7 @@ const toHaveId = locator => {
3793
3688
  actual: element.id
3794
3689
  };
3795
3690
  };
3796
- const toHaveCss = (locator, {
3691
+ const toHaveCss$1 = (locator, {
3797
3692
  key
3798
3693
  }) => {
3799
3694
  const [element] = querySelector(locator._selector);
@@ -3810,7 +3705,7 @@ const toHaveCss = (locator, {
3810
3705
  actual
3811
3706
  };
3812
3707
  };
3813
- const toHaveJSProperty = (locator, {
3708
+ const toHaveJSProperty$1 = (locator, {
3814
3709
  key
3815
3710
  }) => {
3816
3711
  const [element] = querySelector(locator._selector);
@@ -3828,39 +3723,115 @@ const toHaveJSProperty = (locator, {
3828
3723
  };
3829
3724
 
3830
3725
  const ConditionValues = {
3726
+ __proto__: null,
3727
+ toBeFocused: toBeFocused$1,
3728
+ toHaveAttribute: toHaveAttribute$1,
3729
+ toHaveClass: toHaveClass$1,
3730
+ toHaveCount: toHaveCount$1,
3731
+ toHaveCss: toHaveCss$1,
3732
+ toHaveId: toHaveId$1,
3733
+ toHaveJSProperty: toHaveJSProperty$1,
3734
+ toHaveText: toHaveText$1
3735
+ };
3736
+
3737
+ const press = options => {
3738
+ const element = document.activeElement;
3739
+ keyDown(element, options);
3740
+ keyUp(element, options);
3741
+ };
3742
+
3743
+ const KeyBoardActions = {
3744
+ __proto__: null,
3745
+ press
3746
+ };
3747
+
3748
+ const toHaveCount = (elements, {
3749
+ count
3750
+ }) => {
3751
+ return elements.length === count;
3752
+ };
3753
+ const toBeHidden = elements => {
3754
+ return elements.length === 0;
3755
+ };
3756
+
3757
+ const MultiElementConditions = {
3758
+ __proto__: null,
3759
+ toBeHidden,
3760
+ toHaveCount
3761
+ };
3762
+
3763
+ const toBeVisible = element => {
3764
+ if (typeof element.isVisible === 'function') {
3765
+ return element.isVisible();
3766
+ }
3767
+ return element.isConnected;
3768
+ };
3769
+ const toHaveValue = (element, {
3770
+ value
3771
+ }) => {
3772
+ return element.value === value;
3773
+ };
3774
+ const toHaveText = (element, {
3775
+ text
3776
+ }) => {
3777
+ return element.textContent === text;
3778
+ };
3779
+ const toContainText = (element, {
3780
+ text
3781
+ }) => {
3782
+ return element.textContent.includes(text);
3783
+ };
3784
+ const toHaveAttribute = (element, {
3785
+ key,
3786
+ value
3787
+ }) => {
3788
+ const attribute = element.getAttribute(key);
3789
+ return attribute === value;
3790
+ };
3791
+ const toHaveJSProperty = (element, {
3792
+ key,
3793
+ value
3794
+ }) => {
3795
+ const attribute = element[key];
3796
+ return attribute === value;
3797
+ };
3798
+ const toBeFocused = element => {
3799
+ return element === document.activeElement;
3800
+ };
3801
+ const toHaveClass = (element, {
3802
+ className
3803
+ }) => {
3804
+ return element.classList.contains(className);
3805
+ };
3806
+ const toHaveId = (element, {
3807
+ id
3808
+ }) => {
3809
+ return element.id === id;
3810
+ };
3811
+ const toHaveCss = (element, {
3812
+ key,
3813
+ value
3814
+ }) => {
3815
+ const style = getComputedStyle(element);
3816
+ const actualValue = style[key];
3817
+ if (value instanceof RegExp) {
3818
+ return value.test(actualValue);
3819
+ }
3820
+ return actualValue === value;
3821
+ };
3822
+
3823
+ const SingleElementConditions = {
3831
3824
  __proto__: null,
3832
3825
  toBeFocused,
3826
+ toBeVisible,
3827
+ toContainText,
3833
3828
  toHaveAttribute,
3834
3829
  toHaveClass,
3835
- toHaveCount,
3836
3830
  toHaveCss,
3837
3831
  toHaveId,
3838
3832
  toHaveJSProperty,
3839
- toHaveText
3840
- };
3841
-
3842
- // TODO this should also come in via options
3843
- const maxTimeout$1 = 2000;
3844
- const performAction2 = async (locator, fnName, options) => {
3845
- object(locator);
3846
- string(fnName);
3847
- object(options);
3848
- const startTime = getTimeStamp();
3849
- const endTime = startTime + maxTimeout$1;
3850
- let currentTime = startTime;
3851
- const fn = ElementActions[fnName];
3852
- while (currentTime < endTime) {
3853
- const element = querySelectorWithOptions(locator._selector, {
3854
- hasText: locator._hasText,
3855
- nth: locator._nth
3856
- });
3857
- if (element) {
3858
- fn(element, options);
3859
- return;
3860
- }
3861
- await waitForMutation(100);
3862
- currentTime = getTimeStamp();
3863
- }
3833
+ toHaveText,
3834
+ toHaveValue
3864
3835
  };
3865
3836
 
3866
3837
  const create$Overlay = () => {
@@ -3884,26 +3855,21 @@ const showOverlay = (state, background, text) => {
3884
3855
  $TestOverlay.textContent = text;
3885
3856
  document.body.append($TestOverlay);
3886
3857
  };
3887
- const maxTimeout = 2000;
3888
3858
  const performAction = async (locator, fnName, options) => {
3889
3859
  object(locator);
3890
3860
  string(fnName);
3891
3861
  object(options);
3892
- const startTime = getTimeStamp();
3893
- const endTime = startTime + maxTimeout;
3894
- let currentTime = startTime;
3895
3862
  const fn = ElementActions[fnName];
3896
- while (currentTime < endTime) {
3897
- const element = querySelectorWithOptions(locator._selector, {
3898
- hasText: locator._hasText,
3899
- nth: locator._nth
3900
- });
3901
- if (element) {
3902
- fn(element, options);
3903
- return;
3904
- }
3905
- await waitForMutation(100);
3906
- currentTime = getTimeStamp();
3863
+ const element = querySelectorWithOptions(locator._selector, {
3864
+ hasText: locator._hasText,
3865
+ nth: locator._nth
3866
+ });
3867
+ if (!element) {
3868
+ throw new Error(`element not found`);
3869
+ }
3870
+ if (element) {
3871
+ fn(element, options);
3872
+ return;
3907
3873
  }
3908
3874
  };
3909
3875
  const performKeyBoardAction = (fnName, options) => {
@@ -3911,45 +3877,31 @@ const performKeyBoardAction = (fnName, options) => {
3911
3877
  fn(options);
3912
3878
  };
3913
3879
  const checkSingleElementCondition = async (locator, fnName, options) => {
3914
- const startTime = getTimeStamp();
3915
- const endTime = startTime + maxTimeout;
3916
- let currentTime = startTime;
3917
3880
  const fn = SingleElementConditions[fnName];
3918
- while (currentTime < endTime) {
3919
- const element = querySelectorWithOptions(locator._selector, {
3920
- hasText: locator._hasText,
3921
- nth: locator._nth
3922
- });
3923
- if (element) {
3924
- const successful = fn(element, options);
3925
- if (successful) {
3926
- return {
3927
- error: false
3928
- };
3929
- }
3881
+ const element = querySelectorWithOptions(locator._selector, {
3882
+ hasText: locator._hasText,
3883
+ nth: locator._nth
3884
+ });
3885
+ if (element) {
3886
+ const successful = fn(element, options);
3887
+ if (successful) {
3888
+ return {
3889
+ error: false
3890
+ };
3930
3891
  }
3931
- await waitForMutation(100);
3932
- currentTime = getTimeStamp();
3933
3892
  }
3934
3893
  return {
3935
3894
  error: true
3936
3895
  };
3937
3896
  };
3938
3897
  const checkMultiElementCondition = async (locator, fnName, options) => {
3939
- const startTime = getTimeStamp();
3940
- const endTime = startTime + maxTimeout;
3941
- let currentTime = startTime;
3942
3898
  const fn = MultiElementConditions[fnName];
3943
- while (currentTime < endTime) {
3944
- const elements = querySelector(locator._selector);
3945
- const successful = fn(elements, options);
3946
- if (successful) {
3947
- return {
3948
- error: false
3949
- };
3950
- }
3951
- await waitForMutation(100);
3952
- currentTime = getTimeStamp();
3899
+ const elements = querySelector(locator._selector);
3900
+ const successful = fn(elements, options);
3901
+ if (successful) {
3902
+ return {
3903
+ error: false
3904
+ };
3953
3905
  }
3954
3906
  return {
3955
3907
  error: true
@@ -8168,11 +8120,7 @@ const setFocused = (state, isFocused) => {
8168
8120
  const {
8169
8121
  $Viewlet
8170
8122
  } = state;
8171
- if (isFocused) {
8172
- $Viewlet.classList.add(activeClassName);
8173
- } else {
8174
- $Viewlet.classList.remove(activeClassName);
8175
- }
8123
+ $Viewlet.classList.toggle(activeClassName, isFocused);
8176
8124
  };
8177
8125
 
8178
8126
  const ViewletTitleBar = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/renderer-process",
3
- "version": "15.5.0",
3
+ "version": "16.0.0",
4
4
  "keywords": [
5
5
  "lvce-editor",
6
6
  "renderer-process"