shineout 3.8.0-beta.14 → 3.8.0-beta.16

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.
package/cjs/index.js CHANGED
@@ -522,5 +522,5 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
522
522
  // 此文件由脚本自动生成,请勿直接修改。
523
523
  // This file was generated automatically by a script. Please do not modify it directly.
524
524
  var _default = exports.default = {
525
- version: '3.8.0-beta.14'
525
+ version: '3.8.0-beta.16'
526
526
  };
package/dist/shineout.js CHANGED
@@ -12234,7 +12234,7 @@ var handleStyle = function handleStyle(style) {
12234
12234
  };
12235
12235
  /* harmony default export */ var jss_style_handleStyle = (handleStyle);
12236
12236
  ;// CONCATENATED MODULE: ../shineout-style/src/version.ts
12237
- /* harmony default export */ var version = ('3.8.0-beta.14');
12237
+ /* harmony default export */ var version = ('3.8.0-beta.16');
12238
12238
  ;// CONCATENATED MODULE: ../shineout-style/src/jss-style/index.tsx
12239
12239
 
12240
12240
 
@@ -22299,7 +22299,7 @@ function appendNormalizeStyle(styleString, id) {
22299
22299
  document.head.insertBefore(style, document.head.firstChild);
22300
22300
  }
22301
22301
  function appendJssInsertionPoint() {
22302
- var insertionPoint = document.createElement('noscript');
22302
+ var insertionPoint = document.createElement('style');
22303
22303
  insertionPoint.id = jssInsertionPointId;
22304
22304
  document.head.insertBefore(insertionPoint, document.head.firstChild);
22305
22305
  react_jss_esm_defaultJss.setup({
@@ -61403,6 +61403,16 @@ var sticky_cssSupport = cssSupport,
61403
61403
  var supportSticky = sticky_cssSupport('position', 'sticky');
61404
61404
  var defaultZIndex = 900;
61405
61405
  var events = ['scroll', 'pageshow', 'load', 'resize'];
61406
+ function getStaticTop(el) {
61407
+ var stopper = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : document.body;
61408
+ var top = 0;
61409
+ var currentEl = el;
61410
+ while (currentEl && currentEl !== stopper) {
61411
+ top += currentEl.offsetTop;
61412
+ currentEl = currentEl.offsetParent;
61413
+ }
61414
+ return top;
61415
+ }
61406
61416
  var Sticky = function Sticky(props) {
61407
61417
  if (props.target) {
61408
61418
  sticky_devUseWarning.deprecated('target', 'scrollContainer', 'Sticky');
@@ -61413,7 +61423,7 @@ var Sticky = function Sticky(props) {
61413
61423
  // 是否使用css sticky
61414
61424
  var css = (props.css || props.target) && supportSticky;
61415
61425
  var forceUpdate = useRender();
61416
- var elementRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
61426
+ var fixedStickyElRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
61417
61427
  var _useRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)({
61418
61428
  target: null,
61419
61429
  div: null,
@@ -61422,43 +61432,7 @@ var Sticky = function Sticky(props) {
61422
61432
  parentObserver: null,
61423
61433
  fixedObserver: null,
61424
61434
  stoped: false,
61425
- stopStickyFn: function stopStickyFn(e) {
61426
- var target = e.target;
61427
- if (!target || typeof target.scrollTop !== 'number') return;
61428
- var stopStickyPoint = -1;
61429
- if (typeof props.stickyBoundary === 'number') {
61430
- stopStickyPoint = props.stickyBoundary;
61431
- } else if (typeof props.stickyBoundary === 'function') {
61432
- var stopStickyElement = props.stickyBoundary();
61433
- if (!stopStickyElement) return;
61434
- var stopStickyRect = stopStickyElement.getBoundingClientRect();
61435
- var targetRect = elementRef.current.getBoundingClientRect();
61436
- stopStickyPoint = stopStickyRect.bottom - targetRect.bottom;
61437
- }
61438
- if (stopStickyPoint < 0) return;
61439
- if (target.scrollTop > stopStickyPoint) {
61440
- if (context.stoped) return;
61441
- context.stoped = true;
61442
-
61443
- // 把 div 移动到 target 内部,使用 absolute 定位跟随滚动
61444
- if (context.div && context.target) {
61445
- context.target.insertBefore(context.div, context.target.firstChild);
61446
- var paddingLeft = Number(window.getComputedStyle(context.target).paddingLeft.replace('px', '')) || 0;
61447
- var borderLeftWidth = Number(window.getComputedStyle(context.target).borderLeftWidth.replace('px', '')) || 0;
61448
- var left = paddingLeft + borderLeftWidth;
61449
- context.div.style.transform = "translate(-".concat(left, "px, ").concat(stopStickyPoint, "px)");
61450
- }
61451
- } else {
61452
- if (!context.stoped) return;
61453
- context.stoped = false;
61454
-
61455
- // 恢复正常吸附模式:把 div 移动到 target 外部
61456
- if (context.div && context.target && context.target.parentNode) {
61457
- context.target.parentNode.insertBefore(context.div, context.target);
61458
- }
61459
- context.div.style.transform = 'none';
61460
- }
61461
- }
61435
+ originPosition: null
61462
61436
  }),
61463
61437
  context = _useRef.current;
61464
61438
  var _useState = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useState)({}),
@@ -61473,6 +61447,78 @@ var Sticky = function Sticky(props) {
61473
61447
  _useState6 = slicedToArray_default()(_useState5, 2),
61474
61448
  parentVisible = _useState6[0],
61475
61449
  setParentVisible = _useState6[1];
61450
+ var elementRef = (0,external_root_React_commonjs2_react_commonjs_react_amd_react_.useRef)(null);
61451
+ var onStickyBoundaryChange = usePersistFn(function (e) {
61452
+ var target = e.target;
61453
+ var isDocument = !context.target || context.target === document.documentElement;
61454
+ var scrollTop = isDocument ? window.scrollY : target.scrollTop;
61455
+ if (!target || typeof scrollTop !== 'number') return;
61456
+ var stopStickyPoint = -1;
61457
+ var baseTop = 0;
61458
+ var absoluteTop = 0;
61459
+ var absoluteLeft = 0;
61460
+ var stopStickyElement = null;
61461
+ if (typeof props.stickyBoundary === 'number') {
61462
+ stopStickyPoint = props.stickyBoundary;
61463
+ } else if (typeof props.stickyBoundary === 'function') {
61464
+ stopStickyElement = props.stickyBoundary();
61465
+ if (!stopStickyElement) return;
61466
+ var stopStickyRect = stopStickyElement.getBoundingClientRect();
61467
+ var targetRect = elementRef.current.getBoundingClientRect();
61468
+ if (context.target === document.documentElement || !context.target) {
61469
+ baseTop = getStaticTop(elementRef.current) - (props.top || 0);
61470
+ absoluteTop = stopStickyRect.bottom - targetRect.bottom;
61471
+ absoluteLeft = stopStickyRect.left - targetRect.left;
61472
+ }
61473
+ stopStickyPoint = stopStickyRect.bottom - targetRect.bottom + baseTop;
61474
+ }
61475
+ if (stopStickyPoint < 0) return;
61476
+ if (scrollTop > stopStickyPoint) {
61477
+ if (context.stoped) return;
61478
+ context.stoped = true;
61479
+
61480
+ // 把 div 移动到 target 内部,使用 absolute 定位跟随滚动
61481
+ if (context.div && context.target) {
61482
+ context.target.insertBefore(context.div, context.target.firstChild);
61483
+ var paddingLeft = Number(window.getComputedStyle(context.target).paddingLeft.replace('px', '')) || 0;
61484
+ var borderLeftWidth = Number(window.getComputedStyle(context.target).borderLeftWidth.replace('px', '')) || 0;
61485
+ var left = paddingLeft + borderLeftWidth;
61486
+ context.div.style.transform = "translate(-".concat(left, "px, ").concat(stopStickyPoint, "px)");
61487
+ } else {
61488
+ if (stopStickyElement) {
61489
+ if (!fixedStickyElRef.current) return;
61490
+ // 存储原始位置到 context 中
61491
+ if (!context.originPosition) {
61492
+ var originStyle = window.getComputedStyle(fixedStickyElRef.current);
61493
+ context.originPosition = {
61494
+ top: originStyle.top,
61495
+ left: originStyle.left
61496
+ };
61497
+ }
61498
+
61499
+ // 直接操作DOM的原因是:不闪烁且性能更好
61500
+ stopStickyElement.style.transform = "translateZ(0)";
61501
+ fixedStickyElRef.current.style.top = "".concat(absoluteTop, "px");
61502
+ fixedStickyElRef.current.style.left = "".concat(absoluteLeft, "px");
61503
+ }
61504
+ // 暂不支持 props.stickyBoundary 为 number 的fixed定位情况
61505
+ }
61506
+ } else {
61507
+ if (!context.stoped) return;
61508
+ context.stoped = false;
61509
+
61510
+ // 恢复正常吸附模式:把 div 移动到 target 外部
61511
+ if (context.div && context.target && context.target.parentNode) {
61512
+ context.target.parentNode.insertBefore(context.div, context.target);
61513
+ context.div.style.transform = 'none';
61514
+ } else if (stopStickyElement && fixedStickyElRef.current && context.originPosition) {
61515
+ stopStickyElement.style.transform = "none";
61516
+ fixedStickyElRef.current.style.top = context.originPosition.top;
61517
+ fixedStickyElRef.current.style.left = context.originPosition.left;
61518
+ context.originPosition = null; // 清理状态
61519
+ }
61520
+ }
61521
+ });
61476
61522
  var getTarget = function getTarget() {
61477
61523
  var scrollContainer = props.scrollContainer;
61478
61524
  if (typeof scrollContainer === 'string') {
@@ -61651,10 +61697,6 @@ var Sticky = function Sticky(props) {
61651
61697
  context.targetObserver.disconnect();
61652
61698
  context.targetObserver = null;
61653
61699
  }
61654
- if (props.stickyBoundary) {
61655
- var _context$target;
61656
- (_context$target = context.target) === null || _context$target === void 0 || _context$target.removeEventListener('scroll', context.stopStickyFn);
61657
- }
61658
61700
  };
61659
61701
  var createObserver = function createObserver() {
61660
61702
  if (!context.div) {
@@ -61679,9 +61721,6 @@ var Sticky = function Sticky(props) {
61679
61721
  }
61680
61722
  }
61681
61723
  cancelFixedObserver();
61682
- if (props.stickyBoundary) {
61683
- context.target.addEventListener('scroll', context.stopStickyFn);
61684
- }
61685
61724
  if (window.IntersectionObserver) {
61686
61725
  var observer = new IntersectionObserver(handleTargetPosition, {
61687
61726
  root: context.target,
@@ -61721,6 +61760,10 @@ var Sticky = function Sticky(props) {
61721
61760
  context.div.remove();
61722
61761
  context.div = null;
61723
61762
  }
61763
+ if (props.stickyBoundary) {
61764
+ var _context$target;
61765
+ (_context$target = context.target) === null || _context$target === void 0 || _context$target.removeEventListener('scroll', onStickyBoundaryChange);
61766
+ }
61724
61767
  };
61725
61768
  var createFixedEvents = function createFixedEvents() {
61726
61769
  createFixedObserver();
@@ -61733,6 +61776,10 @@ var Sticky = function Sticky(props) {
61733
61776
  events.forEach(function (event) {
61734
61777
  window.removeEventListener(event, handleFixedPosition);
61735
61778
  });
61779
+ if (props.stickyBoundary) {
61780
+ var _context$target2;
61781
+ (_context$target2 = context.target) === null || _context$target2 === void 0 || _context$target2.removeEventListener('scroll', onStickyBoundaryChange);
61782
+ }
61736
61783
  };
61737
61784
  var handleElementRef = function handleElementRef(el) {
61738
61785
  if (el) {
@@ -61760,7 +61807,15 @@ var Sticky = function Sticky(props) {
61760
61807
  context.target = target;
61761
61808
  forceUpdate();
61762
61809
  }
61763
- if (context.target) {
61810
+ if (props.stickyBoundary) {
61811
+ if (!context.target || context.target === document.documentElement) {
61812
+ window.addEventListener('scroll', onStickyBoundaryChange);
61813
+ } else {
61814
+ var _context$target3;
61815
+ (_context$target3 = context.target) === null || _context$target3 === void 0 || _context$target3.addEventListener('scroll', onStickyBoundaryChange);
61816
+ }
61817
+ }
61818
+ if (context.target && context.target !== document.documentElement) {
61764
61819
  createTargetEvents();
61765
61820
  return cancelTargetEvents;
61766
61821
  } else {
@@ -61781,7 +61836,6 @@ var Sticky = function Sticky(props) {
61781
61836
  if (props.onChange) {
61782
61837
  props.onChange(show);
61783
61838
  }
61784
- ;
61785
61839
  }, [show]);
61786
61840
 
61787
61841
  // 纯css方法 直接使用css
@@ -61806,6 +61860,7 @@ var Sticky = function Sticky(props) {
61806
61860
  style: objectSpread2_default()(objectSpread2_default()({
61807
61861
  zIndex: defaultZIndex
61808
61862
  }, style), elementSize),
61863
+ ref: fixedStickyElRef,
61809
61864
  children: /*#__PURE__*/(0,jsx_runtime.jsx)("div", {
61810
61865
  className: props.className,
61811
61866
  style: props.style,
@@ -72036,7 +72091,7 @@ var upload_interface = __webpack_require__(8821);
72036
72091
 
72037
72092
 
72038
72093
  /* harmony default export */ var src_0 = ({
72039
- version: '3.8.0-beta.14'
72094
+ version: '3.8.0-beta.16'
72040
72095
  });
72041
72096
  }();
72042
72097
  /******/ return __webpack_exports__;