@whitesev/pops 1.8.5 → 1.8.7

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.
@@ -213,6 +213,9 @@ var pops = (function () {
213
213
  return this.contains(PopsCore.document.body || PopsCore.document.documentElement, arguments[0]);
214
214
  }
215
215
  else {
216
+ if (target == null) {
217
+ return false;
218
+ }
216
219
  if (typeof target[Symbol.iterator] === "function") {
217
220
  // 可遍历的数组
218
221
  let flag = true;
@@ -4100,289 +4103,6 @@ var pops = (function () {
4100
4103
  }
4101
4104
  }
4102
4105
 
4103
- const PopsTooltipConfig = () => {
4104
- return {
4105
- // @ts-ignore
4106
- target: null,
4107
- content: "默认文字",
4108
- position: "top",
4109
- className: "",
4110
- alwaysShow: false,
4111
- triggerShowEventName: "mouseenter touchstart",
4112
- triggerCloseEventName: "mouseleave touchend",
4113
- zIndex: 10000,
4114
- only: false,
4115
- eventOption: {
4116
- passive: false,
4117
- capture: true,
4118
- once: false,
4119
- },
4120
- showBeforeCallBack() { },
4121
- showAfterCallBack() { },
4122
- closeBeforeCallBack() { },
4123
- closeAfterCallBack() { },
4124
- arrowDistance: 12.5,
4125
- otherDistance: 0,
4126
- style: "",
4127
- beforeAppendToPageCallBack() { },
4128
- };
4129
- };
4130
-
4131
- class PopsTooltip {
4132
- constructor(details) {
4133
- const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow();
4134
- PopsHandler.handleInit($shadowRoot, [
4135
- pops.config.cssText.index,
4136
- pops.config.cssText.anim,
4137
- pops.config.cssText.common,
4138
- pops.config.cssText.tooltipCSS,
4139
- ]);
4140
- let config = PopsTooltipConfig();
4141
- config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
4142
- config = popsUtils.assign(config, details);
4143
- if (!(config.target instanceof HTMLElement)) {
4144
- throw "config.target 必须是HTMLElement类型";
4145
- }
4146
- let guid = popsUtils.getRandomGUID();
4147
- const PopsType = "tooltip";
4148
- config = PopsHandler.handleOnly(PopsType, config);
4149
- function getContent() {
4150
- return typeof config.content === "function"
4151
- ? config.content()
4152
- : config.content;
4153
- }
4154
- /**
4155
- * 获取悬浮提示的元素信息
4156
- */
4157
- function getToolTipElementInfo() {
4158
- let _toolTipHTML_ = `<div class="pops-tip"></div>`;
4159
- let _toolTipElement_ = popsUtils.parseTextToDOM(_toolTipHTML_);
4160
- if (typeof config.className === "string" &&
4161
- config.className.trim() !== "") {
4162
- popsDOMUtils.addClassName(_toolTipElement_, config.className);
4163
- }
4164
- _toolTipElement_.setAttribute("data-guid", guid);
4165
- _toolTipElement_.style.zIndex = PopsHandler.handleZIndex(config.zIndex).toString();
4166
- _toolTipElement_.innerHTML = `<div style="text-align: center;">${getContent()}</div>`;
4167
- /* 箭头元素 */
4168
- let _toolTipArrowHTML_ = '<div class="pops-tip-arrow"></div>';
4169
- let _toolTipArrowNode_ = popsUtils.parseTextToDOM(_toolTipArrowHTML_);
4170
- _toolTipElement_.appendChild(_toolTipArrowNode_);
4171
- if (config.style != null) {
4172
- /* 添加自定义style */
4173
- let cssNode = document.createElement("style");
4174
- cssNode.setAttribute("type", "text/css");
4175
- cssNode.innerHTML = config.style;
4176
- _toolTipElement_.appendChild(cssNode);
4177
- }
4178
- return {
4179
- toolTipElement: _toolTipElement_,
4180
- toolTipArrowElement: _toolTipArrowNode_,
4181
- toolTipHTML: _toolTipHTML_,
4182
- toolTipArrowHTML: _toolTipArrowHTML_,
4183
- };
4184
- }
4185
- config.position =
4186
- config.position.toLowerCase();
4187
- let { toolTipElement } = getToolTipElementInfo();
4188
- /**
4189
- * 设置 提示框的位置
4190
- */
4191
- function setToolTipPosition(positionDetails) {
4192
- let positionDetail = positionDetails[config.position.toUpperCase()];
4193
- if (positionDetail) {
4194
- toolTipElement.style.left = positionDetail.left + "px";
4195
- toolTipElement.style.top = positionDetail.top + "px";
4196
- toolTipElement.setAttribute("data-motion", positionDetail.motion);
4197
- toolTipElement
4198
- .querySelector(".pops-tip-arrow")
4199
- ?.setAttribute("data-position", positionDetail.arrow);
4200
- }
4201
- else {
4202
- console.error("不存在该位置", config.position);
4203
- }
4204
- }
4205
- /**
4206
- * 获取 提示框的位置
4207
- * @param targetElement 目标元素
4208
- * @param arrowDistance 箭头和目标元素的距离
4209
- * @param otherDistance 其它位置的偏移
4210
- */
4211
- function getToolTipPosition(targetElement, arrowDistance, otherDistance) {
4212
- let targetElement_width = popsDOMUtils.offset(targetElement).width;
4213
- let targetElement_height = popsDOMUtils.offset(targetElement).height;
4214
- let targetElement_top = popsDOMUtils.offset(targetElement).top;
4215
- // let targetElement_bottom = popsDOMUtils.offset(targetElement).bottom;
4216
- let targetElement_left = popsDOMUtils.offset(targetElement).left;
4217
- // let targetElement_right = popsDOMUtils.offset(targetElement).right;
4218
- let toolTipElement_width = popsDOMUtils.outerWidth(toolTipElement);
4219
- let toolTipElement_height = popsDOMUtils.outerHeight(toolTipElement);
4220
- /* 目标元素的x轴的中间位置 */
4221
- let targetElement_X_center_pos = targetElement_left + targetElement_width / 2 - toolTipElement_width / 2;
4222
- /* 目标元素的Y轴的中间位置 */
4223
- let targetElement_Y_center_pos = targetElement_top +
4224
- targetElement_height / 2 -
4225
- toolTipElement_height / 2;
4226
- return {
4227
- TOP: {
4228
- left: targetElement_X_center_pos - otherDistance,
4229
- top: targetElement_top - toolTipElement_height - arrowDistance,
4230
- arrow: "bottom",
4231
- motion: "fadeInTop",
4232
- },
4233
- RIGHT: {
4234
- left: targetElement_left + targetElement_width + arrowDistance,
4235
- top: targetElement_Y_center_pos + otherDistance,
4236
- arrow: "left",
4237
- motion: "fadeInRight",
4238
- },
4239
- BOTTOM: {
4240
- left: targetElement_X_center_pos - otherDistance,
4241
- top: targetElement_top + targetElement_height + arrowDistance,
4242
- arrow: "top",
4243
- motion: "fadeInBottom",
4244
- },
4245
- LEFT: {
4246
- left: targetElement_left - toolTipElement_width - arrowDistance,
4247
- top: targetElement_Y_center_pos + otherDistance,
4248
- arrow: "right",
4249
- motion: "fadeInLeft",
4250
- },
4251
- };
4252
- }
4253
- /**
4254
- * 显示提示框
4255
- */
4256
- function showToolTipNode() {
4257
- if (typeof config.showBeforeCallBack === "function") {
4258
- let result = config.showBeforeCallBack();
4259
- if (typeof result === "boolean" && !result) {
4260
- return;
4261
- }
4262
- }
4263
- if (!popsUtils.contains($shadowRoot, toolTipElement)) {
4264
- popsDOMUtils.append($shadowRoot, toolTipElement);
4265
- }
4266
- if (!popsUtils.contains($shadowContainer)) {
4267
- if (typeof config.beforeAppendToPageCallBack === "function") {
4268
- config.beforeAppendToPageCallBack($shadowRoot, $shadowContainer);
4269
- }
4270
- popsDOMUtils.append(document.body, $shadowContainer);
4271
- }
4272
- setToolTipPosition(getToolTipPosition(config.target, config.arrowDistance, config.otherDistance));
4273
- if (typeof config.showAfterCallBack === "function") {
4274
- config.showAfterCallBack(toolTipElement);
4275
- }
4276
- }
4277
- /**
4278
- * 关闭提示框
4279
- */
4280
- function closeToolTipNode() {
4281
- if (typeof config.closeBeforeCallBack === "function") {
4282
- let result = config.closeBeforeCallBack(toolTipElement);
4283
- if (typeof result === "boolean" && !result) {
4284
- return;
4285
- }
4286
- }
4287
- toolTipElement.setAttribute("data-motion", toolTipElement.getAttribute("data-motion").replace("fadeIn", "fadeOut"));
4288
- if (typeof config.closeAfterCallBack === "function") {
4289
- config.closeAfterCallBack(toolTipElement);
4290
- }
4291
- }
4292
- /**
4293
- * 绑定 显示事件
4294
- */
4295
- function onShowEvent() {
4296
- popsDOMUtils.on(config.target, config.triggerShowEventName, showToolTipNode, config.eventOption);
4297
- }
4298
- /**
4299
- * 绑定 关闭事件
4300
- */
4301
- function onCloseEvent() {
4302
- popsDOMUtils.on(config.target, config.triggerCloseEventName, closeToolTipNode, config.eventOption);
4303
- }
4304
- /**
4305
- * 取消绑定 显示事件
4306
- */
4307
- function offShowEvent() {
4308
- popsDOMUtils.off(config.target, config.triggerShowEventName, showToolTipNode, {
4309
- capture: true,
4310
- });
4311
- }
4312
- /**
4313
- * 取消绑定 关闭事件
4314
- */
4315
- function offCloseEvent() {
4316
- popsDOMUtils.off(config.target, config.triggerCloseEventName, closeToolTipNode, {
4317
- capture: true,
4318
- });
4319
- }
4320
- /**
4321
- * 即使存在动画属性,但是当前设置的动画Out结束后移除元素
4322
- */
4323
- function endEvent() {
4324
- if (toolTipElement.getAttribute("data-motion").includes("In")) {
4325
- return;
4326
- }
4327
- toolTipElement.remove();
4328
- }
4329
- if (config.alwaysShow) {
4330
- /* 总是显示 */
4331
- showToolTipNode();
4332
- return {
4333
- guid: guid,
4334
- config: config,
4335
- toolTipNode: toolTipElement,
4336
- show: showToolTipNode,
4337
- close() {
4338
- popsDOMUtils.on(toolTipElement, popsDOMUtils.getAnimationEndNameList(), endEvent, config.eventOption);
4339
- closeToolTipNode();
4340
- },
4341
- off: null,
4342
- on: null,
4343
- };
4344
- }
4345
- else {
4346
- /* 事件触发才显示 */
4347
- /**
4348
- * 当鼠标|手触摸,暂停当前动画
4349
- */
4350
- popsDOMUtils.on(toolTipElement, "mouseenter touchstart", () => {
4351
- toolTipElement.style.animationPlayState = "paused";
4352
- // if (parseInt(getComputedStyle(toolTipElement)) > 0.5) {
4353
- // toolTipElement.style.animationPlayState = "paused";
4354
- // }
4355
- }, config.eventOption);
4356
- /**
4357
- * 当鼠标|手离开,开始当前动画
4358
- */
4359
- popsDOMUtils.on(toolTipElement, "mouseleave touchend", () => {
4360
- toolTipElement.style.animationPlayState = "running";
4361
- }, config.eventOption);
4362
- popsDOMUtils.on(toolTipElement, popsDOMUtils.getAnimationEndNameList(), endEvent, config.eventOption);
4363
- onShowEvent();
4364
- onCloseEvent();
4365
- return {
4366
- guid: guid,
4367
- $shadowContainer: $shadowContainer,
4368
- $shadowRoot: $shadowRoot,
4369
- config: config,
4370
- toolTipNode: toolTipElement,
4371
- show: showToolTipNode,
4372
- close: closeToolTipNode,
4373
- off() {
4374
- offShowEvent();
4375
- offCloseEvent();
4376
- },
4377
- on() {
4378
- onShowEvent();
4379
- onCloseEvent();
4380
- },
4381
- };
4382
- }
4383
- }
4384
- }
4385
-
4386
4106
  const PopsDrawerConfig = () => {
4387
4107
  return {
4388
4108
  title: {
@@ -6365,21 +6085,20 @@ var pops = (function () {
6365
6085
  };
6366
6086
  let tooltip = pops.tooltip({
6367
6087
  target: rangeInputElement.parentElement,
6368
- content: getToolTipContent(rangeInputElement.value),
6369
- zIndex: 1000000,
6370
- className: "github-tooltip",
6371
- showBeforeCallBack() {
6372
- tooltip.toolTipNode.querySelector("div").innerText =
6373
- getToolTipContent(rangeInputElement.value);
6088
+ content: () => {
6089
+ return getToolTipContent(rangeInputElement.value);
6374
6090
  },
6091
+ zIndex: () => {
6092
+ return PopsInstanceUtils.getPopsMaxZIndex().zIndex;
6093
+ },
6094
+ className: "github-tooltip",
6375
6095
  alwaysShow: false,
6376
6096
  only: false,
6377
6097
  position: "top",
6378
6098
  arrowDistance: 10,
6379
6099
  });
6380
6100
  popsDOMUtils.on(rangeInputElement, ["input", "propertychange"], void 0, function (event) {
6381
- tooltip.toolTipNode.querySelector("div").innerText =
6382
- getToolTipContent(rangeInputElement.value);
6101
+ tooltip.toolTip.changeContent(getToolTipContent(rangeInputElement.value));
6383
6102
  if (typeof formConfig.callback === "function") {
6384
6103
  formConfig.callback(event, event.target.value);
6385
6104
  }
@@ -6475,6 +6194,7 @@ var pops = (function () {
6475
6194
  * 10 => 160px~200px
6476
6195
  */
6477
6196
  stepBlockMap: new Map(),
6197
+ tooltip: null,
6478
6198
  },
6479
6199
  $ele: {
6480
6200
  slider: liElement.querySelector(".pops-slider"),
@@ -6482,7 +6202,6 @@ var pops = (function () {
6482
6202
  bar: liElement.querySelector(".pops-slider__bar"),
6483
6203
  buttonWrapper: liElement.querySelector(".pops-slider__button-wrapper"),
6484
6204
  button: liElement.querySelector(".pops-slider__button"),
6485
- tooltip: null,
6486
6205
  },
6487
6206
  $interval: {
6488
6207
  isCheck: false,
@@ -6862,13 +6581,13 @@ var pops = (function () {
6862
6581
  * 显示悬浮的
6863
6582
  */
6864
6583
  showToolTip() {
6865
- this.$ele.tooltip.show();
6584
+ this.$data.tooltip.toolTip.show();
6866
6585
  },
6867
6586
  /**
6868
6587
  * 关闭悬浮的
6869
6588
  */
6870
6589
  closeToolTip() {
6871
- this.$ele.tooltip.close();
6590
+ this.$data.tooltip.toolTip.close();
6872
6591
  },
6873
6592
  /**
6874
6593
  * 检测在1000ms内,是否停止了拖拽
@@ -6905,11 +6624,12 @@ var pops = (function () {
6905
6624
  return PopsPanelSlider.value;
6906
6625
  }
6907
6626
  }
6908
- let tooltipContent = null;
6909
- this.$ele.tooltip = pops.tooltip({
6627
+ let tooltip = pops.tooltip({
6910
6628
  target: this.$ele.button,
6911
6629
  content: getToolTipContent,
6912
- zIndex: 1000000,
6630
+ zIndex: () => {
6631
+ return PopsInstanceUtils.getPopsMaxZIndex().zIndex;
6632
+ },
6913
6633
  className: "github-tooltip",
6914
6634
  only: false,
6915
6635
  eventOption: {
@@ -6920,7 +6640,7 @@ var pops = (function () {
6920
6640
  this.intervalInit();
6921
6641
  },
6922
6642
  showAfterCallBack: (toolTipNode) => {
6923
- tooltipContent.innerText = getToolTipContent();
6643
+ tooltip.toolTip.changeContent(getToolTipContent());
6924
6644
  },
6925
6645
  closeBeforeCallBack: () => {
6926
6646
  if (this.$data.isMove) {
@@ -6933,8 +6653,7 @@ var pops = (function () {
6933
6653
  position: "top",
6934
6654
  arrowDistance: 10,
6935
6655
  });
6936
- tooltipContent =
6937
- this.$ele.tooltip.toolTipNode.querySelector("div");
6656
+ this.$data.tooltip = tooltip;
6938
6657
  },
6939
6658
  };
6940
6659
  PopsPanelSlider.init();
@@ -9703,11 +9422,460 @@ var pops = (function () {
9703
9422
  }
9704
9423
  }
9705
9424
 
9425
+ const PopsTooltipConfig = () => {
9426
+ return {
9427
+ // @ts-ignore
9428
+ target: null,
9429
+ content: "默认文字",
9430
+ position: "top",
9431
+ className: "",
9432
+ alwaysShow: false,
9433
+ triggerShowEventName: "mouseenter touchstart",
9434
+ triggerCloseEventName: "mouseleave touchend",
9435
+ zIndex: 10000,
9436
+ only: false,
9437
+ eventOption: {
9438
+ passive: false,
9439
+ capture: true,
9440
+ once: false,
9441
+ },
9442
+ showBeforeCallBack() { },
9443
+ showAfterCallBack() { },
9444
+ closeBeforeCallBack() { },
9445
+ closeAfterCallBack() { },
9446
+ arrowDistance: 12.5,
9447
+ otherDistance: 0,
9448
+ style: "",
9449
+ beforeAppendToPageCallBack() { },
9450
+ };
9451
+ };
9452
+
9453
+ class ToolTip {
9454
+ $el = {
9455
+ $shadowContainer: null,
9456
+ $shadowRoot: null,
9457
+ $toolTip: null,
9458
+ $content: null,
9459
+ $arrow: null,
9460
+ };
9461
+ $data = {
9462
+ config: null,
9463
+ guid: null,
9464
+ timeId_show: [],
9465
+ timeId_close: [],
9466
+ };
9467
+ constructor(config, guid, ShadowInfo) {
9468
+ this.$data.config = config;
9469
+ this.$data.guid = guid;
9470
+ this.$el.$shadowContainer = ShadowInfo.$shadowContainer;
9471
+ this.$el.$shadowRoot = ShadowInfo.$shadowRoot;
9472
+ this.init();
9473
+ }
9474
+ init() {
9475
+ let toolTipInfo = this.createToolTip();
9476
+ this.$el.$toolTip = toolTipInfo.$toolTipContainer;
9477
+ this.$el.$content = toolTipInfo.$toolTipContent;
9478
+ this.$el.$arrow = toolTipInfo.$toolTipArrow;
9479
+ this.changeContent();
9480
+ this.changeZIndex();
9481
+ this.changePosition();
9482
+ if (!this.$data.config.alwaysShow) {
9483
+ this.offEvent();
9484
+ this.onEvent();
9485
+ }
9486
+ }
9487
+ /**
9488
+ * 创建提示元素
9489
+ */
9490
+ createToolTip() {
9491
+ let $toolTipContainer = popsDOMUtils.createElement("div", {
9492
+ className: "pops-tip",
9493
+ innerHTML: /*html*/ `
9494
+ <div class="pops-tip-content" style="text-align: center;"></div>
9495
+ <div class="pops-tip-arrow"></div>
9496
+ `,
9497
+ });
9498
+ /** 内容 */
9499
+ let $toolTipContent = $toolTipContainer.querySelector(".pops-tip-content");
9500
+ /** 箭头 */
9501
+ let $toolTipArrow = $toolTipContainer.querySelector(".pops-tip-arrow");
9502
+ // 处理className
9503
+ if (typeof this.$data.config.className === "string" &&
9504
+ this.$data.config.className.trim() !== "") {
9505
+ popsDOMUtils.addClassName($toolTipContainer, this.$data.config.className);
9506
+ }
9507
+ // 添加attr
9508
+ $toolTipContainer.setAttribute("data-guid", this.$data.guid);
9509
+ // 添加z-index
9510
+ $toolTipContainer.style.zIndex = PopsHandler.handleZIndex(this.$data.config.zIndex).toString();
9511
+ if (this.$data.config.style != null) {
9512
+ /* 添加自定义style */
9513
+ let cssNode = popsDOMUtils.createElement("style", {
9514
+ type: "text/css",
9515
+ innerHTML: this.$data.config.style,
9516
+ });
9517
+ $toolTipContainer.appendChild(cssNode);
9518
+ }
9519
+ return {
9520
+ $toolTipContainer: $toolTipContainer,
9521
+ $toolTipArrow: $toolTipArrow,
9522
+ $toolTipContent: $toolTipContent,
9523
+ };
9524
+ }
9525
+ /**
9526
+ * 获取提示的内容
9527
+ */
9528
+ getContent() {
9529
+ return typeof this.$data.config.content === "function"
9530
+ ? this.$data.config.content()
9531
+ : this.$data.config.content;
9532
+ }
9533
+ /**
9534
+ * 修改提示的内容
9535
+ * @param text
9536
+ */
9537
+ changeContent(text) {
9538
+ if (text == null) {
9539
+ text = this.getContent();
9540
+ }
9541
+ this.$el.$content.innerHTML = text;
9542
+ }
9543
+ /**
9544
+ * 获取z-index
9545
+ */
9546
+ getZIndex() {
9547
+ const zIndex = PopsHandler.handleZIndex(this.$data.config.zIndex);
9548
+ return zIndex;
9549
+ }
9550
+ /**
9551
+ * 动态修改z-index
9552
+ */
9553
+ changeZIndex() {
9554
+ const zIndex = this.getZIndex();
9555
+ this.$el.$toolTip.style.setProperty("z-index", zIndex.toString());
9556
+ }
9557
+ /**
9558
+ * 获取 提示框的位置
9559
+ * @param targetElement 目标元素
9560
+ * @param arrowDistance 箭头和目标元素的距离
9561
+ * @param otherDistance 其它位置的偏移
9562
+ */
9563
+ getPosition(targetElement, arrowDistance, otherDistance) {
9564
+ let targetElement_width = popsDOMUtils.offset(targetElement).width;
9565
+ let targetElement_height = popsDOMUtils.offset(targetElement).height;
9566
+ let targetElement_top = popsDOMUtils.offset(targetElement).top;
9567
+ // let targetElement_bottom = popsDOMUtils.offset(targetElement).bottom;
9568
+ let targetElement_left = popsDOMUtils.offset(targetElement).left;
9569
+ // let targetElement_right = popsDOMUtils.offset(targetElement).right;
9570
+ let toolTipElement_width = popsDOMUtils.outerWidth(this.$el.$toolTip);
9571
+ let toolTipElement_height = popsDOMUtils.outerHeight(this.$el.$toolTip);
9572
+ /* 目标元素的x轴的中间位置 */
9573
+ let targetElement_X_center_pos = targetElement_left + targetElement_width / 2 - toolTipElement_width / 2;
9574
+ /* 目标元素的Y轴的中间位置 */
9575
+ let targetElement_Y_center_pos = targetElement_top + targetElement_height / 2 - toolTipElement_height / 2;
9576
+ return {
9577
+ TOP: {
9578
+ left: targetElement_X_center_pos - otherDistance,
9579
+ top: targetElement_top - toolTipElement_height - arrowDistance,
9580
+ arrow: "bottom",
9581
+ motion: "fadeInTop",
9582
+ },
9583
+ RIGHT: {
9584
+ left: targetElement_left + targetElement_width + arrowDistance,
9585
+ top: targetElement_Y_center_pos + otherDistance,
9586
+ arrow: "left",
9587
+ motion: "fadeInRight",
9588
+ },
9589
+ BOTTOM: {
9590
+ left: targetElement_X_center_pos - otherDistance,
9591
+ top: targetElement_top + targetElement_height + arrowDistance,
9592
+ arrow: "top",
9593
+ motion: "fadeInBottom",
9594
+ },
9595
+ LEFT: {
9596
+ left: targetElement_left - toolTipElement_width - arrowDistance,
9597
+ top: targetElement_Y_center_pos + otherDistance,
9598
+ arrow: "right",
9599
+ motion: "fadeInLeft",
9600
+ },
9601
+ };
9602
+ }
9603
+ /**
9604
+ * 动态修改tooltip的位置
9605
+ */
9606
+ changePosition() {
9607
+ let positionInfo = this.getPosition(this.$data.config.target, this.$data.config.arrowDistance, this.$data.config.otherDistance);
9608
+ let positionKey = this.$data.config.position.toUpperCase();
9609
+ let positionDetail = positionInfo[positionKey];
9610
+ if (positionDetail) {
9611
+ this.$el.$toolTip.style.left = positionDetail.left + "px";
9612
+ this.$el.$toolTip.style.top = positionDetail.top + "px";
9613
+ this.$el.$toolTip.setAttribute("data-motion", positionDetail.motion);
9614
+ this.$el.$arrow.setAttribute("data-position", positionDetail.arrow);
9615
+ }
9616
+ else {
9617
+ console.error("不存在该位置", this.$data.config.position);
9618
+ }
9619
+ }
9620
+ /**
9621
+ * 事件绑定
9622
+ */
9623
+ onEvent() {
9624
+ // 监听动画结束事件
9625
+ this.onAnimationFinishEvent();
9626
+ this.onShowEvent();
9627
+ this.onCloseEvent();
9628
+ this.onMouseEnterEvent();
9629
+ this.onMouseLeaveEvent();
9630
+ }
9631
+ /**
9632
+ * 取消事件绑定
9633
+ */
9634
+ offEvent() {
9635
+ this.offAnimationFinishEvent();
9636
+ this.offShowEvent();
9637
+ this.offCloseEvent();
9638
+ this.offMouseEnterEvent();
9639
+ this.offMouseLeaveEvent();
9640
+ }
9641
+ /**
9642
+ * 清除延迟的timeId
9643
+ */
9644
+ clearCloseTimeoutId(timeId) {
9645
+ for (let index = 0; index < this.$data.timeId_close.length; index++) {
9646
+ const currentTimeId = this.$data.timeId_close[index];
9647
+ if (typeof timeId === "number") {
9648
+ // 只清除一个
9649
+ if (timeId == currentTimeId) {
9650
+ clearTimeout(timeId);
9651
+ this.$data.timeId_close.splice(index, 1);
9652
+ break;
9653
+ }
9654
+ }
9655
+ else {
9656
+ clearTimeout(currentTimeId);
9657
+ this.$data.timeId_close.splice(index, 1);
9658
+ index--;
9659
+ }
9660
+ }
9661
+ }
9662
+ /**
9663
+ * 显示提示框
9664
+ */
9665
+ show() {
9666
+ if (typeof this.$data.config.showBeforeCallBack === "function") {
9667
+ let result = this.$data.config.showBeforeCallBack(this.$el.$toolTip);
9668
+ if (typeof result === "boolean" && !result) {
9669
+ return;
9670
+ }
9671
+ }
9672
+ this.clearCloseTimeoutId();
9673
+ if (!popsUtils.contains(this.$el.$shadowRoot, this.$el.$toolTip)) {
9674
+ // 不在容器中,添加
9675
+ this.init();
9676
+ popsDOMUtils.append(this.$el.$shadowRoot, this.$el.$toolTip);
9677
+ }
9678
+ if (!popsUtils.contains(this.$el.$shadowContainer)) {
9679
+ // 页面不存在Shadow,添加
9680
+ if (typeof this.$data.config.beforeAppendToPageCallBack === "function") {
9681
+ this.$data.config.beforeAppendToPageCallBack(this.$el.$shadowRoot, this.$el.$shadowContainer);
9682
+ }
9683
+ popsDOMUtils.append(document.body, this.$el.$shadowContainer);
9684
+ }
9685
+ // 更新内容
9686
+ this.changeContent();
9687
+ // 更新tip的位置
9688
+ this.changePosition();
9689
+ if (typeof this.$data.config.showAfterCallBack === "function") {
9690
+ this.$data.config.showAfterCallBack(this.$el.$toolTip);
9691
+ }
9692
+ }
9693
+ /**
9694
+ * 绑定 显示事件
9695
+ */
9696
+ onShowEvent() {
9697
+ popsDOMUtils.on(this.$data.config.target, this.$data.config.triggerShowEventName, this.show.bind(this), this.$data.config.eventOption);
9698
+ }
9699
+ /**
9700
+ * 取消绑定 显示事件
9701
+ */
9702
+ offShowEvent() {
9703
+ popsDOMUtils.off(this.$data.config.target, this.$data.config.triggerShowEventName, this.show.bind(this), {
9704
+ capture: true,
9705
+ });
9706
+ }
9707
+ /**
9708
+ * 关闭提示框
9709
+ */
9710
+ close(...args) {
9711
+ let event = args[0];
9712
+ // 只判断鼠标事件
9713
+ // 其它的如Touch事件不做处理
9714
+ if (event && event instanceof MouseEvent) {
9715
+ let $target = event.composedPath()[0];
9716
+ // 如果是子元素触发的话,忽视
9717
+ if ($target != this.$data.config.target) {
9718
+ return;
9719
+ }
9720
+ }
9721
+ if (typeof this.$data.config.closeBeforeCallBack === "function") {
9722
+ let result = this.$data.config.closeBeforeCallBack(this.$el.$toolTip);
9723
+ if (typeof result === "boolean" && !result) {
9724
+ return;
9725
+ }
9726
+ }
9727
+ if (this.$data.config.delayCloseTime == null ||
9728
+ (typeof this.$data.config.delayCloseTime === "number" &&
9729
+ this.$data.config.delayCloseTime <= 0)) {
9730
+ this.$data.config.delayCloseTime = 100;
9731
+ }
9732
+ let timeId = setTimeout(() => {
9733
+ // 设置属性触发关闭动画
9734
+ this.clearCloseTimeoutId(timeId);
9735
+ this.$el.$toolTip.setAttribute("data-motion", this.$el.$toolTip
9736
+ .getAttribute("data-motion")
9737
+ .replace("fadeIn", "fadeOut"));
9738
+ }, this.$data.config.delayCloseTime);
9739
+ this.$data.timeId_close.push(timeId);
9740
+ if (typeof this.$data.config.closeAfterCallBack === "function") {
9741
+ this.$data.config.closeAfterCallBack(this.$el.$toolTip);
9742
+ }
9743
+ }
9744
+ /**
9745
+ * 绑定 关闭事件
9746
+ */
9747
+ onCloseEvent() {
9748
+ popsDOMUtils.on(this.$data.config.target, this.$data.config.triggerCloseEventName, this.close.bind(this), this.$data.config.eventOption);
9749
+ }
9750
+ /**
9751
+ * 取消绑定 关闭事件
9752
+ */
9753
+ offCloseEvent() {
9754
+ popsDOMUtils.off(this.$data.config.target, this.$data.config.triggerCloseEventName, this.close.bind(this), {
9755
+ capture: true,
9756
+ });
9757
+ }
9758
+ /**
9759
+ * 销毁元素
9760
+ */
9761
+ destory() {
9762
+ if (this.$el.$toolTip) {
9763
+ this.$el.$shadowRoot.removeChild(this.$el.$toolTip);
9764
+ }
9765
+ // @ts-ignore
9766
+ this.$el.$toolTip = null;
9767
+ // @ts-ignore
9768
+ this.$el.$arrow = null;
9769
+ // @ts-ignore
9770
+ this.$el.$content = null;
9771
+ }
9772
+ /**
9773
+ * 动画结束事件
9774
+ */
9775
+ animationFinishEvent() {
9776
+ if (!this.$el.$toolTip) {
9777
+ return;
9778
+ }
9779
+ if (this.$el.$toolTip.getAttribute("data-motion").includes("In")) {
9780
+ return;
9781
+ }
9782
+ this.destory();
9783
+ }
9784
+ /**
9785
+ * 监听动画结束
9786
+ */
9787
+ onAnimationFinishEvent() {
9788
+ popsDOMUtils.on(this.$el.$toolTip, popsDOMUtils.getAnimationEndNameList(), this.animationFinishEvent.bind(this));
9789
+ }
9790
+ /**
9791
+ * 取消监听动画结束
9792
+ */
9793
+ offAnimationFinishEvent() {
9794
+ popsDOMUtils.off(this.$el.$toolTip, popsDOMUtils.getAnimationEndNameList(), this.animationFinishEvent.bind(this));
9795
+ }
9796
+ /**
9797
+ * 鼠标|触摸进入事件
9798
+ */
9799
+ mouseEnterEvent() {
9800
+ this.$el.$toolTip.style.animationPlayState = "paused";
9801
+ // if (parseInt(getComputedStyle(toolTipElement)) > 0.5) {
9802
+ // toolTipElement.style.animationPlayState = "paused";
9803
+ // }
9804
+ }
9805
+ /**
9806
+ * 监听鼠标|触摸事件
9807
+ */
9808
+ onMouseEnterEvent() {
9809
+ this.clearCloseTimeoutId();
9810
+ popsDOMUtils.on(this.$el.$toolTip, "mouseenter touchstart", this.mouseEnterEvent.bind(this), this.$data.config.eventOption);
9811
+ }
9812
+ /**
9813
+ * 取消监听鼠标|触摸事件
9814
+ */
9815
+ offMouseEnterEvent() {
9816
+ popsDOMUtils.off(this.$el.$toolTip, "mouseenter touchstart", this.mouseEnterEvent.bind(this), this.$data.config.eventOption);
9817
+ }
9818
+ /**
9819
+ * 鼠标|触摸离开事件
9820
+ */
9821
+ mouseLeaveEvent() {
9822
+ this.$el.$toolTip.style.animationPlayState = "running";
9823
+ }
9824
+ /**
9825
+ * 监听鼠标|触摸离开事件
9826
+ */
9827
+ onMouseLeaveEvent() {
9828
+ popsDOMUtils.on(this.$el.$toolTip, "mouseleave touchend", this.mouseLeaveEvent.bind(this), this.$data.config.eventOption);
9829
+ }
9830
+ /**
9831
+ * 取消监听鼠标|触摸离开事件
9832
+ */
9833
+ offMouseLeaveEvent() {
9834
+ popsDOMUtils.off(this.$el.$toolTip, "mouseleave touchend", this.mouseLeaveEvent.bind(this), this.$data.config.eventOption);
9835
+ }
9836
+ }
9837
+ class PopsTooltip {
9838
+ constructor(details) {
9839
+ const { $shadowContainer, $shadowRoot } = PopsHandler.handlerShadow();
9840
+ PopsHandler.handleInit($shadowRoot, [
9841
+ pops.config.cssText.index,
9842
+ pops.config.cssText.anim,
9843
+ pops.config.cssText.common,
9844
+ pops.config.cssText.tooltipCSS,
9845
+ ]);
9846
+ let config = PopsTooltipConfig();
9847
+ config = popsUtils.assign(config, GlobalConfig.getGlobalConfig());
9848
+ config = popsUtils.assign(config, details);
9849
+ if (!(config.target instanceof HTMLElement)) {
9850
+ throw "config.target 必须是HTMLElement类型";
9851
+ }
9852
+ let guid = popsUtils.getRandomGUID();
9853
+ const PopsType = "tooltip";
9854
+ config = PopsHandler.handleOnly(PopsType, config);
9855
+ let toolTip = new ToolTip(config, guid, {
9856
+ $shadowContainer,
9857
+ $shadowRoot,
9858
+ });
9859
+ if (config.alwaysShow) {
9860
+ /* 总是显示 */
9861
+ /* 直接显示 */
9862
+ toolTip.show();
9863
+ }
9864
+ return {
9865
+ guid: guid,
9866
+ config: config,
9867
+ $shadowContainer: $shadowContainer,
9868
+ $shadowRoot: $shadowRoot,
9869
+ toolTip: toolTip,
9870
+ };
9871
+ }
9872
+ }
9873
+
9706
9874
  class Pops {
9707
9875
  /** 配置 */
9708
9876
  config = {
9709
9877
  /** 版本号 */
9710
- version: "2024.11.2",
9878
+ version: "2024.11.3",
9711
9879
  cssText: {
9712
9880
  /** 主CSS */
9713
9881
  index: indexCSS,
@@ -9807,7 +9975,6 @@ var pops = (function () {
9807
9975
  /** pops.panel中用于处理各个类型的工具 */
9808
9976
  panelHandleContentUtils: PanelHandleContentDetails,
9809
9977
  };
9810
- constructor() { }
9811
9978
  init() {
9812
9979
  if (!this.config.isInit) {
9813
9980
  /* 处理获取当前所有的动画名 */
@@ -9889,7 +10056,8 @@ var pops = (function () {
9889
10056
  * @param details 配置
9890
10057
  */
9891
10058
  tooltip = (details) => {
9892
- return new PopsTooltip(details);
10059
+ let popsTooltip = new PopsTooltip(details);
10060
+ return popsTooltip;
9893
10061
  };
9894
10062
  /**
9895
10063
  * 抽屉