@khipu/design-system 0.3.5-alpha.4 → 0.3.5-alpha.41

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.
@@ -849,6 +849,7 @@ const ui = _context.ui;
849
849
  * - Sticky invoice card (collapse on scroll)
850
850
  * - Brand inner (logo inside sticky card on mobile)
851
851
  * - Secure footer (moved inside last card per screen)
852
+ * - Read-to-accept contracts (checkbox enabled after scrolling to the end)
852
853
  */
853
854
 
854
855
  (function() {
@@ -895,71 +896,77 @@ const ui = _context.ui;
895
896
  initHideOnScroll();
896
897
  initBankModal();
897
898
  initMerchantLogoBackdrop();
898
- initCardHeightTransition();
899
+ initContract();
899
900
 
900
901
  console.log('Material Design initialization complete!');
901
902
  }
902
903
 
903
904
  /**
904
- * Initialize body card height transition (KTUF-239)
905
- * La body card cambia de alto al pasar de una pantalla a otra (loader ↔ formulario)
906
- * y el salto se nota, sobre todo desde que la card ya no lleva un alto mínimo fijo.
907
- * No se puede resolver con CSS: un cambio de altura provocado por contenido no
908
- * dispara transiciones, porque el valor declarado sigue siendo `auto` antes y
909
- * después (ni `interpolate-size` lo cubre — ese habilita animar hacia `auto` cuando
910
- * el valor declarado cambia, que no es el caso). Por eso se mide y se anima acá.
905
+ * Initialize read-to-accept contracts (KTUF-398)
906
+ * In each [data-kds-contract] the acceptance checkbox (.kds-contract-accept) stays
907
+ * disabled until .kds-contract-content is scrolled to the end, or right away if the
908
+ * content fits without scrolling. Then the hint (.kds-contract-hint) is hidden, the
909
+ * container gets .kds-contract--read and fires `kds:contract-read` once.
910
+ * Vanilla mirror of KdsContract for server-side views (payment).
911
911
  * @param {Element} root - Root element to scope the query (default: document)
912
912
  */
913
- function initCardHeightTransition(root) {
913
+ function initContract(root) {
914
914
  root = root || document;
915
- var MIN_DELTA_PX = 8;
916
- var DURATION_MS = 280;
917
-
918
- if (typeof ResizeObserver === 'undefined' || typeof Element.prototype.animate !== 'function') {
919
- return;
920
- }
921
- if (window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
922
- return;
923
- }
924
-
925
- var cards = root.querySelectorAll('.kds-screen > .kds-card-elevated');
926
- Array.prototype.forEach.call(cards, function(card) {
927
- if (card.getAttribute('data-kds-height-transition') === 'on') {
928
- return;
915
+ root.querySelectorAll('[data-kds-contract]').forEach(function(contract) {
916
+ if (contract.hasAttribute('data-kds-contract-ready')) return;
917
+ contract.setAttribute('data-kds-contract-ready', '');
918
+
919
+ var content = contract.querySelector('.kds-contract-content');
920
+ var checkbox = contract.querySelector('.kds-contract-accept input[type="checkbox"]');
921
+ var hint = contract.querySelector('.kds-contract-hint');
922
+ if (!content || !checkbox) return;
923
+
924
+ // The markup ships the checkbox enabled so the page still works without this
925
+ // script; here it is locked until the content has been read.
926
+ checkbox.disabled = true;
927
+
928
+ function markRead() {
929
+ if (contract.classList.contains('kds-contract--read')) return;
930
+ contract.classList.add('kds-contract--read');
931
+ checkbox.disabled = false;
932
+ if (hint) {
933
+ hint.hidden = true;
934
+ // The hidden hint no longer describes the checkbox (as in KdsContract).
935
+ if (hint.id) {
936
+ var describedBy = (checkbox.getAttribute('aria-describedby') || '')
937
+ .split(/\s+/)
938
+ .filter(function(id) { return id && id !== hint.id; });
939
+ if (describedBy.length) checkbox.setAttribute('aria-describedby', describedBy.join(' '));
940
+ else checkbox.removeAttribute('aria-describedby');
941
+ }
942
+ }
943
+ contract.dispatchEvent(new CustomEvent('kds:contract-read', { bubbles: true }));
929
944
  }
930
- card.setAttribute('data-kds-height-transition', 'on');
931
-
932
- var previous = card.offsetHeight;
933
- var animating = false;
934
945
 
935
- var observer = new ResizeObserver(function() {
936
- // La animación cambia el alto y volveria a disparar el observer.
937
- if (animating) {
938
- return;
939
- }
940
- var next = card.offsetHeight;
941
- // Umbral: ignora reflows menores (fuentes que cargan, scrollbars).
942
- if (Math.abs(next - previous) < MIN_DELTA_PX) {
943
- previous = next;
944
- return;
946
+ // A few px of tolerance: zoom and sub-pixel rounding rarely land exactly on 0.
947
+ // clientHeight 0 means not laid out yet (hidden step or tab): wait for the
948
+ // ResizeObserver instead of reading 0 >= -8 as "reached the end".
949
+ function check() {
950
+ if (content.clientHeight === 0) return;
951
+ if (content.scrollTop + content.clientHeight >= content.scrollHeight - 8) {
952
+ markRead();
945
953
  }
946
- animating = true;
947
- var animation = card.animate(
948
- [{ height: previous + 'px' }, { height: next + 'px' }],
949
- { duration: DURATION_MS, easing: 'ease-out' }
950
- );
951
- previous = next;
952
- animation.finished.then(function() {
953
- animating = false;
954
- previous = card.offsetHeight;
955
- }).catch(function() {
956
- animating = false;
957
- });
958
- });
959
- observer.observe(card);
954
+ }
955
+
956
+ content.addEventListener('scroll', check, { passive: true });
957
+ if (typeof ResizeObserver !== 'undefined') {
958
+ new ResizeObserver(check).observe(content);
959
+ }
960
+ check();
960
961
  });
961
962
  }
962
963
 
964
+ // El alto de la body card cambia de golpe entre pantallas, sin animar. Hubo una
965
+ // transición acá (KTUF-239) y se quitó en KTUF-314: ver el comentario en
966
+ // KdsThemeProvider.tsx — animar el alto obliga a fijar `height` en píxeles, y con el
967
+ // alto fijado no hay forma de medir el alto natural del contenido para saber cuándo
968
+ // soltarlo, así que la card quedaba con espacio muerto abajo.
969
+
963
970
  /**
964
971
  * Initialize merchant logo backdrop (KTUF-204)
965
972
  * Los logos de comercio van sobre el fondo neutro, no sobre el color de marca (los PNG
@@ -1798,7 +1805,7 @@ const ui = _context.ui;
1798
1805
  window.Khipu.initBankModal = initBankModal;
1799
1806
  window.Khipu.initStickyInvoice = initStickyInvoice;
1800
1807
  window.Khipu.initHideOnScroll = initHideOnScroll;
1801
- window.Khipu.initCardHeightTransition = initCardHeightTransition;
1808
+ window.Khipu.initContract = initContract;
1802
1809
 
1803
1810
  // Also export showSnackbar to global scope for backward compatibility
1804
1811
  window.showSnackbar = showSnackbar;