@dolphinweex/weex-vue-render 0.1.7 → 0.1.9

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.
@@ -8,9 +8,12 @@ console.log('START WEEX VUE RENDER: 1.0.36, Build 2018-12-29 17:52.');
8
8
  (global.WeexVueRender = factory());
9
9
  }(this, (function () { 'use strict';
10
10
 
11
- function isAbsoluteOrFixedPositioned(element) {
11
+ function isAbsoluteOrFixedPositioned(element, deep=2) {
12
12
  let currentElement = element;
13
- while (currentElement) {
13
+
14
+ let deep_ = 0;
15
+ while (currentElement && deep_ <= deep) {
16
+ deep_++;
14
17
  const position = window.getComputedStyle(currentElement).position;
15
18
  if (position === 'absolute' || position === 'fixed') {
16
19
  return true;
@@ -2982,7 +2985,7 @@ var scaleStyles = [
2982
2985
  'paddingRight',
2983
2986
  'paddingTop',
2984
2987
  'paddingBottom',
2985
- 'fontSize',
2988
+ 'fontSize', // 如果包含wx单位需要当作vp单位转化为px
2986
2989
  'lineHeight',
2987
2990
  'transform',
2988
2991
  'webkitTransform',
@@ -3030,7 +3033,8 @@ var config = {
3030
3033
  'cell',
3031
3034
  'a'
3032
3035
  ],
3033
- bindingStyleNamesForPx2Rem: allStyles
3036
+ bindingStyleNamesForPx2Rem: allStyles,
3037
+ bindingStyleNamesForPv2Px: ["fontSize", "lineHeight", "letterSpacing"]
3034
3038
  };
3035
3039
 
3036
3040
  /*
@@ -3530,6 +3534,7 @@ function getThrottleLazyload (wait, el) {
3530
3534
  */
3531
3535
 
3532
3536
  var bindingStyleNamesForPx2Rem = config.bindingStyleNamesForPx2Rem;
3537
+ var bindingStyleNamesForPv2Px = config.bindingStyleNamesForPv2Px;
3533
3538
 
3534
3539
  // whether to support using 0.5px to paint 1px width border.
3535
3540
  var _supportHairlines;
@@ -3734,7 +3739,12 @@ function styleObject2rem (style, rootValue) {
3734
3739
  var obj = {};
3735
3740
  for (var k in style) {
3736
3741
  var camK = camelize(k);
3737
- if (bindingStyleNamesForPx2Rem.indexOf(camK) > -1) {
3742
+
3743
+ if (bindingStyleNamesForPv2Px.indexOf(camK) > -1
3744
+ && obj[camK].indexOf("wx") > -1) {
3745
+
3746
+ obj[camK] = px2px(style[k]);
3747
+ } else if (bindingStyleNamesForPx2Rem.indexOf(camK) > -1) {
3738
3748
  obj[camK] = px2rem(style[k] + '', rootValue);
3739
3749
  }
3740
3750
  else {
@@ -3744,11 +3754,27 @@ function styleObject2rem (style, rootValue) {
3744
3754
  return obj
3745
3755
  }
3746
3756
 
3757
+ function px2px(pv) {
3758
+ if (typeof pv == "string" && pv.indexOf("wx" > 0)) {
3759
+ const floatValue = parseFloat(pv);
3760
+ // 不需要计算直接返回
3761
+ return floatValue + 'px'
3762
+ }
3763
+ if (typeof pv == "number") {
3764
+ var scale = window.weex.config.env.scale;
3765
+ return pv * scale + 'px'
3766
+ }
3767
+
3768
+ return pv;
3769
+ }
3770
+
3771
+ const ignoreSubKey = ['scale']
3747
3772
  function px2rem (px, rootValue) {
3748
3773
  // fix: 适配鸿蒙wx单位
3749
3774
  if (px.indexOf("--harmory") > -1) return px;
3750
3775
 
3751
- return px.replace(/([+-]?\d+(?:\.\d*)?)([p|w]x)?/g, function ($0, $1, $2) {
3776
+ return px.replace(/([+-]?\d+(?:\.\d*)?)([p|w]x)?/g, function ($0, $1, $2, offset, str) {
3777
+ if (ignoreSubKey.filter(k => str.slice(offset - k.length - 1, offset - 1) === k).length) return $1
3752
3778
  if ($2 === 'wx') { // 'wx' -> px
3753
3779
  // return ($midea_harmony_native ? $midea_harmony_native.vp2px($1) : $1) + 'px'
3754
3780
  // 适配鸿蒙wx
@@ -4675,6 +4701,15 @@ function watchAppearForScrollables (tagName, context) {
4675
4701
  }
4676
4702
  }
4677
4703
 
4704
+ function checkWeexRootClass () {
4705
+ var body = document.querySelector('body')
4706
+ var firstDiv = body.querySelector('div');
4707
+ // 检查第一个div节点是否包含root类
4708
+ if (firstDiv && !firstDiv.classList.contains('weex-root')) {
4709
+ firstDiv.classList.add('weex-root')
4710
+ }
4711
+ }
4712
+
4678
4713
  var base$1 = {
4679
4714
  beforeCreate: function beforeCreate () {
4680
4715
  if (!lazyloadWatched) {
@@ -4726,6 +4761,7 @@ var base$1 = {
4726
4761
  metaMt[tagName]++;
4727
4762
 
4728
4763
  watchAppearForScrollables(tagName, this);
4764
+ checkWeexRootClass();
4729
4765
 
4730
4766
  // when this is the root element of Vue instance.
4731
4767
  if (this === this.$root) {
@@ -4836,12 +4872,26 @@ var event$1 = {
4836
4872
  */
4837
4873
 
4838
4874
  var bindingStyleNamesForPx2Rem$1 = config.bindingStyleNamesForPx2Rem;
4875
+ var bindingStyleNamesForPv2Px$1 = config.bindingStyleNamesForPv2Px;
4839
4876
 
4840
4877
  var style = {
4841
4878
  methods: {
4879
+ _deepClone: function(obj) {
4880
+ if (obj === null) return null;
4881
+ if (obj instanceof RegExp) return new RegExp(obj);
4882
+ if (obj instanceof Date) return new Date(obj);
4883
+ if (typeof obj !== 'object') {
4884
+ return obj;
4885
+ }
4886
+ /** * 如果obj是数组,那么 obj.constructor 是 [Function: Array] * 如果obj是对象,那么 obj.constructor 是 [Function: Object] */
4887
+ let t = new obj.constructor();
4888
+ for (let key in obj) {
4889
+ t[key] = this._deepClone(obj[key]);
4890
+ }
4891
+ return t;
4892
+ },
4842
4893
  _px2rem: function _px2rem (value, rootValue) {
4843
4894
  var this$1 = this;
4844
-
4845
4895
  if (typeof value === 'string') {
4846
4896
  return (value + '').replace(/[+-]?\d+(?:.\d*)?[pw]x/gi, function ($0) {
4847
4897
  return weex.utils.px2rem($0, rootValue)
@@ -4851,21 +4901,28 @@ var style = {
4851
4901
  return weex.utils.px2rem(value + '', rootValue)
4852
4902
  }
4853
4903
  if (isPlainObject(value)) {
4854
- for (var k in value) {
4904
+ let cloneObj = this._deepClone(value)
4905
+ for (var k in cloneObj) {
4906
+ // 如果是"fontSize", "lineHeight", "letterSpacing"并且值包含wx则按照vp来转化为px使用
4855
4907
  if (
4856
- value.hasOwnProperty(k)
4908
+ bindingStyleNamesForPv2Px$1.indexOf(k) > -1
4909
+ && cloneObj[k].indexOf("wx") > -1) {
4910
+ cloneObj[k] = px2px(cloneObj[k]);
4911
+ }else if (
4912
+ cloneObj.hasOwnProperty(k)
4857
4913
  && bindingStyleNamesForPx2Rem$1.indexOf(k) > -1
4858
4914
  ) {
4859
- value[k] = weex.utils.px2rem(value[k] + '', rootValue);
4915
+ cloneObj[k] = weex.utils.px2rem(cloneObj[k] + '', rootValue);
4860
4916
  }
4861
4917
  }
4862
- return value
4918
+ return cloneObj
4863
4919
  }
4864
4920
  if (isArray(value)) {
4865
- for (var i = 0, l = value.length; i < l; i++) {
4866
- this$1._px2rem(value[i], rootValue);
4921
+ let cloneArr = this._deepClone(value)
4922
+ for (var i = 0, l = cloneArr.length; i < l; i++) {
4923
+ this$1._px2rem(cloneArr[i], rootValue);
4867
4924
  }
4868
- return value
4925
+ return cloneArr
4869
4926
  }
4870
4927
  },
4871
4928
 
@@ -5922,6 +5979,11 @@ function getList (weex) {
5922
5979
  if (isAbsoluteOrFixedPositioned(this$1.$el)) {
5923
5980
  this$1.$el.classList.remove("height-0");
5924
5981
  }
5982
+ setTimeout(() => {
5983
+ if (this$1.$el.clientHeight == 0) {
5984
+ this$1.$el.classList.remove("height-0");
5985
+ }
5986
+ }, 0);
5925
5987
  },
5926
5988
  methods: {
5927
5989
  createChildren: function createChildren (h) {
@@ -6013,6 +6075,11 @@ function getScroller (weex) {
6013
6075
  if (isAbsoluteOrFixedPositioned(this$1.$el)) {
6014
6076
  this$1.$el.classList.remove("height-0");
6015
6077
  }
6078
+ setTimeout(() => {
6079
+ if (this$1.$el.clientHeight == 0) {
6080
+ this$1.$el.classList.remove("height-0");
6081
+ }
6082
+ }, 0);
6016
6083
  },
6017
6084
  computed: {
6018
6085
  wrapperClass: function wrapperClass () {
@@ -6924,6 +6991,11 @@ function getList$1 (weex) {
6924
6991
  if (isAbsoluteOrFixedPositioned(this$1.$el)) {
6925
6992
  this$1.$el.classList.remove("height-0");
6926
6993
  }
6994
+ setTimeout(() => {
6995
+ if (this$1.$el.clientHeight == 0) {
6996
+ this$1.$el.classList.remove("height-0");
6997
+ }
6998
+ }, 0);
6927
6999
  },
6928
7000
  computed: {
6929
7001
  wrapperClass: function wrapperClass () {
package/package.json CHANGED
@@ -49,5 +49,5 @@
49
49
  "type": "git",
50
50
  "url": "git+ssh://git@github.com/weexteam/weex-vue-render.git"
51
51
  },
52
- "version": "0.1.7"
52
+ "version": "0.1.9"
53
53
  }