components.js 48.7 KB
Newer Older
fxy060608's avatar
fxy060608 已提交
1
import { createElementVNode, defineComponent, createVNode, mergeProps, getCurrentInstance, provide, watch, onUnmounted, shallowRef, reactive, watchEffect, ref, inject, onBeforeUnmount, computed, Text, isVNode, Fragment, onMounted } from "vue";
fxy060608's avatar
fxy060608 已提交
2 3
import { extend, hasOwn, isPlainObject } from "@vue/shared";
import { cacheStringFunction, PRIMARY_COLOR } from "@dcloudio/uni-shared";
fxy060608's avatar
fxy060608 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
const OPEN_TYPES = [
  "navigate",
  "redirect",
  "switchTab",
  "reLaunch",
  "navigateBack"
];
const navigatorProps = {
  hoverClass: {
    type: String,
    default: "navigator-hover"
  },
  url: {
    type: String,
    default: ""
  },
  openType: {
    type: String,
    default: "navigate",
    validator(value) {
      return Boolean(~OPEN_TYPES.indexOf(value));
fxy060608's avatar
fxy060608 已提交
25
    }
fxy060608's avatar
fxy060608 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
  },
  delta: {
    type: Number,
    default: 1
  },
  hoverStartTime: {
    type: [Number, String],
    default: 50
  },
  hoverStayTime: {
    type: [Number, String],
    default: 600
  },
  exists: {
    type: String,
    default: ""
  },
  hoverStopPropagation: {
    type: Boolean,
    default: false
  }
};
fxy060608's avatar
fxy060608 已提交
48
function createNavigatorOnClick(props) {
fxy060608's avatar
fxy060608 已提交
49
  return () => {
fxy060608's avatar
fxy060608 已提交
50
    if (props.openType !== "navigateBack" && !props.url) {
fxy060608's avatar
fxy060608 已提交
51 52
      console.error("<navigator/> should have url attribute when using navigateTo, redirectTo, reLaunch or switchTab");
      return;
fxy060608's avatar
fxy060608 已提交
53
    }
fxy060608's avatar
fxy060608 已提交
54
    switch (props.openType) {
fxy060608's avatar
fxy060608 已提交
55 56
      case "navigate":
        uni.navigateTo({
fxy060608's avatar
fxy060608 已提交
57
          url: props.url
fxy060608's avatar
fxy060608 已提交
58 59 60 61
        });
        break;
      case "redirect":
        uni.redirectTo({
fxy060608's avatar
fxy060608 已提交
62 63
          url: props.url,
          exists: props.exists
fxy060608's avatar
fxy060608 已提交
64 65 66 67
        });
        break;
      case "switchTab":
        uni.switchTab({
fxy060608's avatar
fxy060608 已提交
68
          url: props.url
fxy060608's avatar
fxy060608 已提交
69 70 71 72
        });
        break;
      case "reLaunch":
        uni.reLaunch({
fxy060608's avatar
fxy060608 已提交
73
          url: props.url
fxy060608's avatar
fxy060608 已提交
74 75 76 77
        });
        break;
      case "navigateBack":
        uni.navigateBack({
fxy060608's avatar
fxy060608 已提交
78
          delta: props.delta
fxy060608's avatar
fxy060608 已提交
79 80 81 82 83
        });
        break;
    }
  };
}
fxy060608's avatar
fxy060608 已提交
84 85 86 87 88
function useHoverClass(props) {
  if (props.hoverClass && props.hoverClass !== "none") {
    const hoverAttrs = { hoverClass: props.hoverClass };
    if (hasOwn(props, "hoverStartTime")) {
      hoverAttrs.hoverStartTime = props.hoverStartTime;
fxy060608's avatar
fxy060608 已提交
89
    }
fxy060608's avatar
fxy060608 已提交
90 91
    if (hasOwn(props, "hoverStayTime")) {
      hoverAttrs.hoverStayTime = props.hoverStayTime;
fxy060608's avatar
fxy060608 已提交
92
    }
fxy060608's avatar
fxy060608 已提交
93 94
    if (hasOwn(props, "hoverStopPropagation")) {
      hoverAttrs.hoverStopPropagation = props.hoverStopPropagation;
fxy060608's avatar
fxy060608 已提交
95 96 97 98
    }
    return hoverAttrs;
  }
  return {};
fxy060608's avatar
fxy060608 已提交
99
}
fxy060608's avatar
fxy060608 已提交
100 101 102
function createNVueTextVNode(text, attrs) {
  return createElementVNode("u-text", extend({ appendAsTree: true }, attrs), text);
}
fxy060608's avatar
fxy060608 已提交
103 104
const navigatorStyles = [{
  "navigator-hover": {
fxy060608's avatar
fxy060608 已提交
105 106 107 108
    "": {
      backgroundColor: "rgba(0,0,0,0.1)",
      opacity: 0.7
    }
fxy060608's avatar
fxy060608 已提交
109 110 111 112 113 114
  }
}];
var Navigator = defineComponent({
  name: "Navigator",
  props: navigatorProps,
  styles: navigatorStyles,
fxy060608's avatar
fxy060608 已提交
115
  setup(props, {
fxy060608's avatar
fxy060608 已提交
116 117
    slots
  }) {
fxy060608's avatar
fxy060608 已提交
118
    const onClick = createNavigatorOnClick(props);
fxy060608's avatar
fxy060608 已提交
119
    return () => {
fxy060608's avatar
fxy060608 已提交
120
      return createVNode("view", mergeProps(useHoverClass(props), {
fxy060608's avatar
fxy060608 已提交
121 122 123 124 125
        "onClick": onClick
      }), [slots.default && slots.default()]);
    };
  }
});
fxy060608's avatar
fxy060608 已提交
126 127 128 129 130 131
function PolySymbol(name) {
  return Symbol(process.env.NODE_ENV !== "production" ? "[uni-app]: " + name : name);
}
function useCurrentPageId() {
  return getCurrentInstance().root.proxy.$page.id;
}
fxy060608's avatar
fxy060608 已提交
132
const labelProps = {
fxy060608's avatar
fxy060608 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
  for: {
    type: String,
    default: ""
  }
};
const uniLabelKey = PolySymbol(process.env.NODE_ENV !== "production" ? "uniLabel" : "ul");
function useProvideLabel() {
  const handlers = [];
  provide(uniLabelKey, {
    addHandler(handler) {
      handlers.push(handler);
    },
    removeHandler(handler) {
      handlers.splice(handlers.indexOf(handler), 1);
    }
  });
  return handlers;
}
var Label = /* @__PURE__ */ defineComponent({
  name: "Label",
fxy060608's avatar
fxy060608 已提交
153
  props: labelProps,
fxy060608's avatar
fxy060608 已提交
154
  styles: [],
fxy060608's avatar
fxy060608 已提交
155
  setup(props, {
fxy060608's avatar
fxy060608 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169
    slots
  }) {
    const pageId = useCurrentPageId();
    const handlers = useProvideLabel();
    const _onClick = ($event) => {
      const EventTarget = $event.target;
      const dataType = EventTarget.attr.dataUncType || "";
      let stopPropagation = /^uni-(checkbox|radio|switch)-/.test(dataType);
      if (!stopPropagation) {
        stopPropagation = /^uni-(checkbox|radio|switch|button)$/i.test(dataType);
      }
      if (stopPropagation) {
        return;
      }
fxy060608's avatar
fxy060608 已提交
170 171
      if (props.for) {
        UniViewJSBridge.emit(`uni-label-click-${pageId}-${props.for}`, $event, true);
fxy060608's avatar
fxy060608 已提交
172 173 174 175
      } else {
        handlers.length && handlers[0]($event, true);
      }
    };
fxy060608's avatar
fxy060608 已提交
176
    return () => createVNode("view", {
fxy060608's avatar
fxy060608 已提交
177 178 179 180
      "onClick": _onClick
    }, [slots.default && slots.default()]);
  }
});
fxy060608's avatar
fxy060608 已提交
181 182 183
function useListeners(props, listeners) {
  _addListeners(props.id, listeners);
  watch(() => props.id, (newId, oldId) => {
fxy060608's avatar
fxy060608 已提交
184 185 186 187
    _removeListeners(oldId, listeners, true);
    _addListeners(newId, listeners, true);
  });
  onUnmounted(() => {
fxy060608's avatar
fxy060608 已提交
188
    _removeListeners(props.id, listeners);
fxy060608's avatar
fxy060608 已提交
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
  });
}
function _addListeners(id, listeners, watch2) {
  const pageId = useCurrentPageId();
  if (watch2 && !id) {
    return;
  }
  if (!isPlainObject(listeners)) {
    return;
  }
  Object.keys(listeners).forEach((name) => {
    if (watch2) {
      if (name.indexOf("@") !== 0 && name.indexOf("uni-") !== 0) {
        UniViewJSBridge.on(`uni-${name}-${pageId}-${id}`, listeners[name]);
      }
    } else {
      if (name.indexOf("uni-") === 0) {
        UniViewJSBridge.on(name, listeners[name]);
      } else if (id) {
        UniViewJSBridge.on(`uni-${name}-${pageId}-${id}`, listeners[name]);
      }
    }
  });
}
function _removeListeners(id, listeners, watch2) {
  const pageId = useCurrentPageId();
  if (watch2 && !id) {
    return;
  }
  if (!isPlainObject(listeners)) {
    return;
  }
  Object.keys(listeners).forEach((name) => {
    if (watch2) {
      if (name.indexOf("@") !== 0 && name.indexOf("uni-") !== 0) {
        UniViewJSBridge.off(`uni-${name}-${pageId}-${id}`, listeners[name]);
      }
    } else {
      if (name.indexOf("uni-") === 0) {
        UniViewJSBridge.off(name, listeners[name]);
      } else if (id) {
        UniViewJSBridge.off(`uni-${name}-${pageId}-${id}`, listeners[name]);
      }
    }
  });
}
fxy060608's avatar
fxy060608 已提交
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
function entries(obj) {
  return Object.keys(obj).map((key) => [key, obj[key]]);
}
const DEFAULT_EXCLUDE_KEYS = ["class", "style"];
const LISTENER_PREFIX = /^on[A-Z]+/;
const useAttrs = (params = {}) => {
  const { excludeListeners = false, excludeKeys = [] } = params;
  const instance = getCurrentInstance();
  const attrs = shallowRef({});
  const listeners = shallowRef({});
  const excludeAttrs = shallowRef({});
  const allExcludeKeys = excludeKeys.concat(DEFAULT_EXCLUDE_KEYS);
  instance.attrs = reactive(instance.attrs);
  watchEffect(() => {
    const res = entries(instance.attrs).reduce((acc, [key, val]) => {
      if (allExcludeKeys.includes(key)) {
        acc.exclude[key] = val;
      } else if (LISTENER_PREFIX.test(key)) {
        if (!excludeListeners) {
          acc.attrs[key] = val;
        }
        acc.listeners[key] = val;
      } else {
        acc.attrs[key] = val;
      }
      return acc;
    }, {
      exclude: {},
      attrs: {},
      listeners: {}
    });
    attrs.value = res.attrs;
    listeners.value = res.listeners;
    excludeAttrs.value = res.exclude;
  });
  return { $attrs: attrs, $listeners: listeners, $excludeAttrs: excludeAttrs };
};
fxy060608's avatar
fxy060608 已提交
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
const buttonProps = {
  id: {
    type: String,
    default: ""
  },
  hoverClass: {
    type: String,
    default: "button-hover"
  },
  hoverStartTime: {
    type: [Number, String],
    default: 20
  },
  hoverStayTime: {
    type: [Number, String],
    default: 70
  },
  hoverStopPropagation: {
    type: Boolean,
    default: false
  },
  disabled: {
    type: [Boolean, String],
    default: false
  },
  formType: {
    type: String,
    default: ""
  },
  openType: {
    type: String,
    default: ""
  },
  loading: {
    type: [Boolean, String],
    default: false
  },
  plain: {
    type: [Boolean, String],
    default: false
  }
};
const buttonStyle = [{
  ub: {
fxy060608's avatar
fxy060608 已提交
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    "": {
      flexDirection: "row",
      alignItems: "center",
      justifyContent: "center",
      position: "relative",
      paddingLeft: "5",
      paddingRight: "5",
      overflow: "hidden",
      color: "#000000",
      backgroundColor: "#f8f8f8",
      borderRadius: "5",
      borderStyle: "solid",
      borderWidth: "1",
      borderColor: "#dbdbdb"
    }
fxy060608's avatar
fxy060608 已提交
331 332
  },
  "ub-t": {
fxy060608's avatar
fxy060608 已提交
333 334 335 336 337 338
    "": {
      color: "#000000",
      fontSize: "18",
      textDecoration: "none",
      lineHeight: "46"
    }
fxy060608's avatar
fxy060608 已提交
339 340
  },
  "ub-d": {
fxy060608's avatar
fxy060608 已提交
341 342 343
    "": {
      backgroundColor: "#f8f8f8"
    }
fxy060608's avatar
fxy060608 已提交
344 345
  },
  "ub-p": {
fxy060608's avatar
fxy060608 已提交
346 347 348 349
    "": {
      backgroundColor: "#007aff",
      borderColor: "#0062cc"
    }
fxy060608's avatar
fxy060608 已提交
350 351
  },
  "ub-w": {
fxy060608's avatar
fxy060608 已提交
352 353 354 355
    "": {
      backgroundColor: "#e64340",
      borderColor: "#b83633"
    }
fxy060608's avatar
fxy060608 已提交
356 357
  },
  "ub-d-t": {
fxy060608's avatar
fxy060608 已提交
358 359 360
    "": {
      color: "#000000"
    }
fxy060608's avatar
fxy060608 已提交
361 362
  },
  "ub-p-t": {
fxy060608's avatar
fxy060608 已提交
363 364 365
    "": {
      color: "#ffffff"
    }
fxy060608's avatar
fxy060608 已提交
366 367
  },
  "ub-w-t": {
fxy060608's avatar
fxy060608 已提交
368 369 370
    "": {
      color: "#ffffff"
    }
fxy060608's avatar
fxy060608 已提交
371 372
  },
  "ub-d-d": {
fxy060608's avatar
fxy060608 已提交
373 374 375
    "": {
      backgroundColor: "#f7f7f7"
    }
fxy060608's avatar
fxy060608 已提交
376 377
  },
  "ub-p-d": {
fxy060608's avatar
fxy060608 已提交
378 379 380 381
    "": {
      backgroundColor: "#63acfc",
      borderColor: "#4f8aca"
    }
fxy060608's avatar
fxy060608 已提交
382 383
  },
  "ub-w-d": {
fxy060608's avatar
fxy060608 已提交
384 385 386 387
    "": {
      backgroundColor: "#ec8b89",
      borderColor: "#bd6f6e"
    }
fxy060608's avatar
fxy060608 已提交
388 389
  },
  "ub-d-t-d": {
fxy060608's avatar
fxy060608 已提交
390 391 392
    "": {
      color: "#cccccc"
    }
fxy060608's avatar
fxy060608 已提交
393 394
  },
  "ub-p-t-d": {
fxy060608's avatar
fxy060608 已提交
395 396 397
    "": {
      color: "rgba(255,255,255,0.6)"
    }
fxy060608's avatar
fxy060608 已提交
398 399
  },
  "ub-w-t-d": {
fxy060608's avatar
fxy060608 已提交
400 401 402
    "": {
      color: "rgba(255,255,255,0.6)"
    }
fxy060608's avatar
fxy060608 已提交
403 404
  },
  "ub-d-plain": {
fxy060608's avatar
fxy060608 已提交
405 406 407 408
    "": {
      borderColor: "#353535",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
409 410
  },
  "ub-p-plain": {
fxy060608's avatar
fxy060608 已提交
411 412 413 414
    "": {
      borderColor: "#007aff",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
415 416
  },
  "ub-w-plain": {
fxy060608's avatar
fxy060608 已提交
417 418 419 420
    "": {
      borderColor: "#e64340",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
421 422
  },
  "ub-d-t-plain": {
fxy060608's avatar
fxy060608 已提交
423 424 425
    "": {
      color: "#353535"
    }
fxy060608's avatar
fxy060608 已提交
426 427
  },
  "ub-p-t-plain": {
fxy060608's avatar
fxy060608 已提交
428 429 430
    "": {
      color: "#007aff"
    }
fxy060608's avatar
fxy060608 已提交
431 432
  },
  "ub-w-t-plain": {
fxy060608's avatar
fxy060608 已提交
433 434 435
    "": {
      color: "#e64340"
    }
fxy060608's avatar
fxy060608 已提交
436 437
  },
  "ub-d-d-plain": {
fxy060608's avatar
fxy060608 已提交
438 439 440 441
    "": {
      borderColor: "#c6c6c6",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
442 443
  },
  "ub-p-d-plain": {
fxy060608's avatar
fxy060608 已提交
444 445 446 447
    "": {
      borderColor: "#c6c6c6",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
448 449
  },
  "ub-w-d-plain": {
fxy060608's avatar
fxy060608 已提交
450 451 452 453
    "": {
      borderColor: "#c6c6c6",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
454 455
  },
  "ub-d-t-d-plain": {
fxy060608's avatar
fxy060608 已提交
456 457 458
    "": {
      color: "rgba(0,0,0,0.2)"
    }
fxy060608's avatar
fxy060608 已提交
459 460
  },
  "ub-p-t-d-plain": {
fxy060608's avatar
fxy060608 已提交
461 462 463
    "": {
      color: "rgba(0,0,0,0.2)"
    }
fxy060608's avatar
fxy060608 已提交
464 465
  },
  "ub-w-t-d-plain": {
fxy060608's avatar
fxy060608 已提交
466 467 468
    "": {
      color: "rgba(0,0,0,0.2)"
    }
fxy060608's avatar
fxy060608 已提交
469 470
  },
  "ub-mini": {
fxy060608's avatar
fxy060608 已提交
471 472 473 474 475 476 477 478
    "": {
      lineHeight: "30",
      fontSize: "13",
      paddingTop: 0,
      paddingRight: "17.5",
      paddingBottom: 0,
      paddingLeft: "17.5"
    }
fxy060608's avatar
fxy060608 已提交
479 480
  },
  "ub-loading": {
fxy060608's avatar
fxy060608 已提交
481 482 483 484 485
    "": {
      width: "18",
      height: "18",
      marginRight: "10"
    }
fxy060608's avatar
fxy060608 已提交
486 487
  },
  "ub-d-loading": {
fxy060608's avatar
fxy060608 已提交
488 489 490 491
    "": {
      color: "rgba(255,255,255,0.6)",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
492 493
  },
  "ub-p-loading": {
fxy060608's avatar
fxy060608 已提交
494 495 496 497
    "": {
      color: "rgba(255,255,255,0.6)",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
498 499
  },
  "ub-w-loading": {
fxy060608's avatar
fxy060608 已提交
500 501 502 503
    "": {
      color: "rgba(255,255,255,0.6)",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
504 505
  },
  "ub-d-loading-plain": {
fxy060608's avatar
fxy060608 已提交
506 507 508
    "": {
      color: "#353535"
    }
fxy060608's avatar
fxy060608 已提交
509 510
  },
  "ub-p-loading-plain": {
fxy060608's avatar
fxy060608 已提交
511 512 513 514
    "": {
      color: "#007aff",
      backgroundColor: "#0062cc"
    }
fxy060608's avatar
fxy060608 已提交
515 516
  },
  "ub-w-loading-plain": {
fxy060608's avatar
fxy060608 已提交
517 518 519 520
    "": {
      color: "#e64340",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
521 522
  },
  "ub-d-hover": {
fxy060608's avatar
fxy060608 已提交
523 524 525 526
    "": {
      opacity: 0.8,
      backgroundColor: "#dedede"
    }
fxy060608's avatar
fxy060608 已提交
527 528
  },
  "ub-p-hover": {
fxy060608's avatar
fxy060608 已提交
529 530 531 532
    "": {
      opacity: 0.8,
      backgroundColor: "#0062cc"
    }
fxy060608's avatar
fxy060608 已提交
533 534
  },
  "ub-w-hover": {
fxy060608's avatar
fxy060608 已提交
535 536 537 538
    "": {
      opacity: 0.8,
      backgroundColor: "#ce3c39"
    }
fxy060608's avatar
fxy060608 已提交
539 540
  },
  "ub-d-t-hover": {
fxy060608's avatar
fxy060608 已提交
541 542 543
    "": {
      color: "rgba(0,0,0,0.6)"
    }
fxy060608's avatar
fxy060608 已提交
544 545
  },
  "ub-p-t-hover": {
fxy060608's avatar
fxy060608 已提交
546 547 548
    "": {
      color: "rgba(255,255,255,0.6)"
    }
fxy060608's avatar
fxy060608 已提交
549 550
  },
  "ub-w-t-hover": {
fxy060608's avatar
fxy060608 已提交
551 552 553
    "": {
      color: "rgba(255,255,255,0.6)"
    }
fxy060608's avatar
fxy060608 已提交
554 555
  },
  "ub-d-hover-plain": {
fxy060608's avatar
fxy060608 已提交
556 557 558 559 560
    "": {
      color: "rgba(53,53,53,0.6)",
      borderColor: "rgba(53,53,53,0.6)",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
561 562
  },
  "ub-p-hover-plain": {
fxy060608's avatar
fxy060608 已提交
563 564 565 566 567
    "": {
      color: "rgba(26,173,25,0.6)",
      borderColor: "rgba(0,122,255,0.6)",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
568 569
  },
  "ub-w-hover-plain": {
fxy060608's avatar
fxy060608 已提交
570 571 572 573 574
    "": {
      color: "rgba(230,67,64,0.6)",
      borderColor: "rgba(230,67,64,0.6)",
      backgroundColor: "rgba(0,0,0,0)"
    }
fxy060608's avatar
fxy060608 已提交
575 576 577 578 579 580 581 582
  }
}];
const TYPES = {
  default: "d",
  primary: "p",
  warn: "w"
};
var Button = defineComponent({
fxy060608's avatar
fxy060608 已提交
583
  inheritAttrs: false,
fxy060608's avatar
fxy060608 已提交
584 585 586 587 588 589 590 591 592 593 594 595
  name: "Button",
  props: extend(buttonProps, {
    type: {
      type: String,
      default: "default"
    },
    size: {
      type: String,
      default: "default"
    }
  }),
  styles: buttonStyle,
fxy060608's avatar
fxy060608 已提交
596
  setup(props, {
fxy060608's avatar
fxy060608 已提交
597 598 599
    slots,
    attrs
  }) {
fxy060608's avatar
fxy060608 已提交
600 601 602 603 604 605 606
    const {
      $attrs,
      $excludeAttrs,
      $listeners
    } = useAttrs({
      excludeListeners: true
    });
fxy060608's avatar
fxy060608 已提交
607
    const type = props.type;
fxy060608's avatar
fxy060608 已提交
608 609
    const rootRef = ref(null);
    const onClick = (e2, isLabelClick) => {
fxy060608's avatar
fxy060608 已提交
610 611
      const _onClick = $listeners.value.onClick || (() => {
      });
fxy060608's avatar
fxy060608 已提交
612
      if (props.disabled) {
fxy060608's avatar
fxy060608 已提交
613 614
        return;
      }
fxy060608's avatar
fxy060608 已提交
615
      _onClick(e2);
fxy060608's avatar
fxy060608 已提交
616 617 618
    };
    const _getClass = (t2) => {
      let cl = "ub-" + TYPES[type] + t2;
fxy060608's avatar
fxy060608 已提交
619 620 621
      props.disabled && (cl += "-d");
      props.plain && (cl += "-plain");
      props.size === "mini" && t2 === "-t" && (cl += " ub-mini");
fxy060608's avatar
fxy060608 已提交
622 623 624
      return cl;
    };
    const _getHoverClass = (t2) => {
fxy060608's avatar
fxy060608 已提交
625
      if (props.disabled) {
fxy060608's avatar
fxy060608 已提交
626 627 628
        return "";
      }
      let cl = "ub-" + TYPES[type] + t2 + "-hover";
fxy060608's avatar
fxy060608 已提交
629
      props.plain && (cl += "-plain");
fxy060608's avatar
fxy060608 已提交
630 631 632 633 634 635 636 637 638
      return cl;
    };
    const uniLabel = inject(uniLabelKey, false);
    if (uniLabel) {
      uniLabel.addHandler(onClick);
      onBeforeUnmount(() => {
        uniLabel.removeHandler(onClick);
      });
    }
fxy060608's avatar
fxy060608 已提交
639
    useListeners(props, {
fxy060608's avatar
fxy060608 已提交
640 641
      "label-click": onClick
    });
fxy060608's avatar
fxy060608 已提交
642 643 644 645 646 647 648 649 650
    const _listeners = computed(() => {
      const obj = {};
      for (const eventName in $listeners.value) {
        const event = $listeners.value[eventName];
        if (eventName !== "onClick")
          obj[eventName] = event;
      }
      return obj;
    });
fxy060608's avatar
fxy060608 已提交
651 652 653
    const wrapSlots = () => {
      if (!slots.default)
        return [];
fxy060608's avatar
fxy060608 已提交
654 655 656 657 658 659 660
      const vnodes = slots.default();
      if (vnodes.length === 1 && vnodes[0].type === Text) {
        return [createNVueTextVNode(vnodes[0].children, {
          class: "ub-t " + _getClass("-t")
        })];
      }
      return vnodes;
fxy060608's avatar
fxy060608 已提交
661 662
    };
    return () => {
fxy060608's avatar
fxy060608 已提交
663 664 665
      const _attrs = extend({}, useHoverClass(props), {
        hoverClass: _getHoverClass("")
      }, $attrs.value, $excludeAttrs.value, _listeners.value);
D
DCloud_LXH 已提交
666
      return createVNode("view", mergeProps({
fxy060608's avatar
fxy060608 已提交
667
        "ref": rootRef,
fxy060608's avatar
fxy060608 已提交
668
        "class": ["ub", _getClass("")],
fxy060608's avatar
fxy060608 已提交
669
        "onClick": onClick
fxy060608's avatar
fxy060608 已提交
670
      }, _attrs), [props.loading ? createVNode("loading-indicator", mergeProps({
fxy060608's avatar
fxy060608 已提交
671 672 673 674 675 676 677 678
        "class": ["ub-loading", `ub-${TYPES[type]}-loading`]
      }, {
        arrow: "false",
        animating: "true"
      }), null) : null, ...wrapSlots()]);
    };
  }
});
fxy060608's avatar
fxy060608 已提交
679
const movableAreaProps = {
fxy060608's avatar
fxy060608 已提交
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
  scaleArea: {
    type: Boolean,
    default: false
  }
};
function flatVNode(nodes) {
  const array = [];
  if (Array.isArray(nodes)) {
    nodes.forEach((vnode) => {
      if (isVNode(vnode)) {
        if (vnode.type === Fragment) {
          array.push(...flatVNode(vnode.children));
        } else {
          array.push(vnode);
        }
      } else if (Array.isArray(vnode)) {
        array.push(...flatVNode(vnode));
      }
    });
  }
  return array;
}
const getComponentSize = (el) => {
  const dom = weex.requireModule("dom");
  return new Promise((resolve) => {
    dom.getComponentRect(el, ({ size }) => {
      resolve(size);
    });
  });
};
var MovableArea = defineComponent({
  name: "MovableArea",
fxy060608's avatar
fxy060608 已提交
712
  props: movableAreaProps,
fxy060608's avatar
fxy060608 已提交
713 714 715 716 717 718
  styles: [{
    "uni-movable-area": {
      width: "10px",
      height: "10px"
    }
  }],
fxy060608's avatar
fxy060608 已提交
719
  setup(props, {
fxy060608's avatar
fxy060608 已提交
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
    slots
  }) {
    const width = ref(0);
    const height = ref(0);
    const top = ref(0);
    const left = ref(0);
    const _isMounted = ref(false);
    const rootRef = ref(null);
    const originMovableViewContexts = [];
    let touchMovableView = null;
    const setTouchMovableViewContext = (movableview) => {
      touchMovableView = movableview;
    };
    const _getWH = () => {
      return getComponentSize(rootRef.value).then(({
        width: _width,
        height: _height,
        top: _top,
        left: _left
      }) => {
        width.value = _width;
        height.value = _height;
        top.value = _top;
        left.value = _left;
      });
    };
    const _resize = () => {
      _getWH().then(() => {
        originMovableViewContexts.forEach(function(item) {
          item.setParent();
        });
      });
    };
    onMounted(() => {
      setTimeout(() => {
        _isMounted.value = true;
        _resize();
      }, 200);
    });
    const listeners = {
      onPanstart(e2) {
        touchMovableView && touchMovableView.touchstart(e2);
      },
      onPanmove(e2) {
        e2.stopPropagation();
        touchMovableView && touchMovableView.touchmove(e2);
      },
      onPanend(e2) {
        touchMovableView && touchMovableView.touchend(e2);
      }
    };
    const addMovableViewContext = (movableViewContext) => {
      originMovableViewContexts.push(movableViewContext);
    };
    const removeMovableViewContext = (movableViewContext) => {
      const index = originMovableViewContexts.indexOf(movableViewContext);
      if (index >= 0) {
        originMovableViewContexts.splice(index, 1);
      }
    };
    provide("_isMounted", _isMounted);
    provide("parentSize", {
      width,
      height,
      top,
      left
    });
    provide("addMovableViewContext", addMovableViewContext);
    provide("removeMovableViewContext", removeMovableViewContext);
    provide("setTouchMovableViewContext", setTouchMovableViewContext);
    return () => {
      const defaultSlots = slots.default && slots.default();
      const movableViewItems = flatVNode(defaultSlots);
fxy060608's avatar
fxy060608 已提交
793 794
      return createVNode("div", mergeProps({
        "ref": rootRef,
fxy060608's avatar
fxy060608 已提交
795 796 797 798 799
        "class": "uni-movable-area"
      }, listeners), [movableViewItems]);
    };
  }
});
D
DCloud_LXH 已提交
800 801 802 803 804 805
function useTouchtrack(method) {
  const __event = {};
  function callback(type, $event) {
    if (__event[type]) {
      __event[type]($event);
    }
fxy060608's avatar
fxy060608 已提交
806
  }
D
DCloud_LXH 已提交
807 808 809 810 811 812 813
  function addListener(type, callback2) {
    __event[type] = function($event) {
      if (typeof callback2 === "function") {
        $event.touches = $event.changedTouches;
        if (callback2($event) === false) {
          $event.stopPropagation();
        }
fxy060608's avatar
fxy060608 已提交
814
      }
D
DCloud_LXH 已提交
815 816
    };
  }
fxy060608's avatar
fxy060608 已提交
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
  let x0 = 0;
  let y0 = 0;
  let x1 = 0;
  let y1 = 0;
  const fn = function($event, state, x, y) {
    if (method({
      target: $event.target,
      currentTarget: $event.currentTarget,
      stopPropagation: $event.stopPropagation.bind($event),
      touches: $event.touches,
      changedTouches: $event.changedTouches,
      detail: {
        state,
        x,
        y,
        dx: x - x0,
        dy: y - y0,
        ddx: x - x1,
        ddy: y - y1,
        timeStamp: $event.timeStamp || Date.now()
      }
    }) === false) {
      return false;
    }
  };
  let $eventOld = null;
  addListener("touchstart", function($event) {
    if (!$eventOld) {
      $eventOld = $event;
      x0 = x1 = $event.touches[0].pageX;
      y0 = y1 = $event.touches[0].pageY;
      return fn($event, "start", x0, y0);
    }
  });
  addListener("touchmove", function($event) {
    if ($eventOld) {
      const res = fn($event, "move", $event.touches[0].pageX, $event.touches[0].pageY);
      x1 = $event.touches[0].pageX;
      y1 = $event.touches[0].pageY;
      return res;
    }
  });
  addListener("touchend", function($event) {
    if ($eventOld) {
      $eventOld = null;
      return fn($event, "end", $event.changedTouches[0].pageX, $event.changedTouches[0].pageY);
    }
  });
D
DCloud_LXH 已提交
865 866 867 868 869 870 871 872 873 874 875
  return {
    touchstart: function($event) {
      callback("touchstart", $event);
    },
    touchmove: function($event) {
      callback("touchmove", $event);
    },
    touchend: function($event) {
      callback("touchend", $event);
    }
  };
fxy060608's avatar
fxy060608 已提交
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
}
function useCustomEvent(ref2, emit) {
  return (name, detail) => {
    if (ref2.value) {
      emit(name, normalizeCustomEvent(name, ref2.value, detail || {}));
    }
  };
}
function normalizeCustomEvent(name, target, detail = {}) {
  target = processTarget(target);
  return {
    type: name,
    timeStamp: Date.now(),
    target,
    currentTarget: target,
    detail
  };
}
const firstLetterToLowerCase = cacheStringFunction((str) => {
  return str.charAt(0).toLowerCase() + str.slice(1);
});
function processTarget(weexTarget) {
  const { offsetLeft, offsetTop } = weexTarget;
  const attr = weexTarget.attr;
  const dataset = {};
  Object.keys(attr || {}).forEach((key) => {
    if (key.indexOf("data") === 0) {
      dataset[firstLetterToLowerCase(key.replace("data", ""))] = attr[key];
    }
  });
  return {
    id: attr && attr.id || "",
    dataset,
    offsetLeft: offsetLeft || 0,
    offsetTop: offsetTop || 0
  };
}
function e(e2, t2, n) {
  return e2 > t2 - n && e2 < t2 + n;
}
function t(t2, n) {
  return e(t2, 0, n);
}
function Decline() {
}
Decline.prototype.x = function(e2) {
  return Math.sqrt(e2);
};
function Friction(e2, t2) {
  this._m = e2;
  this._f = 1e3 * t2;
  this._startTime = 0;
  this._v = 0;
}
Friction.prototype.setV = function(x, y) {
  const n = Math.pow(Math.pow(x, 2) + Math.pow(y, 2), 0.5);
  this._x_v = x;
  this._y_v = y;
  this._x_a = -this._f * this._x_v / n;
  this._y_a = -this._f * this._y_v / n;
  this._t = Math.abs(x / this._x_a) || Math.abs(y / this._y_a);
  this._lastDt = null;
  this._startTime = new Date().getTime();
};
Friction.prototype.setS = function(x, y) {
  this._x_s = x;
  this._y_s = y;
};
Friction.prototype.s = function(t2) {
  if (t2 === void 0) {
    t2 = (new Date().getTime() - this._startTime) / 1e3;
  }
  if (t2 > this._t) {
    t2 = this._t;
    this._lastDt = t2;
  }
  let x = this._x_v * t2 + 0.5 * this._x_a * Math.pow(t2, 2) + this._x_s;
  let y = this._y_v * t2 + 0.5 * this._y_a * Math.pow(t2, 2) + this._y_s;
  if (this._x_a > 0 && x < this._endPositionX || this._x_a < 0 && x > this._endPositionX) {
    x = this._endPositionX;
  }
  if (this._y_a > 0 && y < this._endPositionY || this._y_a < 0 && y > this._endPositionY) {
    y = this._endPositionY;
  }
  return {
    x,
    y
  };
};
Friction.prototype.ds = function(t2) {
  if (t2 === void 0) {
    t2 = (new Date().getTime() - this._startTime) / 1e3;
  }
  if (t2 > this._t) {
    t2 = this._t;
  }
  return {
    dx: this._x_v + this._x_a * t2,
    dy: this._y_v + this._y_a * t2
  };
};
Friction.prototype.delta = function() {
  return {
    x: -1.5 * Math.pow(this._x_v, 2) / this._x_a || 0,
    y: -1.5 * Math.pow(this._y_v, 2) / this._y_a || 0
  };
};
Friction.prototype.dt = function() {
  return -this._x_v / this._x_a;
};
Friction.prototype.done = function() {
  const t2 = e(this.s().x, this._endPositionX) || e(this.s().y, this._endPositionY) || this._lastDt === this._t;
  this._lastDt = null;
  return t2;
};
Friction.prototype.setEnd = function(x, y) {
  this._endPositionX = x;
  this._endPositionY = y;
};
Friction.prototype.reconfigure = function(m, f) {
  this._m = m;
  this._f = 1e3 * f;
};
function Spring(m, k, c) {
  this._m = m;
  this._k = k;
  this._c = c;
  this._solution = null;
  this._endPosition = 0;
  this._startTime = 0;
}
Spring.prototype._solve = function(e2, t2) {
  const n = this._c;
  const i = this._m;
  const r = this._k;
  const o = n * n - 4 * i * r;
  if (o === 0) {
    const a = -n / (2 * i);
    const s = e2;
    const l = t2 / (a * e2);
    return {
      x: function(e3) {
        return (s + l * e3) * Math.pow(Math.E, a * e3);
      },
      dx: function(e3) {
        const t3 = Math.pow(Math.E, a * e3);
        return a * (s + l * e3) * t3 + l * t3;
      }
    };
  }
  if (o > 0) {
    const c = (-n - Math.sqrt(o)) / (2 * i);
    const u = (-n + Math.sqrt(o)) / (2 * i);
    const d = (t2 - c * e2) / (u - c);
    const h = e2 - d;
    return {
      x: function(e3) {
        let t3;
        let n2;
        if (e3 === this._t) {
          t3 = this._powER1T;
          n2 = this._powER2T;
        }
        this._t = e3;
        if (!t3) {
          t3 = this._powER1T = Math.pow(Math.E, c * e3);
        }
        if (!n2) {
          n2 = this._powER2T = Math.pow(Math.E, u * e3);
        }
        return h * t3 + d * n2;
      },
      dx: function(e3) {
        let t3;
        let n2;
        if (e3 === this._t) {
          t3 = this._powER1T;
          n2 = this._powER2T;
        }
        this._t = e3;
        if (!t3) {
          t3 = this._powER1T = Math.pow(Math.E, c * e3);
        }
        if (!n2) {
          n2 = this._powER2T = Math.pow(Math.E, u * e3);
        }
        return h * c * t3 + d * u * n2;
      }
    };
  }
  const p = Math.sqrt(4 * i * r - n * n) / (2 * i);
  const f = -n / 2 * i;
  const v2 = e2;
  const g2 = (t2 - f * e2) / p;
  return {
    x: function(e3) {
      return Math.pow(Math.E, f * e3) * (v2 * Math.cos(p * e3) + g2 * Math.sin(p * e3));
    },
    dx: function(e3) {
      const t3 = Math.pow(Math.E, f * e3);
      const n2 = Math.cos(p * e3);
      const i2 = Math.sin(p * e3);
      return t3 * (g2 * p * n2 - v2 * p * i2) + f * t3 * (g2 * i2 + v2 * n2);
    }
  };
};
Spring.prototype.x = function(e2) {
  if (e2 === void 0) {
    e2 = (new Date().getTime() - this._startTime) / 1e3;
  }
  return this._solution ? this._endPosition + this._solution.x(e2) : 0;
};
Spring.prototype.dx = function(e2) {
  if (e2 === void 0) {
    e2 = (new Date().getTime() - this._startTime) / 1e3;
  }
  return this._solution ? this._solution.dx(e2) : 0;
};
Spring.prototype.setEnd = function(e2, n, i) {
  if (!i) {
    i = new Date().getTime();
  }
  if (e2 !== this._endPosition || !t(n, 0.1)) {
    n = n || 0;
    let r = this._endPosition;
    if (this._solution) {
      if (t(n, 0.1)) {
        n = this._solution.dx((i - this._startTime) / 1e3);
      }
      r = this._solution.x((i - this._startTime) / 1e3);
      if (t(n, 0.1)) {
        n = 0;
      }
      if (t(r, 0.1)) {
        r = 0;
      }
      r += this._endPosition;
    }
    if (!(this._solution && t(r - e2, 0.1) && t(n, 0.1))) {
      this._endPosition = e2;
      this._solution = this._solve(r - this._endPosition, n);
      this._startTime = i;
    }
  }
};
Spring.prototype.snap = function(e2) {
  this._startTime = new Date().getTime();
  this._endPosition = e2;
  this._solution = {
    x: function() {
      return 0;
    },
    dx: function() {
      return 0;
    }
  };
};
Spring.prototype.done = function(n) {
  if (!n) {
    n = new Date().getTime();
  }
  return e(this.x(), this._endPosition, 0.1) && t(this.dx(), 0.1);
};
Spring.prototype.reconfigure = function(m, t2, c) {
  this._m = m;
  this._k = t2;
  this._c = c;
  if (!this.done()) {
    this._solution = this._solve(this.x() - this._endPosition, this.dx());
    this._startTime = new Date().getTime();
  }
};
Spring.prototype.springConstant = function() {
  return this._k;
};
Spring.prototype.damping = function() {
  return this._c;
};
Spring.prototype.configuration = function() {
  function e2(e3, t3) {
    e3.reconfigure(1, t3, e3.damping());
  }
  function t2(e3, t3) {
    e3.reconfigure(1, e3.springConstant(), t3);
  }
  return [
    {
      label: "Spring Constant",
      read: this.springConstant.bind(this),
      write: e2.bind(this, this),
      min: 100,
      max: 1e3
    },
    {
      label: "Damping",
      read: this.damping.bind(this),
      write: t2.bind(this, this),
      min: 1,
      max: 500
    }
  ];
};
function STD(e2, t2, n) {
  this._springX = new Spring(e2, t2, n);
  this._springY = new Spring(e2, t2, n);
  this._springScale = new Spring(e2, t2, n);
  this._startTime = 0;
}
STD.prototype.setEnd = function(e2, t2, n, i) {
  const r = new Date().getTime();
  this._springX.setEnd(e2, i, r);
  this._springY.setEnd(t2, i, r);
  this._springScale.setEnd(n, i, r);
  this._startTime = r;
};
STD.prototype.x = function() {
  const e2 = (new Date().getTime() - this._startTime) / 1e3;
  return {
    x: this._springX.x(e2),
    y: this._springY.x(e2),
    scale: this._springScale.x(e2)
  };
};
STD.prototype.done = function() {
  const e2 = new Date().getTime();
  return this._springX.done(e2) && this._springY.done(e2) && this._springScale.done(e2);
};
STD.prototype.reconfigure = function(e2, t2, n) {
  this._springX.reconfigure(e2, t2, n);
  this._springY.reconfigure(e2, t2, n);
  this._springScale.reconfigure(e2, t2, n);
};
fxy060608's avatar
fxy060608 已提交
1208
const movableViewProps = {
fxy060608's avatar
fxy060608 已提交
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
  direction: {
    type: String,
    default: "none"
  },
  inertia: {
    type: [Boolean, String],
    default: false
  },
  outOfBounds: {
    type: [Boolean, String],
    default: false
  },
  x: {
    type: [Number, String],
    default: 0
  },
  y: {
    type: [Number, String],
    default: 0
  },
  damping: {
    type: [Number, String],
    default: 20
  },
  friction: {
    type: [Number, String],
    default: 2
  },
  disabled: {
    type: [Boolean, String],
    default: false
  },
  scale: {
    type: [Boolean, String],
    default: false
  },
  scaleMin: {
    type: [Number, String],
    default: 0.5
  },
  scaleMax: {
    type: [Number, String],
    default: 10
  },
  scaleValue: {
    type: [Number, String],
    default: 1
  },
  animation: {
    type: [Boolean, String],
    default: true
  }
};
function v(a, b) {
  return +((1e3 * a - 1e3 * b) / 1e3).toFixed(1);
}
function g(friction, execute, endCallback) {
  let record = {
    id: 0,
    cancelled: false
  };
  let cancel = function(record2) {
    if (record2 && record2.id) {
      cancelAnimationFrame(record2.id);
    }
    if (record2) {
      record2.cancelled = true;
    }
  };
  function fn(record2, friction2, execute2, endCallback2) {
    if (!record2 || !record2.cancelled) {
      execute2(friction2);
      let isDone = friction2.done();
      if (!isDone) {
        if (!record2.cancelled) {
          record2.id = requestAnimationFrame(fn.bind(null, record2, friction2, execute2, endCallback2));
        }
      }
      if (isDone && endCallback2) {
        endCallback2(friction2);
      }
    }
  }
  fn(record, friction, execute, endCallback);
  return {
    cancel: cancel.bind(null, record),
    model: friction
  };
}
let requesting = false;
function _requestAnimationFrame(e2) {
  if (!requesting) {
    requesting = true;
    requestAnimationFrame(function() {
      e2();
      requesting = false;
    });
  }
}
D
DCloud_LXH 已提交
1308 1309
function requestAnimationFrame(callback) {
  return setTimeout(callback, 16);
fxy060608's avatar
fxy060608 已提交
1310 1311 1312 1313 1314 1315 1316
}
function cancelAnimationFrame(id) {
  clearTimeout(id);
}
const animation = weex.requireModule("animation");
var MovableView = defineComponent({
  name: "MovableView",
fxy060608's avatar
fxy060608 已提交
1317
  props: movableViewProps,
fxy060608's avatar
fxy060608 已提交
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
  emits: ["change", "scale"],
  styles: [{
    "uni-movable-view": {
      position: "absolute",
      top: "0px",
      left: "0px",
      width: "10px",
      height: "10px"
    }
  }],
fxy060608's avatar
fxy060608 已提交
1328
  setup(props, {
fxy060608's avatar
fxy060608 已提交
1329 1330 1331 1332 1333 1334 1335
    emit,
    slots
  }) {
    const rootRef = ref(null);
    const trigger = useCustomEvent(rootRef, emit);
    const setTouchMovableViewContext = inject("setTouchMovableViewContext", () => {
    });
D
DCloud_LXH 已提交
1336
    const touchStart = useMovableViewState(props, trigger, rootRef, setTouchMovableViewContext);
fxy060608's avatar
fxy060608 已提交
1337 1338 1339 1340
    return () => {
      const attrs = {
        preventGesture: true
      };
fxy060608's avatar
fxy060608 已提交
1341
      return createVNode("view", mergeProps({
fxy060608's avatar
fxy060608 已提交
1342 1343 1344 1345 1346 1347 1348 1349
        "ref": rootRef,
        "onTouchstart": touchStart,
        "class": "uni-movable-view",
        "style": "transform-origin: center;"
      }, attrs), [slots.default && slots.default()]);
    };
  }
});
D
DCloud_LXH 已提交
1350
function useMovableViewState(props, trigger, rootRef, setTouchMovableViewContext) {
fxy060608's avatar
fxy060608 已提交
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
  const _isMounted = inject("_isMounted", ref(false));
  const parentSize = inject("parentSize", {
    width: ref(0),
    height: ref(0),
    top: ref(0),
    left: ref(0)
  });
  const addMovableViewContext = inject("addMovableViewContext", () => {
  });
  const removeMovableViewContext = inject("removeMovableViewContext", () => {
  });
D
DCloud_LXH 已提交
1362 1363 1364 1365 1366 1367 1368 1369
  let movableViewContext = {
    touchstart: () => {
    },
    touchmove: () => {
    },
    touchend: () => {
    }
  };
fxy060608's avatar
fxy060608 已提交
1370 1371 1372 1373 1374 1375 1376
  function _getPx(val) {
    return Number(val) || 0;
  }
  function _getScaleNumber(val) {
    val = Number(val);
    return isNaN(val) ? 1 : val;
  }
fxy060608's avatar
fxy060608 已提交
1377 1378 1379
  const xSync = ref(_getPx(props.x));
  const ySync = ref(_getPx(props.y));
  const scaleValueSync = ref(_getScaleNumber(Number(props.scaleValue)));
fxy060608's avatar
fxy060608 已提交
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417
  const width = ref(0);
  const height = ref(0);
  const minX = ref(0);
  const minY = ref(0);
  const maxX = ref(0);
  const maxY = ref(0);
  let _SFA = null;
  let _FA = null;
  const _offset = {
    x: 0,
    y: 0
  };
  const _scaleOffset = {
    x: 0,
    y: 0
  };
  let _scale = 1;
  let _translateX = 0;
  let _translateY = 0;
  let _isTouching = false;
  let __baseX;
  let __baseY;
  let _checkCanMove = null;
  let _firstMoveDirection = null;
  let _rect = {
    top: 0,
    left: 0,
    width: 0,
    height: 0
  };
  const _declineX = new Decline();
  const _declineY = new Decline();
  const __touchInfo = {
    historyX: [0, 0],
    historyY: [0, 0],
    historyT: [0, 0]
  };
  const dampingNumber = computed(() => {
fxy060608's avatar
fxy060608 已提交
1418
    let val = Number(props.damping);
fxy060608's avatar
fxy060608 已提交
1419 1420 1421
    return isNaN(val) ? 20 : val;
  });
  const frictionNumber = computed(() => {
fxy060608's avatar
fxy060608 已提交
1422
    let val = Number(props.friction);
fxy060608's avatar
fxy060608 已提交
1423 1424 1425
    return isNaN(val) || val <= 0 ? 2 : val;
  });
  const scaleMinNumber = computed(() => {
fxy060608's avatar
fxy060608 已提交
1426
    let val = Number(props.scaleMin);
fxy060608's avatar
fxy060608 已提交
1427 1428 1429
    return isNaN(val) ? 0.5 : val;
  });
  const scaleMaxNumber = computed(() => {
fxy060608's avatar
fxy060608 已提交
1430
    let val = Number(props.scaleMax);
fxy060608's avatar
fxy060608 已提交
1431 1432
    return isNaN(val) ? 10 : val;
  });
fxy060608's avatar
fxy060608 已提交
1433 1434
  const xMove = computed(() => props.direction === "all" || props.direction === "horizontal");
  const yMove = computed(() => props.direction === "all" || props.direction === "vertical");
fxy060608's avatar
fxy060608 已提交
1435 1436
  const _STD = new STD(1, 9 * Math.pow(dampingNumber.value, 2) / 40, dampingNumber.value);
  const _friction = new Friction(1, frictionNumber.value);
fxy060608's avatar
fxy060608 已提交
1437
  watch(() => props.x, (val) => {
fxy060608's avatar
fxy060608 已提交
1438 1439
    xSync.value = _getPx(val);
  });
fxy060608's avatar
fxy060608 已提交
1440
  watch(() => props.y, (val) => {
fxy060608's avatar
fxy060608 已提交
1441 1442
    ySync.value = _getPx(val);
  });
fxy060608's avatar
fxy060608 已提交
1443
  watch(() => props.scaleValue, (val) => {
fxy060608's avatar
fxy060608 已提交
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485
    scaleValueSync.value = _getScaleNumber(Number(val));
  });
  watch(xSync, _setX);
  watch(ySync, _setY);
  watch(scaleValueSync, _setScaleValue);
  watch(scaleMinNumber, _setScaleMinOrMax);
  watch(scaleMaxNumber, _setScaleMinOrMax);
  function FAandSFACancel() {
    if (_FA) {
      _FA.cancel();
    }
    if (_SFA) {
      _SFA.cancel();
    }
  }
  function _setX(val) {
    if (xMove.value) {
      if (val + _scaleOffset.x === _translateX) {
        return _translateX;
      } else {
        if (_SFA) {
          _SFA.cancel();
        }
        _animationTo(val + _scaleOffset.x, ySync.value + _scaleOffset.y, _scale);
      }
    }
    return val;
  }
  function _setY(val) {
    if (yMove.value) {
      if (val + _scaleOffset.y === _translateY) {
        return _translateY;
      } else {
        if (_SFA) {
          _SFA.cancel();
        }
        _animationTo(xSync.value + _scaleOffset.x, val + _scaleOffset.y, _scale);
      }
    }
    return val;
  }
  function _setScaleMinOrMax() {
fxy060608's avatar
fxy060608 已提交
1486
    if (!props.scale) {
fxy060608's avatar
fxy060608 已提交
1487 1488 1489 1490 1491
      return false;
    }
    _updateScale(_scale, true);
  }
  function _setScaleValue(scale) {
fxy060608's avatar
fxy060608 已提交
1492
    if (!props.scale) {
fxy060608's avatar
fxy060608 已提交
1493 1494 1495 1496 1497 1498 1499 1500
      return false;
    }
    scale = _adjustScale(scale);
    _updateScale(scale, true);
    return scale;
  }
  function __handleTouchStart() {
    {
fxy060608's avatar
fxy060608 已提交
1501
      if (!props.disabled) {
fxy060608's avatar
fxy060608 已提交
1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518
        FAandSFACancel();
        __touchInfo.historyX = [0, 0];
        __touchInfo.historyY = [0, 0];
        __touchInfo.historyT = [0, 0];
        if (xMove.value) {
          __baseX = _translateX;
        }
        if (yMove.value) {
          __baseY = _translateY;
        }
        _checkCanMove = null;
        _firstMoveDirection = null;
        _isTouching = true;
      }
    }
  }
  function __handleTouchMove(event) {
fxy060608's avatar
fxy060608 已提交
1519
    if (!props.disabled && _isTouching) {
fxy060608's avatar
fxy060608 已提交
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545
      let x = _translateX;
      let y = _translateY;
      if (_firstMoveDirection === null) {
        _firstMoveDirection = Math.abs(event.detail.dx / event.detail.dy) > 1 ? "htouchmove" : "vtouchmove";
      }
      if (xMove.value) {
        x = event.detail.dx + __baseX;
        __touchInfo.historyX.shift();
        __touchInfo.historyX.push(x);
        if (!yMove.value && _checkCanMove === null) {
          _checkCanMove = Math.abs(event.detail.dx / event.detail.dy) < 1;
        }
      }
      if (yMove.value) {
        y = event.detail.dy + __baseY;
        __touchInfo.historyY.shift();
        __touchInfo.historyY.push(y);
        if (!xMove.value && _checkCanMove === null) {
          _checkCanMove = Math.abs(event.detail.dy / event.detail.dx) < 1;
        }
      }
      __touchInfo.historyT.shift();
      __touchInfo.historyT.push(event.detail.timeStamp);
      if (!_checkCanMove) {
        let source = "touch";
        if (x < minX.value) {
fxy060608's avatar
fxy060608 已提交
1546
          if (props.outOfBounds) {
fxy060608's avatar
fxy060608 已提交
1547 1548 1549 1550 1551 1552
            source = "touch-out-of-bounds";
            x = minX.value - _declineX.x(minX.value - x);
          } else {
            x = minX.value;
          }
        } else if (x > maxX.value) {
fxy060608's avatar
fxy060608 已提交
1553
          if (props.outOfBounds) {
fxy060608's avatar
fxy060608 已提交
1554 1555 1556 1557 1558 1559 1560
            source = "touch-out-of-bounds";
            x = maxX.value + _declineX.x(x - maxX.value);
          } else {
            x = maxX.value;
          }
        }
        if (y < minY.value) {
fxy060608's avatar
fxy060608 已提交
1561
          if (props.outOfBounds) {
fxy060608's avatar
fxy060608 已提交
1562 1563 1564 1565 1566 1567 1568
            source = "touch-out-of-bounds";
            y = minY.value - _declineY.x(minY.value - y);
          } else {
            y = minY.value;
          }
        } else {
          if (y > maxY.value) {
fxy060608's avatar
fxy060608 已提交
1569
            if (props.outOfBounds) {
fxy060608's avatar
fxy060608 已提交
1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583
              source = "touch-out-of-bounds";
              y = maxY.value + _declineY.x(y - maxY.value);
            } else {
              y = maxY.value;
            }
          }
        }
        _requestAnimationFrame(function() {
          _setTransform(x, y, _scale, source);
        });
      }
    }
  }
  function __handleTouchEnd() {
fxy060608's avatar
fxy060608 已提交
1584
    if (!props.disabled && _isTouching) {
fxy060608's avatar
fxy060608 已提交
1585
      _isTouching = false;
fxy060608's avatar
fxy060608 已提交
1586
      if (!_checkCanMove && !_revise("out-of-bounds") && props.inertia) {
fxy060608's avatar
fxy060608 已提交
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
        const xv = 1e3 * (__touchInfo.historyX[1] - __touchInfo.historyX[0]) / (__touchInfo.historyT[1] - __touchInfo.historyT[0]);
        const yv = 1e3 * (__touchInfo.historyY[1] - __touchInfo.historyY[0]) / (__touchInfo.historyT[1] - __touchInfo.historyT[0]);
        _friction.setV(xv, yv);
        _friction.setS(_translateX, _translateY);
        const x0 = _friction.delta().x;
        const y0 = _friction.delta().y;
        let x = x0 + _translateX;
        let y = y0 + _translateY;
        if (x < minX.value) {
          x = minX.value;
          y = _translateY + (minX.value - _translateX) * y0 / x0;
        } else {
          if (x > maxX.value) {
            x = maxX.value;
            y = _translateY + (maxX.value - _translateX) * y0 / x0;
          }
        }
        if (y < minY.value) {
          y = minY.value;
          x = _translateX + (minY.value - _translateY) * x0 / y0;
        } else {
          if (y > maxY.value) {
            y = maxY.value;
            x = _translateX + (maxY.value - _translateY) * x0 / y0;
          }
        }
        _friction.setEnd(x, y);
        _FA = g(_friction, function() {
          let t2 = _friction.s();
          let x2 = t2.x;
          let y2 = t2.y;
          _setTransform(x2, y2, _scale, "friction");
        }, function() {
          _FA.cancel();
        });
      }
    }
  }
  function _getLimitXY(x, y) {
    let outOfBounds = false;
    if (x > maxX.value) {
      x = maxX.value;
      outOfBounds = true;
    } else {
      if (x < minX.value) {
        x = minX.value;
        outOfBounds = true;
      }
    }
    if (y > maxY.value) {
      y = maxY.value;
      outOfBounds = true;
    } else {
      if (y < minY.value) {
        y = minY.value;
        outOfBounds = true;
      }
    }
    return {
      x,
      y,
      outOfBounds
    };
  }
  function _updateOffset() {
    _offset.x = _rect.left - parentSize.left.value;
    _offset.y = _rect.top - parentSize.top.value;
  }
  function _updateWH(scale) {
    scale = scale || _scale;
    scale = _adjustScale(scale);
    height.value = _rect.height / _scale;
    width.value = _rect.width / _scale;
    let _height = height.value * scale;
    let _width = width.value * scale;
    _scaleOffset.x = (_width - width.value) / 2;
    _scaleOffset.y = (_height - height.value) / 2;
  }
  function _updateBoundary() {
    let x = 0 - _offset.x + _scaleOffset.x;
    let _width = parentSize.width.value - width.value - _offset.x - _scaleOffset.x;
    minX.value = Math.min(x, _width);
    maxX.value = Math.max(x, _width);
    let y = 0 - _offset.y + _scaleOffset.y;
    let _height = parentSize.height.value - height.value - _offset.y - _scaleOffset.y;
    minY.value = Math.min(y, _height);
    maxY.value = Math.max(y, _height);
  }
  function _updateScale(scale, animat) {
fxy060608's avatar
fxy060608 已提交
1676
    if (props.scale) {
fxy060608's avatar
fxy060608 已提交
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704
      scale = _adjustScale(scale);
      _updateWH(scale);
      _updateBoundary();
      const limitXY = _getLimitXY(_translateX, _translateY);
      const x = limitXY.x;
      const y = limitXY.y;
      if (animat) {
        _animationTo(x, y, scale, "", true, true);
      } else {
        _requestAnimationFrame(function() {
          _setTransform(x, y, scale, "", true, true);
        });
      }
    }
  }
  function _adjustScale(scale) {
    scale = Math.max(0.5, scaleMinNumber.value, scale);
    scale = Math.min(10, scaleMaxNumber.value, scale);
    return scale;
  }
  function _animationTo(x, y, scale, source, r, o) {
    FAandSFACancel();
    if (!xMove.value) {
      x = _translateX;
    }
    if (!yMove.value) {
      y = _translateY;
    }
fxy060608's avatar
fxy060608 已提交
1705
    if (!props.scale) {
fxy060608's avatar
fxy060608 已提交
1706 1707 1708 1709 1710
      scale = _scale;
    }
    let limitXY = _getLimitXY(x, y);
    x = limitXY.x;
    y = limitXY.y;
fxy060608's avatar
fxy060608 已提交
1711
    if (!props.animation) {
fxy060608's avatar
fxy060608 已提交
1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760
      _setTransform(x, y, scale, source, r, o);
      return;
    }
    _STD._springX._solution = null;
    _STD._springY._solution = null;
    _STD._springScale._solution = null;
    _STD._springX._endPosition = _translateX;
    _STD._springY._endPosition = _translateY;
    _STD._springScale._endPosition = _scale;
    _STD.setEnd(x, y, scale, 1);
    _SFA = g(_STD, function() {
      let data = _STD.x();
      let x2 = data.x;
      let y2 = data.y;
      let scale2 = data.scale;
      _setTransform(x2, y2, scale2, source, r, o);
    }, function() {
      _SFA.cancel();
    });
  }
  function _revise(source) {
    let limitXY = _getLimitXY(_translateX, _translateY);
    let x = limitXY.x;
    let y = limitXY.y;
    let outOfBounds = limitXY.outOfBounds;
    if (outOfBounds) {
      _animationTo(x, y, _scale, source);
    }
    return outOfBounds;
  }
  function _setTransform(x, y, scale, source = "", r, o) {
    if (!(x !== null && x.toString() !== "NaN" && typeof x === "number")) {
      x = _translateX || 0;
    }
    if (!(y !== null && y.toString() !== "NaN" && typeof y === "number")) {
      y = _translateY || 0;
    }
    x = Number(x.toFixed(1));
    y = Number(y.toFixed(1));
    scale = Number(scale.toFixed(1));
    if (!(_translateX === x && _translateY === y)) {
      if (!r) {
        trigger("change", {
          x: v(x, _scaleOffset.x),
          y: v(y, _scaleOffset.y),
          source
        });
      }
    }
fxy060608's avatar
fxy060608 已提交
1761
    if (!props.scale) {
fxy060608's avatar
fxy060608 已提交
1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794
      scale = _scale;
    }
    scale = _adjustScale(scale);
    scale = +scale.toFixed(3);
    if (o && scale !== _scale) {
      trigger("scale", {
        x,
        y,
        scale
      });
    }
    const transform = `translate(${x}px, ${y}px) scale(${scale})`;
    animation.transition(rootRef.value, {
      styles: {
        transform
      },
      duration: 0,
      delay: 0
    });
    _translateX = x;
    _translateY = y;
    _scale = scale;
  }
  function _updateRect() {
    return getComponentSize(rootRef.value).then((rect) => {
      _rect = rect;
    });
  }
  function setParent() {
    if (!_isMounted.value) {
      return;
    }
    FAandSFACancel();
fxy060608's avatar
fxy060608 已提交
1795
    let scale = props.scale ? scaleValueSync.value : 1;
fxy060608's avatar
fxy060608 已提交
1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806
    _updateOffset();
    _updateWH(scale);
    _updateBoundary();
    _translateX = xSync.value + _scaleOffset.x;
    _translateY = ySync.value + _scaleOffset.y;
    let limitXY = _getLimitXY(_translateX, _translateY);
    let x = limitXY.x;
    let y = limitXY.y;
    _setTransform(x, y, scale, "", true);
  }
  onMounted(() => {
D
DCloud_LXH 已提交
1807
    movableViewContext = useTouchtrack((event) => {
fxy060608's avatar
fxy060608 已提交
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836
      switch (event.detail.state) {
        case "start":
          __handleTouchStart();
          break;
        case "move":
          __handleTouchMove(event);
          break;
        case "end":
          __handleTouchEnd();
      }
    });
    setTimeout(() => {
      _updateRect().then(() => {
        setParent();
      });
    }, 100);
    _friction.reconfigure(1, frictionNumber.value);
    _STD.reconfigure(1, 9 * Math.pow(dampingNumber.value, 2) / 40, dampingNumber.value);
    const context = {
      setParent
    };
    addMovableViewContext(context);
    onUnmounted(() => {
      removeMovableViewContext(context);
    });
  });
  onUnmounted(() => {
    FAandSFACancel();
  });
D
DCloud_LXH 已提交
1837 1838 1839 1840
  const touchStart = () => {
    setTouchMovableViewContext(movableViewContext);
  };
  return touchStart;
fxy060608's avatar
fxy060608 已提交
1841
}
fxy060608's avatar
fxy060608 已提交
1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018
const FONT_SIZE = 16;
const PROGRESS_VALUES = {
  activeColor: PRIMARY_COLOR,
  backgroundColor: "#EBEBEB",
  activeMode: "backwards"
};
const progressProps = {
  percent: {
    type: [Number, String],
    default: 0,
    validator(value) {
      return !isNaN(parseFloat(value));
    }
  },
  fontSize: {
    type: [String, Number],
    default: FONT_SIZE
  },
  showInfo: {
    type: [Boolean, String],
    default: false
  },
  strokeWidth: {
    type: [Number, String],
    default: 6,
    validator(value) {
      return !isNaN(parseFloat(value));
    }
  },
  color: {
    type: String,
    default: PROGRESS_VALUES.activeColor
  },
  activeColor: {
    type: String,
    default: PROGRESS_VALUES.activeColor
  },
  backgroundColor: {
    type: String,
    default: PROGRESS_VALUES.backgroundColor
  },
  active: {
    type: [Boolean, String],
    default: false
  },
  activeMode: {
    type: String,
    default: PROGRESS_VALUES.activeMode
  },
  duration: {
    type: [Number, String],
    default: 30,
    validator(value) {
      return !isNaN(parseFloat(value));
    }
  }
};
const progressStyles = [{
  "uni-progress": {
    flex: 1,
    flexDirection: "row",
    alignItems: "center"
  },
  "uni-progress-bar": {
    flex: 1
  },
  "uni-progress-inner-bar": {
    position: "absolute"
  },
  "uni-progress-info": {
    marginLeft: "15px"
  }
}];
var Progress = defineComponent({
  name: "Progress",
  props: progressProps,
  styles: progressStyles,
  emits: ["activeend"],
  setup(props, {
    emit
  }) {
    const progressRef = ref(null);
    const progressBarRef = ref(null);
    const trigger = useCustomEvent(progressRef, emit);
    const state = useProgressState(props);
    watch(() => state.realPercent, (newValue, oldValue) => {
      state.lastPercent = oldValue || 0;
      _activeAnimation(state, props, trigger);
    });
    onMounted(() => {
      setTimeout(() => {
        getComponentSize(progressBarRef.value).then(({
          width
        }) => {
          state.progressWidth = width || 0;
          _activeAnimation(state, props, trigger);
        });
      }, 50);
    });
    return () => {
      const {
        showInfo,
        fontSize
      } = props;
      const {
        outerBarStyle,
        innerBarStyle,
        currentPercent
      } = state;
      return createVNode("div", {
        "ref": progressRef,
        "class": "uni-progress"
      }, [createVNode("div", {
        "ref": progressBarRef,
        "style": outerBarStyle,
        "class": "uni-progress-bar"
      }, [createVNode("div", {
        "style": innerBarStyle,
        "class": "uni-progress-inner-bar"
      }, null)]), showInfo ? createNVueTextVNode(currentPercent + "%", {
        class: "uni-progress-info",
        style: {
          fontSize
        }
      }) : null]);
    };
  }
});
function useProgressState(props) {
  const currentPercent = ref(0);
  const progressWidth = ref(0);
  const outerBarStyle = computed(() => ({
    backgroundColor: props.backgroundColor,
    height: props.strokeWidth
  }));
  const innerBarStyle = computed(() => {
    const backgroundColor = props.color !== PROGRESS_VALUES.activeColor && props.activeColor === PROGRESS_VALUES.activeColor ? props.color : props.activeColor;
    return {
      width: currentPercent.value * progressWidth.value / 100,
      height: props.strokeWidth,
      backgroundColor
    };
  });
  const realPercent = computed(() => {
    let realValue = parseFloat(props.percent);
    realValue < 0 && (realValue = 0);
    realValue > 100 && (realValue = 100);
    return realValue;
  });
  const state = reactive({
    outerBarStyle,
    innerBarStyle,
    realPercent,
    currentPercent,
    strokeTimer: 0,
    lastPercent: 0,
    progressWidth
  });
  return state;
}
function _activeAnimation(state, props, trigger) {
  state.strokeTimer && clearInterval(state.strokeTimer);
  if (props.active) {
    state.currentPercent = props.activeMode === PROGRESS_VALUES.activeMode ? 0 : state.lastPercent;
    state.strokeTimer = setInterval(() => {
      if (state.currentPercent + 1 > state.realPercent) {
        state.currentPercent = state.realPercent;
        state.strokeTimer && clearInterval(state.strokeTimer);
        trigger("activeend", {});
      } else {
        state.currentPercent += 1;
      }
    }, parseFloat(props.duration));
  } else {
    state.currentPercent = state.realPercent;
  }
}
fxy060608's avatar
fxy060608 已提交
2019
var components = {
fxy060608's avatar
fxy060608 已提交
2020 2021 2022 2023
  Navigator,
  Label,
  Button,
  MovableArea,
fxy060608's avatar
fxy060608 已提交
2024 2025
  MovableView,
  Progress
fxy060608's avatar
fxy060608 已提交
2026 2027
};
export { components as default };