bootstrap-italia 2.12.1 → 2.13.0
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/README.EN.md +1 -1
- package/README.md +1 -1
- package/dist/bootstrap-italia.esm.js +1 -1
- package/dist/css/bootstrap-italia.min.css +9 -1
- package/dist/css/bootstrap-italia.min.css.map +1 -1
- package/dist/js/bootstrap-italia.bundle.min.js +19 -23
- package/dist/js/bootstrap-italia.min.js +18 -2
- package/dist/plugins/accept-overlay.js +19 -9
- package/dist/plugins/accept-overlay.js.map +1 -1
- package/dist/plugins/accordion.js +19 -24
- package/dist/plugins/accordion.js.map +1 -1
- package/dist/plugins/alert.js +67 -2
- package/dist/plugins/alert.js.map +1 -1
- package/dist/plugins/{backToTop.js → back-to-top.js} +14 -5
- package/dist/plugins/back-to-top.js.map +1 -0
- package/dist/plugins/base-component.js +91 -0
- package/dist/plugins/base-component.js.map +1 -0
- package/dist/plugins/button.js +58 -2
- package/dist/plugins/button.js.map +1 -1
- package/dist/plugins/carousel-bi.js +19 -9
- package/dist/plugins/carousel-bi.js.map +1 -1
- package/dist/plugins/carousel.js +445 -2
- package/dist/plugins/carousel.js.map +1 -1
- package/dist/plugins/collapse.js +273 -2
- package/dist/plugins/collapse.js.map +1 -1
- package/dist/plugins/cookiebar.js +39 -52
- package/dist/plugins/cookiebar.js.map +1 -1
- package/dist/plugins/dimmer.js +19 -8
- package/dist/plugins/dimmer.js.map +1 -1
- package/dist/plugins/dom/data.js +61 -0
- package/dist/plugins/dom/data.js.map +1 -0
- package/dist/plugins/dom/event-handler.js +296 -0
- package/dist/plugins/dom/event-handler.js.map +1 -0
- package/dist/plugins/dom/manipulator.js +76 -0
- package/dist/plugins/dom/manipulator.js.map +1 -0
- package/dist/plugins/dom/selector-engine.js +82 -0
- package/dist/plugins/dom/selector-engine.js.map +1 -0
- package/dist/plugins/dropdown.js +433 -2
- package/dist/plugins/dropdown.js.map +1 -1
- package/dist/plugins/fonts-loader.js +9 -1
- package/dist/plugins/fonts-loader.js.map +1 -1
- package/dist/plugins/form-validate.js +22 -8
- package/dist/plugins/form-validate.js.map +1 -1
- package/dist/plugins/forward.js +21 -18
- package/dist/plugins/forward.js.map +1 -1
- package/dist/plugins/header-sticky.js +11 -2
- package/dist/plugins/header-sticky.js.map +1 -1
- package/dist/plugins/history-back.js +17 -17
- package/dist/plugins/history-back.js.map +1 -1
- package/dist/plugins/init.js +9 -0
- package/dist/plugins/init.js.map +1 -1
- package/dist/plugins/input-label.js +14 -3
- package/dist/plugins/input-label.js.map +1 -1
- package/dist/plugins/input-number.js +13 -4
- package/dist/plugins/input-number.js.map +1 -1
- package/dist/plugins/input-password.js +48 -37
- package/dist/plugins/input-password.js.map +1 -1
- package/dist/plugins/input-search-autocomplete.js +9 -11
- package/dist/plugins/input-search-autocomplete.js.map +1 -1
- package/dist/plugins/input.js +12 -3
- package/dist/plugins/input.js.map +1 -1
- package/dist/plugins/list.js +23 -12
- package/dist/plugins/list.js.map +1 -1
- package/dist/plugins/masonry.js +29 -29
- package/dist/plugins/masonry.js.map +1 -1
- package/dist/plugins/modal.js +358 -2
- package/dist/plugins/modal.js.map +1 -1
- package/dist/plugins/navbar-collapsible.js +55 -45
- package/dist/plugins/navbar-collapsible.js.map +1 -1
- package/dist/plugins/navscroll.js +16 -23
- package/dist/plugins/navscroll.js.map +1 -1
- package/dist/plugins/notification.js +34 -23
- package/dist/plugins/notification.js.map +1 -1
- package/dist/plugins/offcanvas.js +259 -2
- package/dist/plugins/offcanvas.js.map +1 -1
- package/dist/plugins/popover.js +76 -2
- package/dist/plugins/popover.js.map +1 -1
- package/dist/plugins/progress-donut.js +19 -12
- package/dist/plugins/progress-donut.js.map +1 -1
- package/dist/plugins/scrollspy.js +273 -2
- package/dist/plugins/scrollspy.js.map +1 -1
- package/dist/plugins/select-autocomplete.js +10 -1
- package/dist/plugins/select-autocomplete.js.map +1 -1
- package/dist/plugins/sticky.js +21 -18
- package/dist/plugins/sticky.js.map +1 -1
- package/dist/plugins/tab.js +244 -27
- package/dist/plugins/tab.js.map +1 -1
- package/dist/plugins/toast.js +203 -2
- package/dist/plugins/toast.js.map +1 -1
- package/dist/plugins/tooltip.js +602 -2
- package/dist/plugins/tooltip.js.map +1 -1
- package/dist/plugins/track-focus.js +8 -0
- package/dist/plugins/track-focus.js.map +1 -1
- package/dist/plugins/transfer.js +11 -16
- package/dist/plugins/transfer.js.map +1 -1
- package/dist/plugins/upload-dragdrop.js +13 -4
- package/dist/plugins/upload-dragdrop.js.map +1 -1
- package/dist/plugins/util/backdrop.js +155 -0
- package/dist/plugins/util/backdrop.js.map +1 -0
- package/dist/plugins/util/component-functions.js +38 -0
- package/dist/plugins/util/component-functions.js.map +1 -0
- package/dist/plugins/util/config.js +70 -0
- package/dist/plugins/util/config.js.map +1 -0
- package/dist/plugins/util/cookies.js +8 -0
- package/dist/plugins/util/cookies.js.map +1 -1
- package/dist/plugins/util/device.js +0 -3
- package/dist/plugins/util/device.js.map +1 -1
- package/dist/plugins/util/dom.js +8 -0
- package/dist/plugins/util/dom.js.map +1 -1
- package/dist/plugins/util/focustrap.js +121 -0
- package/dist/plugins/util/focustrap.js.map +1 -0
- package/dist/plugins/util/index.js +280 -0
- package/dist/plugins/util/index.js.map +1 -0
- package/dist/plugins/util/observer.js +8 -0
- package/dist/plugins/util/observer.js.map +1 -1
- package/dist/plugins/util/on-document-scroll.js +20 -9
- package/dist/plugins/util/on-document-scroll.js.map +1 -1
- package/dist/plugins/util/pageScroll.js +8 -0
- package/dist/plugins/util/pageScroll.js.map +1 -1
- package/dist/plugins/util/sanitizer.js +115 -0
- package/dist/plugins/util/sanitizer.js.map +1 -0
- package/dist/plugins/util/scrollbar.js +120 -0
- package/dist/plugins/util/scrollbar.js.map +1 -0
- package/dist/plugins/util/swipe.js +150 -0
- package/dist/plugins/util/swipe.js.map +1 -0
- package/dist/plugins/util/template-factory.js +166 -0
- package/dist/plugins/util/template-factory.js.map +1 -0
- package/dist/plugins/util/tween.js +10 -1
- package/dist/plugins/util/tween.js.map +1 -1
- package/dist/plugins/util/youtube-video.js +12 -21
- package/dist/plugins/util/youtube-video.js.map +1 -1
- package/dist/plugins/videoplayer.js +19 -8
- package/dist/plugins/videoplayer.js.map +1 -1
- package/dist/version.js +10 -3
- package/dist/version.js.map +1 -1
- package/package.json +6 -7
- package/src/js/bootstrap-italia.entry.js +8 -0
- package/src/js/bootstrap-italia.esm.js +9 -1
- package/src/js/icons.js +8 -0
- package/src/js/load-plugin.js +8 -0
- package/src/js/plugins/accept-overlay.js +18 -10
- package/src/js/plugins/accordion.js +16 -22
- package/src/js/plugins/alert.js +66 -2
- package/src/js/plugins/{backToTop.js → back-to-top.js} +12 -4
- package/src/js/plugins/base-component.js +89 -0
- package/src/js/plugins/button.js +57 -2
- package/src/js/plugins/carousel-bi.js +18 -9
- package/src/js/plugins/carousel.js +444 -2
- package/src/js/plugins/collapse.js +272 -2
- package/src/js/plugins/cookiebar.js +37 -60
- package/src/js/plugins/dimmer.js +18 -8
- package/src/js/plugins/dom/data.js +58 -0
- package/src/js/plugins/dom/event-handler.js +301 -0
- package/src/js/plugins/dom/manipulator.js +75 -0
- package/src/js/plugins/dom/selector-engine.js +80 -0
- package/src/js/plugins/dropdown.js +432 -2
- package/src/js/plugins/fonts-loader.js +9 -1
- package/src/js/plugins/form-validate.js +21 -8
- package/src/js/plugins/form.js +11 -3
- package/src/js/plugins/forward.js +18 -16
- package/src/js/plugins/header-sticky.js +10 -2
- package/src/js/plugins/history-back.js +14 -14
- package/src/js/plugins/init.js +8 -0
- package/src/js/plugins/input-label.js +13 -3
- package/src/js/plugins/input-number.js +12 -4
- package/src/js/plugins/input-password.js +46 -36
- package/src/js/plugins/input-search-autocomplete.js +9 -13
- package/src/js/plugins/input.js +11 -3
- package/src/js/plugins/list.js +22 -12
- package/src/js/plugins/masonry.js +26 -27
- package/src/js/plugins/modal.js +357 -2
- package/src/js/plugins/navbar-collapsible.js +55 -53
- package/src/js/plugins/navscroll.js +16 -23
- package/src/js/plugins/notification.js +33 -23
- package/src/js/plugins/offcanvas.js +258 -2
- package/src/js/plugins/popover.js +75 -2
- package/src/js/plugins/progress-donut.js +17 -13
- package/src/js/plugins/scrollspy.js +272 -2
- package/src/js/plugins/select-autocomplete.js +9 -1
- package/src/js/plugins/sticky.js +21 -23
- package/src/js/plugins/tab.js +243 -27
- package/src/js/plugins/toast.js +206 -2
- package/src/js/plugins/tooltip.js +601 -2
- package/src/js/plugins/track-focus.js +8 -0
- package/src/js/plugins/transfer.js +12 -24
- package/src/js/plugins/upload-dragdrop.js +12 -4
- package/src/js/plugins/util/backdrop.js +153 -0
- package/src/js/plugins/util/component-functions.js +36 -0
- package/src/js/plugins/util/config.js +68 -0
- package/src/js/plugins/util/cookies.js +8 -0
- package/src/js/plugins/util/device.js +0 -3
- package/src/js/plugins/util/dom.js +8 -0
- package/src/js/plugins/util/focustrap.js +119 -0
- package/src/js/plugins/util/index.js +317 -0
- package/src/js/plugins/util/observer.js +8 -0
- package/src/js/plugins/util/on-document-scroll.js +19 -9
- package/src/js/plugins/util/pageScroll.js +8 -0
- package/src/js/plugins/util/sanitizer.js +112 -0
- package/src/js/plugins/util/scrollbar.js +118 -0
- package/src/js/plugins/util/swipe.js +148 -0
- package/src/js/plugins/util/template-factory.js +164 -0
- package/src/js/plugins/util/tween.js +9 -1
- package/src/js/plugins/util/youtube-video.js +12 -21
- package/src/js/plugins/videoplayer.js +18 -8
- package/src/js/version.js +10 -3
- package/src/scss/base/_containers.scss +41 -0
- package/src/scss/base/_functions.scss +373 -0
- package/src/scss/base/_helpers.scss +10 -0
- package/src/scss/base/_maps.scss +54 -0
- package/src/scss/base/_mixins.scss +44 -0
- package/src/scss/base/_reboot.scss +590 -0
- package/src/scss/base/_root.scss +73 -0
- package/src/scss/base/_transitions.scss +27 -0
- package/src/scss/base/_utilities.scss +742 -0
- package/src/scss/base/_variables.scss +2123 -0
- package/src/scss/base/_version.scss +3 -0
- package/src/scss/base/helpers/_clearfix.scss +3 -0
- package/src/scss/base/helpers/_color-bg.scss +10 -0
- package/src/scss/base/helpers/_colored-links.scss +16 -0
- package/src/scss/base/helpers/_position.scss +36 -0
- package/src/scss/base/helpers/_ratio.scss +26 -0
- package/src/scss/base/helpers/_stacks.scss +15 -0
- package/src/scss/base/helpers/_stretched-link.scss +15 -0
- package/src/scss/base/helpers/_text-truncation.scss +7 -0
- package/src/scss/base/helpers/_visually-hidden.scss +8 -0
- package/src/scss/base/helpers/_vr.scss +8 -0
- package/src/scss/base/mixins/_alert.scss +15 -0
- package/src/scss/base/mixins/_backdrop.scss +18 -0
- package/src/scss/base/mixins/_banner.scss +11 -0
- package/src/scss/base/mixins/_border-radius.scss +77 -0
- package/src/scss/base/mixins/_box-shadow.scss +18 -0
- package/src/scss/base/mixins/_breakpoints.scss +127 -0
- package/src/scss/base/mixins/_buttons.scss +141 -0
- package/src/scss/base/mixins/_caret.scss +64 -0
- package/src/scss/base/mixins/_clearfix.scss +9 -0
- package/src/scss/base/mixins/_color-scheme.scss +7 -0
- package/src/scss/base/mixins/_container.scss +11 -0
- package/src/scss/base/mixins/_deprecate.scss +10 -0
- package/src/scss/base/mixins/_forms.scss +152 -0
- package/src/scss/base/mixins/_gradients.scss +47 -0
- package/src/scss/base/mixins/_grid.scss +151 -0
- package/src/scss/base/mixins/_image.scss +15 -0
- package/src/scss/base/mixins/_list-group.scss +24 -0
- package/src/scss/base/mixins/_lists.scss +7 -0
- package/src/scss/base/mixins/_pagination.scss +10 -0
- package/src/scss/base/mixins/_reset-text.scss +17 -0
- package/src/scss/base/mixins/_resize.scss +6 -0
- package/src/scss/base/mixins/_table-variants.scss +24 -0
- package/src/scss/base/mixins/_text-truncate.scss +8 -0
- package/src/scss/base/mixins/_transition.scss +26 -0
- package/src/scss/base/mixins/_utilities.scss +96 -0
- package/src/scss/base/mixins/_visually-hidden.scss +29 -0
- package/src/scss/base/utilities/_api.scss +45 -0
- package/src/scss/base/vendor/_rfs.scss +337 -0
- package/src/scss/bootstrap-italia.scss +137 -156
- package/src/scss/components/_accordion.scss +297 -0
- package/src/scss/components/_badge.scss +60 -0
- package/src/scss/components/_breadcrumb.scss +95 -0
- package/src/scss/components/_button-group.scss +143 -0
- package/src/scss/components/_buttons.scss +467 -0
- package/src/scss/{custom → components}/_card.scss +228 -0
- package/src/scss/{custom → components}/_carousel.scss +225 -3
- package/src/scss/components/_dropdown.scss +480 -0
- package/src/scss/{custom → components}/_grid.scss +33 -0
- package/src/scss/{custom → components}/_gridlist.scss +7 -0
- package/src/scss/{custom → components}/_hero.scss +23 -57
- package/src/scss/components/_images.scss +48 -0
- package/src/scss/{custom → components}/_linklist.scss +0 -1
- package/src/scss/components/_list-group.scss +190 -0
- package/src/scss/components/_modal.scss +475 -0
- package/src/scss/components/_nav.scss +169 -0
- package/src/scss/components/_navbar.scss +273 -0
- package/src/scss/components/_offcanvas.scss +144 -0
- package/src/scss/components/_pagination.scss +108 -0
- package/src/scss/components/_placeholders.scss +51 -0
- package/src/scss/components/_popover.scss +298 -0
- package/src/scss/components/_progress-bars.scss +126 -0
- package/src/scss/{custom → components}/_steppers.scss +2 -2
- package/src/scss/{custom → components}/_tab.scss +3 -7
- package/src/scss/components/_tables.scss +171 -0
- package/src/scss/components/_toasts.scss +73 -0
- package/src/scss/{custom → components}/_toolbar.scss +19 -12
- package/src/scss/components/_tooltip.scss +139 -0
- package/src/scss/{custom → components}/_type.scss +92 -0
- package/src/scss/forms/_accessible-autocomplete.scss +188 -0
- package/src/scss/forms/_floating-labels.scss +75 -0
- package/src/scss/forms/_form-check.scss +175 -0
- package/src/scss/forms/_form-control.scss +201 -0
- package/src/scss/forms/_form-range.scss +95 -0
- package/src/scss/{custom → forms}/_form-select.scss +72 -0
- package/src/scss/forms/_form-text.scss +11 -0
- package/src/scss/{custom → forms}/_forms.scss +8 -12
- package/src/scss/forms/_input-group.scss +129 -0
- package/src/scss/forms/_labels.scss +36 -0
- package/src/scss/forms/_validation.scss +12 -0
- package/src/scss/utilities/icons.scss +5 -5
- package/types/index.d.ts +4 -1
- package/types/plugins/video.ts +33 -0
- package/dist/plugins/backToTop.js.map +0 -1
- package/src/scss/_functions.scss +0 -38
- package/src/scss/_variables.scss +0 -639
- package/src/scss/custom/_accessible-autocomplete.scss +0 -30
- package/src/scss/custom/_accordion.scss +0 -176
- package/src/scss/custom/_badge.scss +0 -29
- package/src/scss/custom/_breadcrumb.scss +0 -51
- package/src/scss/custom/_buttons.scss +0 -235
- package/src/scss/custom/_componente-base.scss +0 -6
- package/src/scss/custom/_dropdown.scss +0 -248
- package/src/scss/custom/_form-datepicker.scss +0 -604
- package/src/scss/custom/_images.scss +0 -10
- package/src/scss/custom/_modal.scss +0 -248
- package/src/scss/custom/_popover.scss +0 -106
- package/src/scss/custom/_progress-bars.scss +0 -70
- package/src/scss/custom/_tables.scss +0 -11
- package/src/scss/custom/_timepicker.scss +0 -252
- package/src/scss/custom/_tooltip.scss +0 -33
- package/src/scss/custom/_version.scss +0 -3
- package/src/scss/custom/mixins/_buttons.scss +0 -67
- package/src/scss/utilities/colors_vars.scss +0 -426
- /package/src/scss/{custom → base}/mixins/_text-emphasis.scss +0 -0
- /package/src/scss/{custom → components}/_accept-overlay.scss +0 -0
- /package/src/scss/{custom → components}/_affix.scss +0 -0
- /package/src/scss/{custom → components}/_alert.scss +0 -0
- /package/src/scss/{custom → components}/_anchor.scss +0 -0
- /package/src/scss/{custom → components}/_avatar.scss +0 -0
- /package/src/scss/{custom → components}/_back-to-top.scss +0 -0
- /package/src/scss/{custom → components}/_bottomnav.scss +0 -0
- /package/src/scss/{custom → components}/_calendar.scss +0 -0
- /package/src/scss/{custom → components}/_callout.scss +0 -0
- /package/src/scss/{custom → components}/_chips.scss +0 -0
- /package/src/scss/{custom → components}/_code.scss +0 -0
- /package/src/scss/{custom → components}/_cookiebar.scss +0 -0
- /package/src/scss/{custom → components}/_dimmer.scss +0 -0
- /package/src/scss/{custom → components}/_figcaption.scss +0 -0
- /package/src/scss/{custom → components}/_font.scss +0 -0
- /package/src/scss/{custom → components}/_footer.scss +0 -0
- /package/src/scss/{custom → components}/_forward.scss +0 -0
- /package/src/scss/{custom → components}/_header.scss +0 -0
- /package/src/scss/{custom → components}/_headercenter.scss +0 -0
- /package/src/scss/{custom → components}/_headercentertheme.scss +0 -0
- /package/src/scss/{custom → components}/_headernavbar.scss +0 -0
- /package/src/scss/{custom → components}/_headernavbartheme.scss +0 -0
- /package/src/scss/{custom → components}/_headerslim.scss +0 -0
- /package/src/scss/{custom → components}/_headerslimtheme.scss +0 -0
- /package/src/scss/{custom → components}/_imgresponsive.scss +0 -0
- /package/src/scss/{custom → components}/_list.scss +0 -0
- /package/src/scss/{custom → components}/_map.scss +0 -0
- /package/src/scss/{custom → components}/_masonry-loader.scss +0 -0
- /package/src/scss/{custom → components}/_megamenu.scss +0 -0
- /package/src/scss/{custom → components}/_navigation.scss +0 -0
- /package/src/scss/{custom → components}/_navigationtheme.scss +0 -0
- /package/src/scss/{custom → components}/_navscroll.scss +0 -0
- /package/src/scss/{custom → components}/_navscrolltheme.scss +0 -0
- /package/src/scss/{custom → components}/_notifications.scss +0 -0
- /package/src/scss/{custom → components}/_overlay-panel.scss +0 -0
- /package/src/scss/{custom → components}/_page-scroll.scss +0 -0
- /package/src/scss/{custom → components}/_pager.scss +0 -0
- /package/src/scss/{custom → components}/_point-list.scss +0 -0
- /package/src/scss/{custom → components}/_print.scss +0 -0
- /package/src/scss/{custom → components}/_progress-donuts.scss +0 -0
- /package/src/scss/{custom → components}/_progress-spinners.scss +0 -0
- /package/src/scss/{custom → components}/_rating-list.scss +0 -0
- /package/src/scss/{custom → components}/_rating.scss +0 -0
- /package/src/scss/{custom → components}/_sections.scss +0 -0
- /package/src/scss/{custom → components}/_sidebar.scss +0 -0
- /package/src/scss/{custom → components}/_sidebarthemes.scss +0 -0
- /package/src/scss/{custom → components}/_skiplinks.scss +0 -0
- /package/src/scss/{custom → components}/_sticky.scss +0 -0
- /package/src/scss/{custom → components}/_thumbnav.scss +0 -0
- /package/src/scss/{custom → components}/_timeline.scss +0 -0
- /package/src/scss/{custom → components}/_videoplayer.scss +0 -0
- /package/src/scss/{custom → forms}/_autocomplete.scss +0 -0
- /package/src/scss/{custom → forms}/_form-input-file.scss +0 -0
- /package/src/scss/{custom → forms}/_form-input-number.scss +0 -0
- /package/src/scss/{custom → forms}/_form-input-upload.scss +0 -0
- /package/src/scss/{custom → forms}/_form-password.scss +0 -0
- /package/src/scss/{custom → forms}/_form-toggles.scss +0 -0
- /package/src/scss/{custom → forms}/_form-transfer.scss +0 -0
- /package/src/scss/{custom → forms}/_just-validate.scss +0 -0
- /package/types/plugins/{backToTop.d.ts → back-to-top.d.ts} +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* --------------------------------------------------------------------------
|
|
3
|
+
* Bootstrap Italia (https://italia.github.io/bootstrap-italia/)
|
|
4
|
+
* Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS
|
|
5
|
+
* Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)
|
|
6
|
+
* This a fork of Bootstrap: Initial license and original file name below
|
|
7
|
+
* Bootstrap (v5.2.3): util/sanitizer.js
|
|
8
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
9
|
+
* --------------------------------------------------------------------------
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const uriAttributes = new Set(['background', 'cite', 'href', 'itemtype', 'longdesc', 'poster', 'src', 'xlink:href']);
|
|
13
|
+
|
|
14
|
+
const ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A pattern that recognizes a commonly useful subset of URLs that are safe.
|
|
18
|
+
*
|
|
19
|
+
* Shout-out to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts
|
|
20
|
+
*/
|
|
21
|
+
const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^#&/:?]*(?:[#/?]|$))/i;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A pattern that matches safe data URLs. Only matches image, video and audio types.
|
|
25
|
+
*
|
|
26
|
+
* Shout-out to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts
|
|
27
|
+
*/
|
|
28
|
+
const DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[\d+/a-z]+=*$/i;
|
|
29
|
+
|
|
30
|
+
const allowedAttribute = (attribute, allowedAttributeList) => {
|
|
31
|
+
const attributeName = attribute.nodeName.toLowerCase();
|
|
32
|
+
|
|
33
|
+
if (allowedAttributeList.includes(attributeName)) {
|
|
34
|
+
if (uriAttributes.has(attributeName)) {
|
|
35
|
+
return Boolean(SAFE_URL_PATTERN.test(attribute.nodeValue) || DATA_URL_PATTERN.test(attribute.nodeValue))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Check if a regular expression validates the attribute.
|
|
42
|
+
return allowedAttributeList.filter((attributeRegex) => attributeRegex instanceof RegExp).some((regex) => regex.test(attributeName))
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const DefaultAllowlist = {
|
|
46
|
+
// Global attributes allowed on any supplied element below.
|
|
47
|
+
'*': ['class', 'dir', 'id', 'lang', 'role', ARIA_ATTRIBUTE_PATTERN],
|
|
48
|
+
a: ['target', 'href', 'title', 'rel'],
|
|
49
|
+
area: [],
|
|
50
|
+
b: [],
|
|
51
|
+
br: [],
|
|
52
|
+
col: [],
|
|
53
|
+
code: [],
|
|
54
|
+
div: [],
|
|
55
|
+
em: [],
|
|
56
|
+
hr: [],
|
|
57
|
+
h1: [],
|
|
58
|
+
h2: [],
|
|
59
|
+
h3: [],
|
|
60
|
+
h4: [],
|
|
61
|
+
h5: [],
|
|
62
|
+
h6: [],
|
|
63
|
+
i: [],
|
|
64
|
+
img: ['src', 'srcset', 'alt', 'title', 'width', 'height'],
|
|
65
|
+
li: [],
|
|
66
|
+
ol: [],
|
|
67
|
+
p: [],
|
|
68
|
+
pre: [],
|
|
69
|
+
s: [],
|
|
70
|
+
small: [],
|
|
71
|
+
span: [],
|
|
72
|
+
sub: [],
|
|
73
|
+
sup: [],
|
|
74
|
+
strong: [],
|
|
75
|
+
u: [],
|
|
76
|
+
ul: [],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
function sanitizeHtml(unsafeHtml, allowList, sanitizeFunction) {
|
|
80
|
+
if (!unsafeHtml.length) {
|
|
81
|
+
return unsafeHtml
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (sanitizeFunction && typeof sanitizeFunction === 'function') {
|
|
85
|
+
return sanitizeFunction(unsafeHtml)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const domParser = new window.DOMParser();
|
|
89
|
+
const createdDocument = domParser.parseFromString(unsafeHtml, 'text/html');
|
|
90
|
+
const elements = [].concat(...createdDocument.body.querySelectorAll('*'));
|
|
91
|
+
|
|
92
|
+
for (const element of elements) {
|
|
93
|
+
const elementName = element.nodeName.toLowerCase();
|
|
94
|
+
|
|
95
|
+
if (!Object.keys(allowList).includes(elementName)) {
|
|
96
|
+
element.remove();
|
|
97
|
+
|
|
98
|
+
continue
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const attributeList = [].concat(...element.attributes);
|
|
102
|
+
const allowedAttributes = [].concat(allowList['*'] || [], allowList[elementName] || []);
|
|
103
|
+
|
|
104
|
+
for (const attribute of attributeList) {
|
|
105
|
+
if (!allowedAttribute(attribute, allowedAttributes)) {
|
|
106
|
+
element.removeAttribute(attribute.nodeName);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return createdDocument.body.innerHTML
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { DefaultAllowlist, sanitizeHtml };
|
|
115
|
+
//# sourceMappingURL=sanitizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizer.js","sources":["../../../src/js/plugins/util/sanitizer.js"],"sourcesContent":["/**\n * --------------------------------------------------------------------------\n * Bootstrap Italia (https://italia.github.io/bootstrap-italia/)\n * Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS\n * Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)\n * This a fork of Bootstrap: Initial license and original file name below\n * Bootstrap (v5.2.3): util/sanitizer.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nconst uriAttributes = new Set(['background', 'cite', 'href', 'itemtype', 'longdesc', 'poster', 'src', 'xlink:href'])\n\nconst ARIA_ATTRIBUTE_PATTERN = /^aria-[\\w-]*$/i\n\n/**\n * A pattern that recognizes a commonly useful subset of URLs that are safe.\n *\n * Shout-out to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts\n */\nconst SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file|sms):|[^#&/:?]*(?:[#/?]|$))/i\n\n/**\n * A pattern that matches safe data URLs. Only matches image, video and audio types.\n *\n * Shout-out to Angular https://github.com/angular/angular/blob/12.2.x/packages/core/src/sanitization/url_sanitizer.ts\n */\nconst DATA_URL_PATTERN = /^data:(?:image\\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\\/(?:mpeg|mp4|ogg|webm)|audio\\/(?:mp3|oga|ogg|opus));base64,[\\d+/a-z]+=*$/i\n\nconst allowedAttribute = (attribute, allowedAttributeList) => {\n const attributeName = attribute.nodeName.toLowerCase()\n\n if (allowedAttributeList.includes(attributeName)) {\n if (uriAttributes.has(attributeName)) {\n return Boolean(SAFE_URL_PATTERN.test(attribute.nodeValue) || DATA_URL_PATTERN.test(attribute.nodeValue))\n }\n\n return true\n }\n\n // Check if a regular expression validates the attribute.\n return allowedAttributeList.filter((attributeRegex) => attributeRegex instanceof RegExp).some((regex) => regex.test(attributeName))\n}\n\nexport const DefaultAllowlist = {\n // Global attributes allowed on any supplied element below.\n '*': ['class', 'dir', 'id', 'lang', 'role', ARIA_ATTRIBUTE_PATTERN],\n a: ['target', 'href', 'title', 'rel'],\n area: [],\n b: [],\n br: [],\n col: [],\n code: [],\n div: [],\n em: [],\n hr: [],\n h1: [],\n h2: [],\n h3: [],\n h4: [],\n h5: [],\n h6: [],\n i: [],\n img: ['src', 'srcset', 'alt', 'title', 'width', 'height'],\n li: [],\n ol: [],\n p: [],\n pre: [],\n s: [],\n small: [],\n span: [],\n sub: [],\n sup: [],\n strong: [],\n u: [],\n ul: [],\n}\n\nexport function sanitizeHtml(unsafeHtml, allowList, sanitizeFunction) {\n if (!unsafeHtml.length) {\n return unsafeHtml\n }\n\n if (sanitizeFunction && typeof sanitizeFunction === 'function') {\n return sanitizeFunction(unsafeHtml)\n }\n\n const domParser = new window.DOMParser()\n const createdDocument = domParser.parseFromString(unsafeHtml, 'text/html')\n const elements = [].concat(...createdDocument.body.querySelectorAll('*'))\n\n for (const element of elements) {\n const elementName = element.nodeName.toLowerCase()\n\n if (!Object.keys(allowList).includes(elementName)) {\n element.remove()\n\n continue\n }\n\n const attributeList = [].concat(...element.attributes)\n const allowedAttributes = [].concat(allowList['*'] || [], allowList[elementName] || [])\n\n for (const attribute of attributeList) {\n if (!allowedAttribute(attribute, allowedAttributes)) {\n element.removeAttribute(attribute.nodeName)\n }\n }\n }\n\n return createdDocument.body.innerHTML\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,U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QAAQ,CAAC,WAAW;;AAEpD,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;AACvD,MAAM,OAAO,CAAC,MAAM;;AAEpB,MAAM;AACN;;AAEA,IAAI,MAAM,aAAa,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,UAAU;AACzD,IAAI,MAAM,iBAAiB,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE;;AAE1F,IAAI,KAAK,MAAM,SAAS,IAAI,aAAa,EAAE;AAC3C,MAAM,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,iBAAiB,CAAC,EAAE;AAC3D,QAAQ,OAAO,CAAC,eAAe,CAAC,SAAS,CAAC,QAAQ;AAClD;AACA;AACA;;AAEA,EAAE,OAAO,eAAe,CAAC,IAAI,CAAC;AAC9B;;;;"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import SelectorEngine from '../dom/selector-engine.js';
|
|
2
|
+
import Manipulator from '../dom/manipulator.js';
|
|
3
|
+
import { isElement } from './index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* --------------------------------------------------------------------------
|
|
7
|
+
* Bootstrap Italia (https://italia.github.io/bootstrap-italia/)
|
|
8
|
+
* Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS
|
|
9
|
+
* Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)
|
|
10
|
+
* This a fork of Bootstrap: Initial license and original file name below
|
|
11
|
+
* Bootstrap (v5.2.3): util/scrollBar.js
|
|
12
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
13
|
+
* --------------------------------------------------------------------------
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Constants
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top';
|
|
22
|
+
const SELECTOR_STICKY_CONTENT = '.sticky-top';
|
|
23
|
+
const PROPERTY_PADDING = 'padding-right';
|
|
24
|
+
const PROPERTY_MARGIN = 'margin-right';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Class definition
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
class ScrollBarHelper {
|
|
31
|
+
constructor() {
|
|
32
|
+
this._element = document.body;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Public
|
|
36
|
+
getWidth() {
|
|
37
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes
|
|
38
|
+
const documentWidth = document.documentElement.clientWidth;
|
|
39
|
+
return Math.abs(window.innerWidth - documentWidth)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
hide() {
|
|
43
|
+
const width = this.getWidth();
|
|
44
|
+
this._disableOverFlow();
|
|
45
|
+
// give padding to element to balance the hidden scrollbar width
|
|
46
|
+
this._setElementAttributes(this._element, PROPERTY_PADDING, (calculatedValue) => calculatedValue + width);
|
|
47
|
+
// trick: We adjust positive paddingRight and negative marginRight to sticky-top elements to keep showing fullwidth
|
|
48
|
+
this._setElementAttributes(SELECTOR_FIXED_CONTENT, PROPERTY_PADDING, (calculatedValue) => calculatedValue + width);
|
|
49
|
+
this._setElementAttributes(SELECTOR_STICKY_CONTENT, PROPERTY_MARGIN, (calculatedValue) => calculatedValue - width);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
reset() {
|
|
53
|
+
this._resetElementAttributes(this._element, 'overflow');
|
|
54
|
+
this._resetElementAttributes(this._element, PROPERTY_PADDING);
|
|
55
|
+
this._resetElementAttributes(SELECTOR_FIXED_CONTENT, PROPERTY_PADDING);
|
|
56
|
+
this._resetElementAttributes(SELECTOR_STICKY_CONTENT, PROPERTY_MARGIN);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
isOverflowing() {
|
|
60
|
+
return this.getWidth() > 0
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Private
|
|
64
|
+
_disableOverFlow() {
|
|
65
|
+
this._saveInitialAttribute(this._element, 'overflow');
|
|
66
|
+
this._element.style.overflow = 'hidden';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_setElementAttributes(selector, styleProperty, callback) {
|
|
70
|
+
const scrollbarWidth = this.getWidth();
|
|
71
|
+
const manipulationCallBack = (element) => {
|
|
72
|
+
if (element !== this._element && window.innerWidth > element.clientWidth + scrollbarWidth) {
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this._saveInitialAttribute(element, styleProperty);
|
|
77
|
+
const calculatedValue = window.getComputedStyle(element).getPropertyValue(styleProperty);
|
|
78
|
+
element.style.setProperty(styleProperty, `${callback(Number.parseFloat(calculatedValue))}px`);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
this._applyManipulationCallback(selector, manipulationCallBack);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
_saveInitialAttribute(element, styleProperty) {
|
|
85
|
+
const actualValue = element.style.getPropertyValue(styleProperty);
|
|
86
|
+
if (actualValue) {
|
|
87
|
+
Manipulator.setDataAttribute(element, styleProperty, actualValue);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
_resetElementAttributes(selector, styleProperty) {
|
|
92
|
+
const manipulationCallBack = (element) => {
|
|
93
|
+
const value = Manipulator.getDataAttribute(element, styleProperty);
|
|
94
|
+
// We only want to remove the property if the value is `null`; the value can also be zero
|
|
95
|
+
if (value === null) {
|
|
96
|
+
element.style.removeProperty(styleProperty);
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
Manipulator.removeDataAttribute(element, styleProperty);
|
|
101
|
+
element.style.setProperty(styleProperty, value);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
this._applyManipulationCallback(selector, manipulationCallBack);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
_applyManipulationCallback(selector, callBack) {
|
|
108
|
+
if (isElement(selector)) {
|
|
109
|
+
callBack(selector);
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (const sel of SelectorEngine.find(selector, this._element)) {
|
|
114
|
+
callBack(sel);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { ScrollBarHelper as default };
|
|
120
|
+
//# sourceMappingURL=scrollbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrollbar.js","sources":["../../../src/js/plugins/util/scrollbar.js"],"sourcesContent":["/**\n * --------------------------------------------------------------------------\n * Bootstrap Italia (https://italia.github.io/bootstrap-italia/)\n * Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS\n * Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)\n * This a fork of Bootstrap: Initial license and original file name below\n * Bootstrap (v5.2.3): util/scrollBar.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nimport SelectorEngine from '../dom/selector-engine'\nimport Manipulator from '../dom/manipulator'\nimport { isElement } from './index'\n\n/**\n * Constants\n */\n\nconst SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top'\nconst SELECTOR_STICKY_CONTENT = '.sticky-top'\nconst PROPERTY_PADDING = 'padding-right'\nconst PROPERTY_MARGIN = 'margin-right'\n\n/**\n * Class definition\n */\n\nclass ScrollBarHelper {\n constructor() {\n this._element = document.body\n }\n\n // Public\n getWidth() {\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes\n const documentWidth = document.documentElement.clientWidth\n return Math.abs(window.innerWidth - documentWidth)\n }\n\n hide() {\n const width = this.getWidth()\n this._disableOverFlow()\n // give padding to element to balance the hidden scrollbar width\n this._setElementAttributes(this._element, PROPERTY_PADDING, (calculatedValue) => calculatedValue + width)\n // trick: We adjust positive paddingRight and negative marginRight to sticky-top elements to keep showing fullwidth\n this._setElementAttributes(SELECTOR_FIXED_CONTENT, PROPERTY_PADDING, (calculatedValue) => calculatedValue + width)\n this._setElementAttributes(SELECTOR_STICKY_CONTENT, PROPERTY_MARGIN, (calculatedValue) => calculatedValue - width)\n }\n\n reset() {\n this._resetElementAttributes(this._element, 'overflow')\n this._resetElementAttributes(this._element, PROPERTY_PADDING)\n this._resetElementAttributes(SELECTOR_FIXED_CONTENT, PROPERTY_PADDING)\n this._resetElementAttributes(SELECTOR_STICKY_CONTENT, PROPERTY_MARGIN)\n }\n\n isOverflowing() {\n return this.getWidth() > 0\n }\n\n // Private\n _disableOverFlow() {\n this._saveInitialAttribute(this._element, 'overflow')\n this._element.style.overflow = 'hidden'\n }\n\n _setElementAttributes(selector, styleProperty, callback) {\n const scrollbarWidth = this.getWidth()\n const manipulationCallBack = (element) => {\n if (element !== this._element && window.innerWidth > element.clientWidth + scrollbarWidth) {\n return\n }\n\n this._saveInitialAttribute(element, styleProperty)\n const calculatedValue = window.getComputedStyle(element).getPropertyValue(styleProperty)\n element.style.setProperty(styleProperty, `${callback(Number.parseFloat(calculatedValue))}px`)\n }\n\n this._applyManipulationCallback(selector, manipulationCallBack)\n }\n\n _saveInitialAttribute(element, styleProperty) {\n const actualValue = element.style.getPropertyValue(styleProperty)\n if (actualValue) {\n Manipulator.setDataAttribute(element, styleProperty, actualValue)\n }\n }\n\n _resetElementAttributes(selector, styleProperty) {\n const manipulationCallBack = (element) => {\n const value = Manipulator.getDataAttribute(element, styleProperty)\n // We only want to remove the property if the value is `null`; the value can also be zero\n if (value === null) {\n element.style.removeProperty(styleProperty)\n return\n }\n\n Manipulator.removeDataAttribute(element, styleProperty)\n element.style.setProperty(styleProperty, value)\n }\n\n this._applyManipulationCallback(selector, manipulationCallBack)\n }\n\n _applyManipulationCallback(selector, callBack) {\n if (isElement(selector)) {\n callBack(selector)\n return\n }\n\n for (const sel of SelectorEngine.find(selector, this._element)) {\n callBack(sel)\n }\n }\n}\n\nexport default ScrollBarHelper\n"],"names":[],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAMA;AACA;AACA;;AAEA,MAAM,sBAAsB,GAAG;AAC/B,MAAM,uBAAuB,GAAG;AAChC,MAAM,gBAAgB,GAAG;AACzB,MAAM,eAAe,GAAG;;AAExB;AACA;AACA;;AAEA,MAAM,eAAe,CAAC;AACtB,EAAE,WAAW,GAAG;AAChB,IAAI,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC7B;;AAEA;AACA,EAAE,QAAQ,GAAG;AACb;AACA,IAAI,MAAM,aAAa,GAAG,QAAQ,CAAC,eAAe,CAAC;AACnD,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,UAAU,GAAG,aAAa;AACrD;;AAEA,EAAE,IAAI,GAAG;AACT,IAAI,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ;AAC/B,IAAI,IAAI,CAAC,gBAAgB;AACzB;AACA,IAAI,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,QAAQ,EAAE,gBAAgB,EAAE,CAAC,eAAe,KAAK,eAAe,GAAG,KAAK;AAC5G;AACA,IAAI,IAAI,CAAC,qBAAqB,CAAC,sBAAsB,EAAE,gBAAgB,EAAE,CAAC,eAAe,KAAK,eAAe,GAAG,KAAK;AACrH,IAAI,IAAI,CAAC,qBAAqB,CAAC,uBAAuB,EAAE,eAAe,EAAE,CAAC,eAAe,KAAK,eAAe,GAAG,KAAK;AACrH;;AAEA,EAAE,KAAK,GAAG;AACV,IAAI,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU;AAC1D,IAAI,IAAI,CAAC,uBAAuB,CAAC,IAAI,C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AAE;AACrB,MAAM,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,WAAW;AACtE;AACA;;AAEA,EAAE,uBAAuB,CAAC,QAAQ,EAAE,aAAa,EAAE;AACnD,IAAI,MAAM,oBAAoB,GAAG,CAAC,OAAO,KAAK;AAC9C,MAAM,MAAM,KAAK,GAAG,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,aAAa;AACvE;AACA,MAAM,IAAI,KAAK,KAAK,IAAI,EAAE;AAC1B,QAAQ,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,aAAa;AAClD,QAAQ;AACR;;AAEA,MAAM,WAAW,CAAC,mBAAmB,CAAC,OAAO,EAAE,aAAa;AAC5D,MAAM,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,EAAE,KAAK;AACpD;;AAEA,IAAI,IAAI,CAAC,0BAA0B,CAAC,QAAQ,EAAE,oBAAoB;AAClE;;AAEA,EAAE,0BAA0B,CAAC,QAAQ,EAAE,QAAQ,EAAE;AACjD,IAAI,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE;AAC7B,MAAM,QAAQ,CAAC,QAAQ;AACvB,MAAM;AACN;;AAEA,IAAI,KAAK,MAAM,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,EAAE;AACpE,MAAM,QAAQ,CAAC,GAAG;AAClB;AACA;AACA;;;;"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import Config from './config.js';
|
|
2
|
+
import EventHandler from '../dom/event-handler.js';
|
|
3
|
+
import { execute } from './index.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* --------------------------------------------------------------------------
|
|
7
|
+
* Bootstrap Italia (https://italia.github.io/bootstrap-italia/)
|
|
8
|
+
* Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS
|
|
9
|
+
* Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)
|
|
10
|
+
* This a fork of Bootstrap: Initial license and original file name below
|
|
11
|
+
* Bootstrap (v5.2.3): util/swipe.js
|
|
12
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
13
|
+
* --------------------------------------------------------------------------
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Constants
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const NAME = 'swipe';
|
|
22
|
+
const EVENT_KEY = '.bs.swipe';
|
|
23
|
+
const EVENT_TOUCHSTART = `touchstart${EVENT_KEY}`;
|
|
24
|
+
const EVENT_TOUCHMOVE = `touchmove${EVENT_KEY}`;
|
|
25
|
+
const EVENT_TOUCHEND = `touchend${EVENT_KEY}`;
|
|
26
|
+
const EVENT_POINTERDOWN = `pointerdown${EVENT_KEY}`;
|
|
27
|
+
const EVENT_POINTERUP = `pointerup${EVENT_KEY}`;
|
|
28
|
+
const POINTER_TYPE_TOUCH = 'touch';
|
|
29
|
+
const POINTER_TYPE_PEN = 'pen';
|
|
30
|
+
const CLASS_NAME_POINTER_EVENT = 'pointer-event';
|
|
31
|
+
const SWIPE_THRESHOLD = 40;
|
|
32
|
+
|
|
33
|
+
const Default = {
|
|
34
|
+
endCallback: null,
|
|
35
|
+
leftCallback: null,
|
|
36
|
+
rightCallback: null,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const DefaultType = {
|
|
40
|
+
endCallback: '(function|null)',
|
|
41
|
+
leftCallback: '(function|null)',
|
|
42
|
+
rightCallback: '(function|null)',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Class definition
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
class Swipe extends Config {
|
|
50
|
+
constructor(element, config) {
|
|
51
|
+
super();
|
|
52
|
+
this._element = element;
|
|
53
|
+
|
|
54
|
+
if (!element || !Swipe.isSupported()) {
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this._config = this._getConfig(config);
|
|
59
|
+
this._deltaX = 0;
|
|
60
|
+
this._supportPointerEvents = Boolean(window.PointerEvent);
|
|
61
|
+
this._initEvents();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Getters
|
|
65
|
+
static get Default() {
|
|
66
|
+
return Default
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static get DefaultType() {
|
|
70
|
+
return DefaultType
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static get NAME() {
|
|
74
|
+
return NAME
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Public
|
|
78
|
+
dispose() {
|
|
79
|
+
EventHandler.off(this._element, EVENT_KEY);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Private
|
|
83
|
+
_start(event) {
|
|
84
|
+
if (!this._supportPointerEvents) {
|
|
85
|
+
this._deltaX = event.touches[0].clientX;
|
|
86
|
+
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (this._eventIsPointerPenTouch(event)) {
|
|
91
|
+
this._deltaX = event.clientX;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
_end(event) {
|
|
96
|
+
if (this._eventIsPointerPenTouch(event)) {
|
|
97
|
+
this._deltaX = event.clientX - this._deltaX;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this._handleSwipe();
|
|
101
|
+
execute(this._config.endCallback);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
_move(event) {
|
|
105
|
+
this._deltaX = event.touches && event.touches.length > 1 ? 0 : event.touches[0].clientX - this._deltaX;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
_handleSwipe() {
|
|
109
|
+
const absDeltaX = Math.abs(this._deltaX);
|
|
110
|
+
|
|
111
|
+
if (absDeltaX <= SWIPE_THRESHOLD) {
|
|
112
|
+
return
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const direction = absDeltaX / this._deltaX;
|
|
116
|
+
|
|
117
|
+
this._deltaX = 0;
|
|
118
|
+
|
|
119
|
+
if (!direction) {
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
execute(direction > 0 ? this._config.rightCallback : this._config.leftCallback);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
_initEvents() {
|
|
127
|
+
if (this._supportPointerEvents) {
|
|
128
|
+
EventHandler.on(this._element, EVENT_POINTERDOWN, (event) => this._start(event));
|
|
129
|
+
EventHandler.on(this._element, EVENT_POINTERUP, (event) => this._end(event));
|
|
130
|
+
|
|
131
|
+
this._element.classList.add(CLASS_NAME_POINTER_EVENT);
|
|
132
|
+
} else {
|
|
133
|
+
EventHandler.on(this._element, EVENT_TOUCHSTART, (event) => this._start(event));
|
|
134
|
+
EventHandler.on(this._element, EVENT_TOUCHMOVE, (event) => this._move(event));
|
|
135
|
+
EventHandler.on(this._element, EVENT_TOUCHEND, (event) => this._end(event));
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
_eventIsPointerPenTouch(event) {
|
|
140
|
+
return this._supportPointerEvents && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Static
|
|
144
|
+
static isSupported() {
|
|
145
|
+
return 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export { Swipe as default };
|
|
150
|
+
//# sourceMappingURL=swipe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swipe.js","sources":["../../../src/js/plugins/util/swipe.js"],"sourcesContent":["/**\n * --------------------------------------------------------------------------\n * Bootstrap Italia (https://italia.github.io/bootstrap-italia/)\n * Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS\n * Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)\n * This a fork of Bootstrap: Initial license and original file name below\n * Bootstrap (v5.2.3): util/swipe.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nimport Config from './config'\nimport EventHandler from '../dom/event-handler'\nimport { execute } from './index'\n\n/**\n * Constants\n */\n\nconst NAME = 'swipe'\nconst EVENT_KEY = '.bs.swipe'\nconst EVENT_TOUCHSTART = `touchstart${EVENT_KEY}`\nconst EVENT_TOUCHMOVE = `touchmove${EVENT_KEY}`\nconst EVENT_TOUCHEND = `touchend${EVENT_KEY}`\nconst EVENT_POINTERDOWN = `pointerdown${EVENT_KEY}`\nconst EVENT_POINTERUP = `pointerup${EVENT_KEY}`\nconst POINTER_TYPE_TOUCH = 'touch'\nconst POINTER_TYPE_PEN = 'pen'\nconst CLASS_NAME_POINTER_EVENT = 'pointer-event'\nconst SWIPE_THRESHOLD = 40\n\nconst Default = {\n endCallback: null,\n leftCallback: null,\n rightCallback: null,\n}\n\nconst DefaultType = {\n endCallback: '(function|null)',\n leftCallback: '(function|null)',\n rightCallback: '(function|null)',\n}\n\n/**\n * Class definition\n */\n\nclass Swipe extends Config {\n constructor(element, config) {\n super()\n this._element = element\n\n if (!element || !Swipe.isSupported()) {\n return\n }\n\n this._config = this._getConfig(config)\n this._deltaX = 0\n this._supportPointerEvents = Boolean(window.PointerEvent)\n this._initEvents()\n }\n\n // Getters\n static get Default() {\n return Default\n }\n\n static get DefaultType() {\n return DefaultType\n }\n\n static get NAME() {\n return NAME\n }\n\n // Public\n dispose() {\n EventHandler.off(this._element, EVENT_KEY)\n }\n\n // Private\n _start(event) {\n if (!this._supportPointerEvents) {\n this._deltaX = event.touches[0].clientX\n\n return\n }\n\n if (this._eventIsPointerPenTouch(event)) {\n this._deltaX = event.clientX\n }\n }\n\n _end(event) {\n if (this._eventIsPointerPenTouch(event)) {\n this._deltaX = event.clientX - this._deltaX\n }\n\n this._handleSwipe()\n execute(this._config.endCallback)\n }\n\n _move(event) {\n this._deltaX = event.touches && event.touches.length > 1 ? 0 : event.touches[0].clientX - this._deltaX\n }\n\n _handleSwipe() {\n const absDeltaX = Math.abs(this._deltaX)\n\n if (absDeltaX <= SWIPE_THRESHOLD) {\n return\n }\n\n const direction = absDeltaX / this._deltaX\n\n this._deltaX = 0\n\n if (!direction) {\n return\n }\n\n execute(direction > 0 ? this._config.rightCallback : this._config.leftCallback)\n }\n\n _initEvents() {\n if (this._supportPointerEvents) {\n EventHandler.on(this._element, EVENT_POINTERDOWN, (event) => this._start(event))\n EventHandler.on(this._element, EVENT_POINTERUP, (event) => this._end(event))\n\n this._element.classList.add(CLASS_NAME_POINTER_EVENT)\n } else {\n EventHandler.on(this._element, EVENT_TOUCHSTART, (event) => this._start(event))\n EventHandler.on(this._element, EVENT_TOUCHMOVE, (event) => this._move(event))\n EventHandler.on(this._element, EVENT_TOUCHEND, (event) => this._end(event))\n }\n }\n\n _eventIsPointerPenTouch(event) {\n return this._supportPointerEvents && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)\n }\n\n // Static\n static isSupported() {\n return 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0\n }\n}\n\nexport default Swipe\n"],"names":[],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAMA;AACA;AACA;;AAEA,MAAM,IAAI,GAAG;AACb,MAAM,SAAS,GAAG;AAClB,MAAM,gBAAgB,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC;AAChD,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC;AAC9C,MAAM,cAAc,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC;AAC5C,MAAM,iBAAiB,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC;AAClD,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC;AAC9C,MAAM,kBAAkB,GAAG;AAC3B,MAAM,gB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C,MAAM,CAAC,KAAK,CAAC;AACrF,MAAM,YAAY,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;;AAEjF,MAAM,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,wBAAwB;AAC1D,KAAK,MAAM;AACX,MAAM,YAAY,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,gBAAgB,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;AACpF,MAAM,YAAY,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,eAAe,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC;AAClF,MAAM,YAAY,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,EAAE,CAAC,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;AAChF;AACA;;AAEA,EAAE,uBAAuB,CAAC,KAAK,EAAE;AACjC,IAAI,OAAO,IAAI,CAAC,qBAAqB,KAAK,KAAK,CAAC,WAAW,KAAK,gBAAgB,IAAI,KAAK,CAAC,WAAW,KAAK,kBAAkB;AAC5H;;AAEA;AACA,EAAE,OAAO,WAAW,GAAG;AACvB,IAAI,OAAO,cAAc,IAAI,QAAQ,CAAC,eAAe,IAAI,SAAS,CAAC,cAAc,GAAG;AACpF;AACA;;;;"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { sanitizeHtml, DefaultAllowlist } from './sanitizer.js';
|
|
2
|
+
import { isElement, getElement } from './index.js';
|
|
3
|
+
import SelectorEngine from '../dom/selector-engine.js';
|
|
4
|
+
import Config from './config.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* --------------------------------------------------------------------------
|
|
8
|
+
* Bootstrap Italia (https://italia.github.io/bootstrap-italia/)
|
|
9
|
+
* Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS
|
|
10
|
+
* Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)
|
|
11
|
+
* This a fork of Bootstrap: Initial license and original file name below
|
|
12
|
+
* Bootstrap (v5.2.3): util/template-factory.js
|
|
13
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
|
14
|
+
* --------------------------------------------------------------------------
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Constants
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const NAME = 'TemplateFactory';
|
|
23
|
+
|
|
24
|
+
const Default = {
|
|
25
|
+
allowList: DefaultAllowlist,
|
|
26
|
+
content: {}, // { selector : text , selector2 : text2 , }
|
|
27
|
+
extraClass: '',
|
|
28
|
+
html: false,
|
|
29
|
+
sanitize: true,
|
|
30
|
+
sanitizeFn: null,
|
|
31
|
+
template: '<div></div>',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const DefaultType = {
|
|
35
|
+
allowList: 'object',
|
|
36
|
+
content: 'object',
|
|
37
|
+
extraClass: '(string|function)',
|
|
38
|
+
html: 'boolean',
|
|
39
|
+
sanitize: 'boolean',
|
|
40
|
+
sanitizeFn: '(null|function)',
|
|
41
|
+
template: 'string',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const DefaultContentType = {
|
|
45
|
+
entry: '(string|element|function|null)',
|
|
46
|
+
selector: '(string|element)',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Class definition
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
class TemplateFactory extends Config {
|
|
54
|
+
constructor(config) {
|
|
55
|
+
super();
|
|
56
|
+
this._config = this._getConfig(config);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Getters
|
|
60
|
+
static get Default() {
|
|
61
|
+
return Default
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static get DefaultType() {
|
|
65
|
+
return DefaultType
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static get NAME() {
|
|
69
|
+
return NAME
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Public
|
|
73
|
+
getContent() {
|
|
74
|
+
return Object.values(this._config.content)
|
|
75
|
+
.map((config) => this._resolvePossibleFunction(config))
|
|
76
|
+
.filter(Boolean)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
hasContent() {
|
|
80
|
+
return this.getContent().length > 0
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
changeContent(content) {
|
|
84
|
+
this._checkContent(content);
|
|
85
|
+
this._config.content = { ...this._config.content, ...content };
|
|
86
|
+
return this
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
toHtml() {
|
|
90
|
+
const templateWrapper = document.createElement('div');
|
|
91
|
+
templateWrapper.innerHTML = this._maybeSanitize(this._config.template);
|
|
92
|
+
|
|
93
|
+
for (const [selector, text] of Object.entries(this._config.content)) {
|
|
94
|
+
this._setContent(templateWrapper, text, selector);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const template = templateWrapper.children[0];
|
|
98
|
+
const extraClass = this._resolvePossibleFunction(this._config.extraClass);
|
|
99
|
+
|
|
100
|
+
if (extraClass) {
|
|
101
|
+
template.classList.add(...extraClass.split(' '));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return template
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Private
|
|
108
|
+
_typeCheckConfig(config) {
|
|
109
|
+
super._typeCheckConfig(config);
|
|
110
|
+
this._checkContent(config.content);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
_checkContent(arg) {
|
|
114
|
+
for (const [selector, content] of Object.entries(arg)) {
|
|
115
|
+
super._typeCheckConfig({ selector, entry: content }, DefaultContentType);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
_setContent(template, content, selector) {
|
|
120
|
+
const templateElement = SelectorEngine.findOne(selector, template);
|
|
121
|
+
|
|
122
|
+
if (!templateElement) {
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
content = this._resolvePossibleFunction(content);
|
|
127
|
+
|
|
128
|
+
if (!content) {
|
|
129
|
+
templateElement.remove();
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (isElement(content)) {
|
|
134
|
+
this._putElementInTemplate(getElement(content), templateElement);
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (this._config.html) {
|
|
139
|
+
templateElement.innerHTML = this._maybeSanitize(content);
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
templateElement.textContent = content;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
_maybeSanitize(arg) {
|
|
147
|
+
return this._config.sanitize ? sanitizeHtml(arg, this._config.allowList, this._config.sanitizeFn) : arg
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
_resolvePossibleFunction(arg) {
|
|
151
|
+
return typeof arg === 'function' ? arg(this) : arg
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
_putElementInTemplate(element, templateElement) {
|
|
155
|
+
if (this._config.html) {
|
|
156
|
+
templateElement.innerHTML = '';
|
|
157
|
+
templateElement.append(element);
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
templateElement.textContent = element.textContent;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { TemplateFactory as default };
|
|
166
|
+
//# sourceMappingURL=template-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-factory.js","sources":["../../../src/js/plugins/util/template-factory.js"],"sourcesContent":["/**\n * --------------------------------------------------------------------------\n * Bootstrap Italia (https://italia.github.io/bootstrap-italia/)\n * Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS\n * Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)\n * This a fork of Bootstrap: Initial license and original file name below\n * Bootstrap (v5.2.3): util/template-factory.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nimport { DefaultAllowlist, sanitizeHtml } from './sanitizer'\nimport { getElement, isElement } from '../util/index'\nimport SelectorEngine from '../dom/selector-engine'\nimport Config from './config'\n\n/**\n * Constants\n */\n\nconst NAME = 'TemplateFactory'\n\nconst Default = {\n allowList: DefaultAllowlist,\n content: {}, // { selector : text , selector2 : text2 , }\n extraClass: '',\n html: false,\n sanitize: true,\n sanitizeFn: null,\n template: '<div></div>',\n}\n\nconst DefaultType = {\n allowList: 'object',\n content: 'object',\n extraClass: '(string|function)',\n html: 'boolean',\n sanitize: 'boolean',\n sanitizeFn: '(null|function)',\n template: 'string',\n}\n\nconst DefaultContentType = {\n entry: '(string|element|function|null)',\n selector: '(string|element)',\n}\n\n/**\n * Class definition\n */\n\nclass TemplateFactory extends Config {\n constructor(config) {\n super()\n this._config = this._getConfig(config)\n }\n\n // Getters\n static get Default() {\n return Default\n }\n\n static get DefaultType() {\n return DefaultType\n }\n\n static get NAME() {\n return NAME\n }\n\n // Public\n getContent() {\n return Object.values(this._config.content)\n .map((config) => this._resolvePossibleFunction(config))\n .filter(Boolean)\n }\n\n hasContent() {\n return this.getContent().length > 0\n }\n\n changeContent(content) {\n this._checkContent(content)\n this._config.content = { ...this._config.content, ...content }\n return this\n }\n\n toHtml() {\n const templateWrapper = document.createElement('div')\n templateWrapper.innerHTML = this._maybeSanitize(this._config.template)\n\n for (const [selector, text] of Object.entries(this._config.content)) {\n this._setContent(templateWrapper, text, selector)\n }\n\n const template = templateWrapper.children[0]\n const extraClass = this._resolvePossibleFunction(this._config.extraClass)\n\n if (extraClass) {\n template.classList.add(...extraClass.split(' '))\n }\n\n return template\n }\n\n // Private\n _typeCheckConfig(config) {\n super._typeCheckConfig(config)\n this._checkContent(config.content)\n }\n\n _checkContent(arg) {\n for (const [selector, content] of Object.entries(arg)) {\n super._typeCheckConfig({ selector, entry: content }, DefaultContentType)\n }\n }\n\n _setContent(template, content, selector) {\n const templateElement = SelectorEngine.findOne(selector, template)\n\n if (!templateElement) {\n return\n }\n\n content = this._resolvePossibleFunction(content)\n\n if (!content) {\n templateElement.remove()\n return\n }\n\n if (isElement(content)) {\n this._putElementInTemplate(getElement(content), templateElement)\n return\n }\n\n if (this._config.html) {\n templateElement.innerHTML = this._maybeSanitize(content)\n return\n }\n\n templateElement.textContent = content\n }\n\n _maybeSanitize(arg) {\n return this._config.sanitize ? sanitizeHtml(arg, this._config.allowList, this._config.sanitizeFn) : arg\n }\n\n _resolvePossibleFunction(arg) {\n return typeof arg === 'function' ? arg(this) : arg\n }\n\n _putElementInTemplate(element, templateElement) {\n if (this._config.html) {\n templateElement.innerHTML = ''\n templateElement.append(element)\n return\n }\n\n templateElement.textContent = element.textContent\n }\n}\n\nexport default TemplateFactory\n"],"names":[],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAOA;AACA;AACA;;AAEA,MAAM,IAAI,GAAG;;AAEb,MAAM,OAAO,GAAG;AAChB,EAAE,SAAS,EAAE,gBAAgB;AAC7B,EAAE,OAAO,EAAE,EAAE;AACb,EAAE,UAAU,EAAE,EAAE;AAChB,EAAE,IAAI,EAAE,KAAK;AACb,EAAE,QAAQ,EAAE,IAAI;AAChB,EAAE,UAAU,EAAE,IAAI;AAClB,EAAE,QAAQ,EAAE,aAAa;AACzB;;AAEA,MAAM,WAAW,GAAG;AACpB,EAAE,SAAS,EAAE,QAAQ;AACrB,EAAE,OAAO,EAAE,QAAQ;AACnB,EAAE,UAAU,EAAE,mBAAmB;AACjC,EAAE,IAAI,EAAE,SAAS;AACjB,EAAE,QAAQ,EAAE,SAAS;AACrB,EAAE,UAAU,EAAE,iBAAiB;AAC/B,EAAE,QAAQ,EA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AAC5B,MAAM,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,eAAe;AACrE,MAAM;AACN;;AAEA,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;AAC3B,MAAM,eAAe,CAAC,SAAS,GAAG,IAAI,CAAC,cAAc,CAAC,OAAO;AAC7D,MAAM;AACN;;AAEA,IAAI,eAAe,CAAC,WAAW,GAAG;AAClC;;AAEA,EAAE,cAAc,CAAC,GAAG,EAAE;AACtB,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,GAAG,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG;AACxG;;AAEA,EAAE,wBAAwB,CAAC,GAAG,EAAE;AAChC,IAAI,OAAO,OAAO,GAAG,KAAK,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG;AACnD;;AAEA,EAAE,qBAAqB,CAAC,OAAO,EAAE,eAAe,EAAE;AAClD,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;AAC3B,MAAM,eAAe,CAAC,SAAS,GAAG;AAClC,MAAM,eAAe,CAAC,MAAM,CAAC,OAAO;AACpC,MAAM;AACN;;AAEA,IAAI,eAAe,CAAC,WAAW,GAAG,OAAO,CAAC;AAC1C;AACA;;;;"}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import anime from 'animejs/lib/anime.es.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* --------------------------------------------------------------------------
|
|
5
|
+
* Bootstrap Italia (https://italia.github.io/bootstrap-italia/)
|
|
6
|
+
* Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS
|
|
7
|
+
* Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)
|
|
8
|
+
* --------------------------------------------------------------------------
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
|
|
3
12
|
const AnimeDefault = {
|
|
4
13
|
duration: 800,
|
|
5
14
|
easing: 'easeInOutSine',
|
|
@@ -11,7 +20,7 @@ const AnimeDefault = {
|
|
|
11
20
|
* @param {Object} config - duration, easing, complete, update, ...
|
|
12
21
|
*/
|
|
13
22
|
const documentScrollTo = (scrollTop, config) => {
|
|
14
|
-
if (typeof document === 'undefined') {
|
|
23
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
15
24
|
return
|
|
16
25
|
}
|
|
17
26
|
const onComplete = (typeof config === 'object' ? config : {}).complete;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tween.js","sources":["../../../src/js/plugins/util/tween.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"tween.js","sources":["../../../src/js/plugins/util/tween.js"],"sourcesContent":["/**\n * --------------------------------------------------------------------------\n * Bootstrap Italia (https://italia.github.io/bootstrap-italia/)\n * Authors: https://github.com/italia/bootstrap-italia/blob/main/AUTHORS\n * Licensed under BSD-3-Clause license (https://github.com/italia/bootstrap-italia/blob/main/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nimport anime from 'animejs/lib/anime.es.js'\n\nconst AnimeDefault = {\n duration: 800,\n easing: 'easeInOutSine',\n}\n\n/**\n *\n * @param {number} scrollTop\n * @param {Object} config - duration, easing, complete, update, ...\n */\nexport const documentScrollTo = (scrollTop, config) => {\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return\n }\n const onComplete = (typeof config === 'object' ? config : {}).complete\n const scrollElement = window.document.scrollingElement || window.document.body || window.document.documentElement\n const prevScrollBehavior = scrollElement.style.scrollBehavior\n\n config = {\n scrollTop: scrollTop || 0,\n ...AnimeDefault,\n ...(typeof config === 'object' ? config : {}),\n }\n\n scrollElement.style.scrollBehavior = 'auto'\n\n config.complete = (anim) => {\n scrollElement.style.scrollBehavior = prevScrollBehavior\n if (typeof onComplete === 'function') {\n onComplete(anim)\n }\n }\n\n anime({\n targets: scrollElement,\n ...config,\n })\n}\n"],"names":[],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAIA,MAAM,YAAY,GAAG;AACrB,EAAE,QAAQ,EAAE,GAAG;AACf,EAAE,MAAM,EAAE,eAAe;AACzB;;AAEA;AACA;AACA;AACA;AACA;AACY,MAAC,gBAAgB,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK;AACvD,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE;AACxE,IAAI;AACJ;AACA,EAAE,MAAM,UAAU,GAAG,CAAC,OAAO,MAAM,KAAK,QAAQ,GAAG,MAAM,GAAG,EAAE,EAAE;AAChE,EAAE,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAC,gBAAgB,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC;AACpG,EAAE,MAAM,kBAAkB,GAAG,aAAa,CAAC,KAAK,CAAC;;AAEjD,EAAE,MAAM,GAAG;AACX,IAAI,SAAS,EAAE,SAAS,IAAI,CAAC;AAC7B,IAAI,GAAG,YAAY;AACnB,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,GAAG,MAAM,GAAG,EAAE,CAAC;AACjD;;AAEA,EAAE,aAAa,CAAC,KAAK,CAAC,cAAc,GAAG;;AAEvC,EAAE,MAAM,CAAC,QAAQ,GAAG,CAAC,IAAI,KAAK;AAC9B,IAAI,aAAa,CAAC,KAAK,CAAC,cAAc,GAAG;AACzC,IAAI,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE;AAC1C,MAAM,UAAU,CAAC,IAAI;AACrB;AACA;;AAEA,EAAE,KAAK,CAAC;AACR,IAAI,OAAO,EAAE,aAAa;AAC1B,IAAI,GAAG,MAAM;AACb,GAAG;AACH;;;;"}
|