@hortonstudio/main 1.2.4 → 1.2.6
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/attributes-master/.changeset/README.md +8 -0
- package/attributes-master/.changeset/config.json +11 -0
- package/attributes-master/.gitattributes +2 -0
- package/attributes-master/.github/ISSUE_TEMPLATE/bug_report.md +42 -0
- package/attributes-master/.github/ISSUE_TEMPLATE/feature_request.md +22 -0
- package/attributes-master/.github/workflows/ci.yml +66 -0
- package/attributes-master/.github/workflows/release.yml +40 -0
- package/attributes-master/.prettierignore +3 -0
- package/attributes-master/.prettierrc +8 -0
- package/attributes-master/.vscode/extensions.json +3 -0
- package/attributes-master/.vscode/settings.json +7 -0
- package/attributes-master/CONTRIBUTING.md +72 -0
- package/attributes-master/LICENSE.md +201 -0
- package/attributes-master/README.md +31 -0
- package/attributes-master/eslint.config.js +3 -0
- package/attributes-master/package.json +34 -0
- package/attributes-master/packages/accordion/CHANGELOG.md +89 -0
- package/attributes-master/packages/accordion/README.md +31 -0
- package/attributes-master/packages/accordion/package.json +25 -0
- package/attributes-master/packages/accordion/src/actions/a11y.ts +39 -0
- package/attributes-master/packages/accordion/src/actions/classes.ts +27 -0
- package/attributes-master/packages/accordion/src/actions/content.ts +42 -0
- package/attributes-master/packages/accordion/src/actions/list.ts +36 -0
- package/attributes-master/packages/accordion/src/actions/query.ts +27 -0
- package/attributes-master/packages/accordion/src/actions/settings.ts +61 -0
- package/attributes-master/packages/accordion/src/factory.ts +145 -0
- package/attributes-master/packages/accordion/src/index.ts +3 -0
- package/attributes-master/packages/accordion/src/init.ts +37 -0
- package/attributes-master/packages/accordion/src/utils/constants.ts +62 -0
- package/attributes-master/packages/accordion/src/utils/helpers.ts +5 -0
- package/attributes-master/packages/accordion/src/utils/selectors.ts +12 -0
- package/attributes-master/packages/accordion/src/utils/types.ts +23 -0
- package/attributes-master/packages/accordion/tsconfig.json +3 -0
- package/attributes-master/packages/attributes/CHANGELOG.md +564 -0
- package/attributes-master/packages/attributes/README.md +66 -0
- package/attributes-master/packages/attributes/bin/build.ts +107 -0
- package/attributes-master/packages/attributes/bin/live-reload.js +1 -0
- package/attributes-master/packages/attributes/package.json +77 -0
- package/attributes-master/packages/attributes/playwright.config.ts +89 -0
- package/attributes-master/packages/attributes/src/attributes.ts +153 -0
- package/attributes-master/packages/attributes/src/load.ts +125 -0
- package/attributes-master/packages/attributes/tests/accordion.spec.ts +137 -0
- package/attributes-master/packages/attributes/tests/codehighlight.spec.ts +23 -0
- package/attributes-master/packages/attributes/tests/combobox.spec.ts +321 -0
- package/attributes-master/packages/attributes/tests/copyclip.spec.ts +19 -0
- package/attributes-master/packages/attributes/tests/displayvalues.spec.ts +48 -0
- package/attributes-master/packages/attributes/tests/favcustom.spec.ts +23 -0
- package/attributes-master/packages/attributes/tests/inject.spec.ts +40 -0
- package/attributes-master/packages/attributes/tests/inputactive.spec.ts +77 -0
- package/attributes-master/packages/attributes/tests/inputcounter.spec.ts +83 -0
- package/attributes-master/packages/attributes/tests/list.spec.ts +800 -0
- package/attributes-master/packages/attributes/tests/mirrorclick.spec.ts +22 -0
- package/attributes-master/packages/attributes/tests/mirrorinput.spec.ts +37 -0
- package/attributes-master/packages/attributes/tests/modal.spec.ts +34 -0
- package/attributes-master/packages/attributes/tests/numbercount.spec.ts +40 -0
- package/attributes-master/packages/attributes/tests/readtime.spec.ts +19 -0
- package/attributes-master/packages/attributes/tests/selectcustom.spec.ts +51 -0
- package/attributes-master/packages/attributes/tests/socialshare.spec.ts +54 -0
- package/attributes-master/packages/attributes/tests/starrating.spec.ts +79 -0
- package/attributes-master/packages/attributes/tests/toc.spec.ts +38 -0
- package/attributes-master/packages/attributes/tests/utils/index.ts +16 -0
- package/attributes-master/packages/attributes/tsconfig.json +6 -0
- package/attributes-master/packages/autovideo/CHANGELOG.md +182 -0
- package/attributes-master/packages/autovideo/README.md +31 -0
- package/attributes-master/packages/autovideo/package.json +22 -0
- package/attributes-master/packages/autovideo/src/index.ts +3 -0
- package/attributes-master/packages/autovideo/src/init.ts +52 -0
- package/attributes-master/packages/autovideo/src/types.ts +5 -0
- package/attributes-master/packages/autovideo/src/utils/constants.ts +4 -0
- package/attributes-master/packages/autovideo/tsconfig.json +3 -0
- package/attributes-master/packages/codehighlight/CHANGELOG.md +185 -0
- package/attributes-master/packages/codehighlight/README.md +27 -0
- package/attributes-master/packages/codehighlight/package.json +23 -0
- package/attributes-master/packages/codehighlight/src/actions/import.ts +50 -0
- package/attributes-master/packages/codehighlight/src/index.ts +3 -0
- package/attributes-master/packages/codehighlight/src/init.ts +53 -0
- package/attributes-master/packages/codehighlight/src/utils/constants.ts +24 -0
- package/attributes-master/packages/codehighlight/src/utils/selectors.ts +5 -0
- package/attributes-master/packages/codehighlight/src/utils/themes.ts +202 -0
- package/attributes-master/packages/codehighlight/tsconfig.json +3 -0
- package/attributes-master/packages/combobox/CHANGELOG.md +99 -0
- package/attributes-master/packages/combobox/README.md +27 -0
- package/attributes-master/packages/combobox/package.json +23 -0
- package/attributes-master/packages/combobox/src/actions/a11y.ts +29 -0
- package/attributes-master/packages/combobox/src/actions/body/index.ts +12 -0
- package/attributes-master/packages/combobox/src/actions/clearDropdown/index.ts +37 -0
- package/attributes-master/packages/combobox/src/actions/dropdownList/index.ts +220 -0
- package/attributes-master/packages/combobox/src/actions/dropdownToggle/index.ts +34 -0
- package/attributes-master/packages/combobox/src/actions/events.ts +75 -0
- package/attributes-master/packages/combobox/src/actions/input/index.ts +235 -0
- package/attributes-master/packages/combobox/src/actions/observe.ts +158 -0
- package/attributes-master/packages/combobox/src/actions/populate.ts +97 -0
- package/attributes-master/packages/combobox/src/actions/selectElement/index.ts +23 -0
- package/attributes-master/packages/combobox/src/actions/settings.ts +134 -0
- package/attributes-master/packages/combobox/src/actions/state.ts +34 -0
- package/attributes-master/packages/combobox/src/index.ts +3 -0
- package/attributes-master/packages/combobox/src/init.ts +52 -0
- package/attributes-master/packages/combobox/src/utils/constants.ts +48 -0
- package/attributes-master/packages/combobox/src/utils/dropdowns.ts +120 -0
- package/attributes-master/packages/combobox/src/utils/index.ts +1 -0
- package/attributes-master/packages/combobox/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/combobox/src/utils/types.ts +14 -0
- package/attributes-master/packages/combobox/tsconfig.json +3 -0
- package/attributes-master/packages/copyclip/CHANGELOG.md +213 -0
- package/attributes-master/packages/copyclip/README.md +27 -0
- package/attributes-master/packages/copyclip/package.json +23 -0
- package/attributes-master/packages/copyclip/src/factory.ts +67 -0
- package/attributes-master/packages/copyclip/src/index.ts +3 -0
- package/attributes-master/packages/copyclip/src/init.ts +68 -0
- package/attributes-master/packages/copyclip/src/utils/constants.ts +40 -0
- package/attributes-master/packages/copyclip/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/copyclip/tsconfig.json +3 -0
- package/attributes-master/packages/displayvalues/CHANGELOG.md +164 -0
- package/attributes-master/packages/displayvalues/README.md +27 -0
- package/attributes-master/packages/displayvalues/package.json +22 -0
- package/attributes-master/packages/displayvalues/src/actions/collect.ts +17 -0
- package/attributes-master/packages/displayvalues/src/actions/events.ts +22 -0
- package/attributes-master/packages/displayvalues/src/actions/sync.ts +23 -0
- package/attributes-master/packages/displayvalues/src/index.ts +3 -0
- package/attributes-master/packages/displayvalues/src/init.ts +31 -0
- package/attributes-master/packages/displayvalues/src/utils/constants.ts +20 -0
- package/attributes-master/packages/displayvalues/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/displayvalues/src/utils/stores.ts +3 -0
- package/attributes-master/packages/displayvalues/tsconfig.json +3 -0
- package/attributes-master/packages/docs/CHANGELOG.md +108 -0
- package/attributes-master/packages/docs/README.md +3 -0
- package/attributes-master/packages/docs/bin/build.js +92 -0
- package/attributes-master/packages/docs/bin/live-reload.js +1 -0
- package/attributes-master/packages/docs/package.json +40 -0
- package/attributes-master/packages/docs/src/copy.ts +260 -0
- package/attributes-master/packages/docs/src/x-ray.ts +377 -0
- package/attributes-master/packages/docs/tsconfig.json +3 -0
- package/attributes-master/packages/favcustom/CHANGELOG.md +194 -0
- package/attributes-master/packages/favcustom/README.md +27 -0
- package/attributes-master/packages/favcustom/package.json +22 -0
- package/attributes-master/packages/favcustom/src/index.ts +3 -0
- package/attributes-master/packages/favcustom/src/init.ts +30 -0
- package/attributes-master/packages/favcustom/src/utils/constants.ts +10 -0
- package/attributes-master/packages/favcustom/src/utils/selectors.ts +5 -0
- package/attributes-master/packages/favcustom/tsconfig.json +3 -0
- package/attributes-master/packages/formsubmit/CHANGELOG.md +161 -0
- package/attributes-master/packages/formsubmit/README.md +51 -0
- package/attributes-master/packages/formsubmit/package.json +22 -0
- package/attributes-master/packages/formsubmit/src/actions/redirect.ts +9 -0
- package/attributes-master/packages/formsubmit/src/actions/reset.ts +49 -0
- package/attributes-master/packages/formsubmit/src/actions/submit.ts +34 -0
- package/attributes-master/packages/formsubmit/src/components/Form.ts +231 -0
- package/attributes-master/packages/formsubmit/src/factory.ts +62 -0
- package/attributes-master/packages/formsubmit/src/index.ts +3 -0
- package/attributes-master/packages/formsubmit/src/init.ts +24 -0
- package/attributes-master/packages/formsubmit/src/utils/attributes.ts +19 -0
- package/attributes-master/packages/formsubmit/src/utils/constants.ts +89 -0
- package/attributes-master/packages/formsubmit/src/utils/dom.ts +76 -0
- package/attributes-master/packages/formsubmit/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/formsubmit/src/utils/types.ts +7 -0
- package/attributes-master/packages/formsubmit/tsconfig.json +3 -0
- package/attributes-master/packages/inject/CHANGELOG.md +117 -0
- package/attributes-master/packages/inject/README.md +60 -0
- package/attributes-master/packages/inject/package.json +22 -0
- package/attributes-master/packages/inject/src/actions/collect.ts +125 -0
- package/attributes-master/packages/inject/src/actions/css.ts +27 -0
- package/attributes-master/packages/inject/src/actions/prefetch.ts +44 -0
- package/attributes-master/packages/inject/src/factory.ts +123 -0
- package/attributes-master/packages/inject/src/index.ts +3 -0
- package/attributes-master/packages/inject/src/init.ts +22 -0
- package/attributes-master/packages/inject/src/utils/constants.ts +89 -0
- package/attributes-master/packages/inject/src/utils/helpers.ts +36 -0
- package/attributes-master/packages/inject/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/inject/src/utils/types.ts +16 -0
- package/attributes-master/packages/inject/tsconfig.json +3 -0
- package/attributes-master/packages/inputactive/CHANGELOG.md +58 -0
- package/attributes-master/packages/inputactive/README.md +25 -0
- package/attributes-master/packages/inputactive/package.json +22 -0
- package/attributes-master/packages/inputactive/src/actions/classes.ts +43 -0
- package/attributes-master/packages/inputactive/src/factory.ts +24 -0
- package/attributes-master/packages/inputactive/src/index.ts +3 -0
- package/attributes-master/packages/inputactive/src/init.ts +18 -0
- package/attributes-master/packages/inputactive/src/utils/constants.ts +13 -0
- package/attributes-master/packages/inputactive/src/utils/selectors.ts +5 -0
- package/attributes-master/packages/inputactive/tsconfig.json +3 -0
- package/attributes-master/packages/inputcounter/CHANGELOG.md +110 -0
- package/attributes-master/packages/inputcounter/README.md +25 -0
- package/attributes-master/packages/inputcounter/package.json +22 -0
- package/attributes-master/packages/inputcounter/src/actions/a11y.ts +23 -0
- package/attributes-master/packages/inputcounter/src/actions/buttons.ts +61 -0
- package/attributes-master/packages/inputcounter/src/actions/input.ts +31 -0
- package/attributes-master/packages/inputcounter/src/actions/style.ts +12 -0
- package/attributes-master/packages/inputcounter/src/factory.ts +51 -0
- package/attributes-master/packages/inputcounter/src/index.ts +3 -0
- package/attributes-master/packages/inputcounter/src/init.ts +22 -0
- package/attributes-master/packages/inputcounter/src/utils/constants.ts +59 -0
- package/attributes-master/packages/inputcounter/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/inputcounter/tsconfig.json +3 -0
- package/attributes-master/packages/list/CHANGELOG.md +185 -0
- package/attributes-master/packages/list/README.md +331 -0
- package/attributes-master/packages/list/package.json +37 -0
- package/attributes-master/packages/list/src/combine/index.ts +38 -0
- package/attributes-master/packages/list/src/components/List.ts +861 -0
- package/attributes-master/packages/list/src/components/ListItem.ts +229 -0
- package/attributes-master/packages/list/src/components/index.ts +2 -0
- package/attributes-master/packages/list/src/factory.ts +130 -0
- package/attributes-master/packages/list/src/filter/dynamic/conditions.ts +639 -0
- package/attributes-master/packages/list/src/filter/dynamic/groups.ts +221 -0
- package/attributes-master/packages/list/src/filter/dynamic/index.ts +119 -0
- package/attributes-master/packages/list/src/filter/dynamic/utils.ts +44 -0
- package/attributes-master/packages/list/src/filter/elements.ts +93 -0
- package/attributes-master/packages/list/src/filter/filter.ts +118 -0
- package/attributes-master/packages/list/src/filter/filter.worker.ts +152 -0
- package/attributes-master/packages/list/src/filter/index.ts +94 -0
- package/attributes-master/packages/list/src/filter/standard/conditions.ts +123 -0
- package/attributes-master/packages/list/src/filter/standard/facets.ts +253 -0
- package/attributes-master/packages/list/src/filter/standard/index.ts +176 -0
- package/attributes-master/packages/list/src/filter/standard/query.ts +111 -0
- package/attributes-master/packages/list/src/filter/tags.ts +314 -0
- package/attributes-master/packages/list/src/filter/types.ts +62 -0
- package/attributes-master/packages/list/src/filter/utils.ts +126 -0
- package/attributes-master/packages/list/src/index.ts +4 -0
- package/attributes-master/packages/list/src/init.ts +38 -0
- package/attributes-master/packages/list/src/load/all.ts +27 -0
- package/attributes-master/packages/list/src/load/elements.ts +39 -0
- package/attributes-master/packages/list/src/load/index.ts +63 -0
- package/attributes-master/packages/list/src/load/infinite.ts +79 -0
- package/attributes-master/packages/list/src/load/load.ts +191 -0
- package/attributes-master/packages/list/src/load/more.ts +97 -0
- package/attributes-master/packages/list/src/load/pagination.ts +402 -0
- package/attributes-master/packages/list/src/nest/index.ts +198 -0
- package/attributes-master/packages/list/src/prevnext/index.ts +98 -0
- package/attributes-master/packages/list/src/select/index.ts +56 -0
- package/attributes-master/packages/list/src/slider/index.ts +62 -0
- package/attributes-master/packages/list/src/sort/buttons.ts +96 -0
- package/attributes-master/packages/list/src/sort/dropdown.ts +179 -0
- package/attributes-master/packages/list/src/sort/index.ts +81 -0
- package/attributes-master/packages/list/src/sort/query.ts +63 -0
- package/attributes-master/packages/list/src/sort/select.ts +67 -0
- package/attributes-master/packages/list/src/sort/sort.ts +79 -0
- package/attributes-master/packages/list/src/sort/types.ts +28 -0
- package/attributes-master/packages/list/src/static/index.ts +73 -0
- package/attributes-master/packages/list/src/tabs/index.ts +97 -0
- package/attributes-master/packages/list/src/utils/constants.ts +728 -0
- package/attributes-master/packages/list/src/utils/dom.ts +108 -0
- package/attributes-master/packages/list/src/utils/pagination.ts +14 -0
- package/attributes-master/packages/list/src/utils/selectors.ts +18 -0
- package/attributes-master/packages/list/src/utils/store.ts +5 -0
- package/attributes-master/packages/list/tsconfig.json +3 -0
- package/attributes-master/packages/mirrorclick/CHANGELOG.md +171 -0
- package/attributes-master/packages/mirrorclick/README.md +25 -0
- package/attributes-master/packages/mirrorclick/package.json +22 -0
- package/attributes-master/packages/mirrorclick/src/index.ts +3 -0
- package/attributes-master/packages/mirrorclick/src/init.ts +35 -0
- package/attributes-master/packages/mirrorclick/src/utils/constants.ts +20 -0
- package/attributes-master/packages/mirrorclick/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/mirrorclick/tsconfig.json +3 -0
- package/attributes-master/packages/mirrorinput/CHANGELOG.md +172 -0
- package/attributes-master/packages/mirrorinput/README.md +25 -0
- package/attributes-master/packages/mirrorinput/package.json +22 -0
- package/attributes-master/packages/mirrorinput/src/index.ts +3 -0
- package/attributes-master/packages/mirrorinput/src/init.ts +48 -0
- package/attributes-master/packages/mirrorinput/src/utils/constants.ts +15 -0
- package/attributes-master/packages/mirrorinput/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/mirrorinput/tsconfig.json +3 -0
- package/attributes-master/packages/modal/CHANGELOG.md +94 -0
- package/attributes-master/packages/modal/README.md +29 -0
- package/attributes-master/packages/modal/package.json +23 -0
- package/attributes-master/packages/modal/src/actions/a11y.ts +46 -0
- package/attributes-master/packages/modal/src/actions/modal.ts +164 -0
- package/attributes-master/packages/modal/src/actions/settings.ts +21 -0
- package/attributes-master/packages/modal/src/factory.ts +26 -0
- package/attributes-master/packages/modal/src/index.ts +3 -0
- package/attributes-master/packages/modal/src/init.ts +22 -0
- package/attributes-master/packages/modal/src/utils/constants.ts +54 -0
- package/attributes-master/packages/modal/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/modal/src/utils/types.ts +12 -0
- package/attributes-master/packages/modal/tsconfig.json +3 -0
- package/attributes-master/packages/numbercount/CHANGELOG.md +90 -0
- package/attributes-master/packages/numbercount/README.md +27 -0
- package/attributes-master/packages/numbercount/package.json +23 -0
- package/attributes-master/packages/numbercount/src/actions/a11y.ts +26 -0
- package/attributes-master/packages/numbercount/src/actions/animate.ts +43 -0
- package/attributes-master/packages/numbercount/src/actions/observe.ts +44 -0
- package/attributes-master/packages/numbercount/src/factory.ts +31 -0
- package/attributes-master/packages/numbercount/src/index.ts +3 -0
- package/attributes-master/packages/numbercount/src/init.ts +22 -0
- package/attributes-master/packages/numbercount/src/utils/constants.ts +40 -0
- package/attributes-master/packages/numbercount/src/utils/helpers.ts +31 -0
- package/attributes-master/packages/numbercount/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/numbercount/tsconfig.json +3 -0
- package/attributes-master/packages/queryparam/CHANGELOG.md +118 -0
- package/attributes-master/packages/queryparam/README.md +25 -0
- package/attributes-master/packages/queryparam/package.json +22 -0
- package/attributes-master/packages/queryparam/src/factory.ts +51 -0
- package/attributes-master/packages/queryparam/src/index.ts +3 -0
- package/attributes-master/packages/queryparam/src/init.ts +40 -0
- package/attributes-master/packages/queryparam/src/utils/constants.ts +18 -0
- package/attributes-master/packages/queryparam/src/utils/selectors.ts +5 -0
- package/attributes-master/packages/queryparam/tsconfig.json +3 -0
- package/attributes-master/packages/rangeslider/CHANGELOG.md +236 -0
- package/attributes-master/packages/rangeslider/README.md +95 -0
- package/attributes-master/packages/rangeslider/package.json +23 -0
- package/attributes-master/packages/rangeslider/src/actions/a11y.ts +21 -0
- package/attributes-master/packages/rangeslider/src/actions/events.ts +9 -0
- package/attributes-master/packages/rangeslider/src/actions/settings.ts +97 -0
- package/attributes-master/packages/rangeslider/src/actions/styles.ts +10 -0
- package/attributes-master/packages/rangeslider/src/actions/values.ts +47 -0
- package/attributes-master/packages/rangeslider/src/components/Fill.ts +70 -0
- package/attributes-master/packages/rangeslider/src/components/Handle.ts +281 -0
- package/attributes-master/packages/rangeslider/src/factory.ts +100 -0
- package/attributes-master/packages/rangeslider/src/index.ts +3 -0
- package/attributes-master/packages/rangeslider/src/init.ts +194 -0
- package/attributes-master/packages/rangeslider/src/utils/constants.ts +87 -0
- package/attributes-master/packages/rangeslider/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/rangeslider/src/utils/types.ts +6 -0
- package/attributes-master/packages/rangeslider/tsconfig.json +3 -0
- package/attributes-master/packages/readtime/CHANGELOG.md +108 -0
- package/attributes-master/packages/readtime/README.md +25 -0
- package/attributes-master/packages/readtime/package.json +22 -0
- package/attributes-master/packages/readtime/src/factory.ts +21 -0
- package/attributes-master/packages/readtime/src/index.ts +3 -0
- package/attributes-master/packages/readtime/src/init.ts +19 -0
- package/attributes-master/packages/readtime/src/utils/constants.ts +33 -0
- package/attributes-master/packages/readtime/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/readtime/tsconfig.json +3 -0
- package/attributes-master/packages/removequery/CHANGELOG.md +8 -0
- package/attributes-master/packages/removequery/README.md +25 -0
- package/attributes-master/packages/removequery/package.json +22 -0
- package/attributes-master/packages/removequery/src/index.ts +3 -0
- package/attributes-master/packages/removequery/src/init.ts +18 -0
- package/attributes-master/packages/removequery/src/utils/constants.ts +5 -0
- package/attributes-master/packages/removequery/tsconfig.json +3 -0
- package/attributes-master/packages/scrolldisable/CHANGELOG.md +164 -0
- package/attributes-master/packages/scrolldisable/README.md +29 -0
- package/attributes-master/packages/scrolldisable/package.json +27 -0
- package/attributes-master/packages/scrolldisable/src/click.ts +40 -0
- package/attributes-master/packages/scrolldisable/src/display.ts +117 -0
- package/attributes-master/packages/scrolldisable/src/index.ts +3 -0
- package/attributes-master/packages/scrolldisable/src/init.ts +36 -0
- package/attributes-master/packages/scrolldisable/src/scroll.ts +63 -0
- package/attributes-master/packages/scrolldisable/src/utils/constants.ts +56 -0
- package/attributes-master/packages/scrolldisable/src/utils/selectors.ts +6 -0
- package/attributes-master/packages/scrolldisable/tsconfig.json +3 -0
- package/attributes-master/packages/selectcustom/CHANGELOG.md +242 -0
- package/attributes-master/packages/selectcustom/README.md +25 -0
- package/attributes-master/packages/selectcustom/package.json +23 -0
- package/attributes-master/packages/selectcustom/src/actions/a11y.ts +29 -0
- package/attributes-master/packages/selectcustom/src/actions/events.ts +159 -0
- package/attributes-master/packages/selectcustom/src/actions/observe.ts +83 -0
- package/attributes-master/packages/selectcustom/src/actions/populate.ts +67 -0
- package/attributes-master/packages/selectcustom/src/actions/settings.ts +68 -0
- package/attributes-master/packages/selectcustom/src/actions/state.ts +41 -0
- package/attributes-master/packages/selectcustom/src/index.ts +3 -0
- package/attributes-master/packages/selectcustom/src/init.ts +51 -0
- package/attributes-master/packages/selectcustom/src/utils/constants.ts +34 -0
- package/attributes-master/packages/selectcustom/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/selectcustom/src/utils/types.ts +14 -0
- package/attributes-master/packages/selectcustom/tsconfig.json +3 -0
- package/attributes-master/packages/sliderdots/CHANGELOG.md +220 -0
- package/attributes-master/packages/sliderdots/README.md +27 -0
- package/attributes-master/packages/sliderdots/package.json +22 -0
- package/attributes-master/packages/sliderdots/src/actions/events.ts +26 -0
- package/attributes-master/packages/sliderdots/src/actions/observe.ts +40 -0
- package/attributes-master/packages/sliderdots/src/actions/populate.ts +46 -0
- package/attributes-master/packages/sliderdots/src/actions/sync.ts +28 -0
- package/attributes-master/packages/sliderdots/src/actions/wait.ts +28 -0
- package/attributes-master/packages/sliderdots/src/factory.ts +57 -0
- package/attributes-master/packages/sliderdots/src/index.ts +3 -0
- package/attributes-master/packages/sliderdots/src/init.ts +30 -0
- package/attributes-master/packages/sliderdots/src/utils/constants.ts +33 -0
- package/attributes-master/packages/sliderdots/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/sliderdots/src/utils/types.ts +7 -0
- package/attributes-master/packages/sliderdots/tsconfig.json +3 -0
- package/attributes-master/packages/smartlightbox/CHANGELOG.md +203 -0
- package/attributes-master/packages/smartlightbox/README.md +25 -0
- package/attributes-master/packages/smartlightbox/package.json +22 -0
- package/attributes-master/packages/smartlightbox/src/actions/collect.ts +15 -0
- package/attributes-master/packages/smartlightbox/src/actions/move.ts +25 -0
- package/attributes-master/packages/smartlightbox/src/index.ts +3 -0
- package/attributes-master/packages/smartlightbox/src/init.ts +61 -0
- package/attributes-master/packages/smartlightbox/src/utils/constants.ts +31 -0
- package/attributes-master/packages/smartlightbox/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/smartlightbox/tsconfig.json +3 -0
- package/attributes-master/packages/socialshare/CHANGELOG.md +170 -0
- package/attributes-master/packages/socialshare/README.md +25 -0
- package/attributes-master/packages/socialshare/package.json +25 -0
- package/attributes-master/packages/socialshare/src/actions/collect.ts +93 -0
- package/attributes-master/packages/socialshare/src/actions/share.ts +91 -0
- package/attributes-master/packages/socialshare/src/actions/trigger.ts +46 -0
- package/attributes-master/packages/socialshare/src/factory.ts +149 -0
- package/attributes-master/packages/socialshare/src/index.ts +3 -0
- package/attributes-master/packages/socialshare/src/init.ts +35 -0
- package/attributes-master/packages/socialshare/src/utils/constants.ts +94 -0
- package/attributes-master/packages/socialshare/src/utils/dom.ts +8 -0
- package/attributes-master/packages/socialshare/src/utils/selectors.ts +6 -0
- package/attributes-master/packages/socialshare/src/utils/stores.ts +10 -0
- package/attributes-master/packages/socialshare/src/utils/types.ts +34 -0
- package/attributes-master/packages/socialshare/tsconfig.json +3 -0
- package/attributes-master/packages/starrating/CHANGELOG.md +70 -0
- package/attributes-master/packages/starrating/README.md +25 -0
- package/attributes-master/packages/starrating/package.json +22 -0
- package/attributes-master/packages/starrating/src/actions/classes.ts +41 -0
- package/attributes-master/packages/starrating/src/actions/events.ts +80 -0
- package/attributes-master/packages/starrating/src/factory.ts +24 -0
- package/attributes-master/packages/starrating/src/index.ts +3 -0
- package/attributes-master/packages/starrating/src/init.ts +24 -0
- package/attributes-master/packages/starrating/src/utils/constants.ts +20 -0
- package/attributes-master/packages/starrating/src/utils/helpers.ts +63 -0
- package/attributes-master/packages/starrating/src/utils/selectors.ts +9 -0
- package/attributes-master/packages/starrating/tsconfig.json +3 -0
- package/attributes-master/packages/template/README.md +25 -0
- package/attributes-master/packages/template/package.json +22 -0
- package/attributes-master/packages/template/src/actions/console.ts +4 -0
- package/attributes-master/packages/template/src/index.ts +3 -0
- package/attributes-master/packages/template/src/init.ts +14 -0
- package/attributes-master/packages/template/src/utils/constants.ts +18 -0
- package/attributes-master/packages/template/src/utils/selectors.ts +5 -0
- package/attributes-master/packages/template/tsconfig.json +3 -0
- package/attributes-master/packages/toc/CHANGELOG.md +192 -0
- package/attributes-master/packages/toc/README.md +25 -0
- package/attributes-master/packages/toc/package.json +23 -0
- package/attributes-master/packages/toc/src/actions/collect.ts +136 -0
- package/attributes-master/packages/toc/src/actions/create.ts +44 -0
- package/attributes-master/packages/toc/src/actions/events.ts +29 -0
- package/attributes-master/packages/toc/src/actions/observe.ts +31 -0
- package/attributes-master/packages/toc/src/actions/populate.ts +68 -0
- package/attributes-master/packages/toc/src/actions/prepare.ts +25 -0
- package/attributes-master/packages/toc/src/actions/scroll.ts +33 -0
- package/attributes-master/packages/toc/src/components/TOCItem.ts +88 -0
- package/attributes-master/packages/toc/src/factory.ts +47 -0
- package/attributes-master/packages/toc/src/index.ts +3 -0
- package/attributes-master/packages/toc/src/init.ts +37 -0
- package/attributes-master/packages/toc/src/utils/constants.ts +55 -0
- package/attributes-master/packages/toc/src/utils/helpers.ts +23 -0
- package/attributes-master/packages/toc/src/utils/selectors.ts +6 -0
- package/attributes-master/packages/toc/src/utils/types.ts +21 -0
- package/attributes-master/packages/toc/tsconfig.json +3 -0
- package/attributes-master/packages/utils/CHANGELOG.md +43 -0
- package/attributes-master/packages/utils/package.json +27 -0
- package/attributes-master/packages/utils/src/animations/factory.ts +100 -0
- package/attributes-master/packages/utils/src/animations/index.ts +73 -0
- package/attributes-master/packages/utils/src/animations/types.ts +37 -0
- package/attributes-master/packages/utils/src/components/Interaction.ts +79 -0
- package/attributes-master/packages/utils/src/components/Renderer.ts +59 -0
- package/attributes-master/packages/utils/src/components/index.ts +2 -0
- package/attributes-master/packages/utils/src/constants/a11y.ts +50 -0
- package/attributes-master/packages/utils/src/constants/attributes.ts +57 -0
- package/attributes-master/packages/utils/src/constants/index.ts +5 -0
- package/attributes-master/packages/utils/src/constants/keyboard.ts +10 -0
- package/attributes-master/packages/utils/src/constants/webflow.ts +74 -0
- package/attributes-master/packages/utils/src/helpers/dates.ts +17 -0
- package/attributes-master/packages/utils/src/helpers/dom.ts +82 -0
- package/attributes-master/packages/utils/src/helpers/events.ts +59 -0
- package/attributes-master/packages/utils/src/helpers/fetch.ts +217 -0
- package/attributes-master/packages/utils/src/helpers/forms.ts +238 -0
- package/attributes-master/packages/utils/src/helpers/guards.ts +138 -0
- package/attributes-master/packages/utils/src/helpers/index.ts +11 -0
- package/attributes-master/packages/utils/src/helpers/numbers.ts +86 -0
- package/attributes-master/packages/utils/src/helpers/selectors.ts +249 -0
- package/attributes-master/packages/utils/src/helpers/strings.ts +19 -0
- package/attributes-master/packages/utils/src/helpers/wait.ts +36 -0
- package/attributes-master/packages/utils/src/helpers/webflow.ts +117 -0
- package/attributes-master/packages/utils/src/index.ts +5 -0
- package/attributes-master/packages/utils/src/types/core.ts +100 -0
- package/attributes-master/packages/utils/src/types/dom.ts +31 -0
- package/attributes-master/packages/utils/src/types/index.ts +4 -0
- package/attributes-master/packages/utils/src/types/utils.ts +20 -0
- package/attributes-master/packages/utils/src/types/webflow.ts +147 -0
- package/attributes-master/packages/utils/tsconfig.json +3 -0
- package/attributes-master/packages/videohls/CHANGELOG.md +76 -0
- package/attributes-master/packages/videohls/README.md +27 -0
- package/attributes-master/packages/videohls/package.json +26 -0
- package/attributes-master/packages/videohls/src/actions/list.ts +23 -0
- package/attributes-master/packages/videohls/src/actions/video.ts +44 -0
- package/attributes-master/packages/videohls/src/index.ts +3 -0
- package/attributes-master/packages/videohls/src/init.ts +28 -0
- package/attributes-master/packages/videohls/src/utils/constants.ts +12 -0
- package/attributes-master/packages/videohls/src/utils/selectors.ts +5 -0
- package/attributes-master/packages/videohls/src/utils/stores.ts +3 -0
- package/attributes-master/packages/videohls/tsconfig.json +3 -0
- package/attributes-master/pnpm-lock.yaml +3317 -0
- package/attributes-master/pnpm-workspace.yaml +3 -0
- package/attributes-master/tsconfig.json +6 -0
- package/index.js +173 -257
- package/package.json +1 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ALLOWED_HEADINGS_SELECTOR,
|
|
3
|
+
ANCHOR_SELECTOR,
|
|
4
|
+
CUSTOM_HEADING_REGEXP,
|
|
5
|
+
DEFAULT_INITIAL_HEADING_LEVEL,
|
|
6
|
+
OMIT_HEADING_REGEXP,
|
|
7
|
+
} from '../utils/constants';
|
|
8
|
+
import { extractHeadingLevel } from '../utils/helpers';
|
|
9
|
+
import { getElementSelector } from '../utils/selectors';
|
|
10
|
+
import type { HeadingData, LinkData } from '../utils/types';
|
|
11
|
+
import { createHeadingWrapper } from './create';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Collects the {@link HeadingData} of all heading elements.
|
|
15
|
+
* @param contentsElement The element that holds all the contents.
|
|
16
|
+
*
|
|
17
|
+
* @returns A {@link HeadingData} array
|
|
18
|
+
*/
|
|
19
|
+
export const collectHeadingsData = ({ children }: HTMLElement) => {
|
|
20
|
+
const headingsData: HeadingData[] = [];
|
|
21
|
+
|
|
22
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
23
|
+
const child = children[i];
|
|
24
|
+
if (!child) continue;
|
|
25
|
+
|
|
26
|
+
const headingElement = child.closest<HTMLParagraphElement>(ALLOWED_HEADINGS_SELECTOR);
|
|
27
|
+
if (!headingElement) continue;
|
|
28
|
+
|
|
29
|
+
const { tagName, textContent } = headingElement;
|
|
30
|
+
if (!textContent) continue;
|
|
31
|
+
|
|
32
|
+
const omit = textContent.match(OMIT_HEADING_REGEXP);
|
|
33
|
+
if (omit) {
|
|
34
|
+
headingElement.textContent = textContent.replace(OMIT_HEADING_REGEXP, '').trim();
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const [customTag] = textContent.match(CUSTOM_HEADING_REGEXP) || [];
|
|
39
|
+
if (customTag) headingElement.textContent = textContent.replace(CUSTOM_HEADING_REGEXP, '').trim();
|
|
40
|
+
|
|
41
|
+
const level = extractHeadingLevel(customTag || tagName);
|
|
42
|
+
if (!level) continue;
|
|
43
|
+
|
|
44
|
+
const headingWrapper = createHeadingWrapper(headingElement);
|
|
45
|
+
if (!headingWrapper) continue;
|
|
46
|
+
|
|
47
|
+
const { id } = headingWrapper;
|
|
48
|
+
|
|
49
|
+
// Create a placeholder level memo when a heading level has been skipped
|
|
50
|
+
// Example: the user added an <h5> after an <h3>, he skipped the <h4> level
|
|
51
|
+
const [previousHeadingData] = headingsData;
|
|
52
|
+
|
|
53
|
+
if (previousHeadingData?.level) {
|
|
54
|
+
const correspondingLevel = previousHeadingData.level - 1;
|
|
55
|
+
|
|
56
|
+
if (level < correspondingLevel) {
|
|
57
|
+
for (let i = 1; i <= correspondingLevel - level; i++) {
|
|
58
|
+
headingsData.unshift({ level: previousHeadingData.level - i });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Render the wrapper
|
|
64
|
+
headingElement.insertAdjacentElement('beforebegin', headingWrapper);
|
|
65
|
+
|
|
66
|
+
// Group all lower elements under the wrapper
|
|
67
|
+
const nextHeading = headingsData.find((headingData) => headingData.level <= level);
|
|
68
|
+
const childrenSlice = Array.from(children).slice(i + 1);
|
|
69
|
+
|
|
70
|
+
for (const element of childrenSlice) {
|
|
71
|
+
if (element === nextHeading?.headingWrapper) break;
|
|
72
|
+
|
|
73
|
+
headingWrapper.append(element);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Store the data
|
|
77
|
+
headingsData.unshift({
|
|
78
|
+
level,
|
|
79
|
+
headingElement,
|
|
80
|
+
headingWrapper,
|
|
81
|
+
id,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return headingsData;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Collects the template links data.
|
|
90
|
+
* @param firstLinkTemplate
|
|
91
|
+
* @returns A {@link LinkData} array.
|
|
92
|
+
*/
|
|
93
|
+
export const collectLinksData = (firstLinkTemplate: Element) => {
|
|
94
|
+
const linksData: LinkData[] = [];
|
|
95
|
+
|
|
96
|
+
const collectLinkData = (referenceNode: Element) => {
|
|
97
|
+
// Query elements
|
|
98
|
+
const linkElement = referenceNode.closest('a');
|
|
99
|
+
if (!linkElement) return;
|
|
100
|
+
|
|
101
|
+
const component = linkElement.parentElement;
|
|
102
|
+
if (!component) return;
|
|
103
|
+
|
|
104
|
+
// Get the link level
|
|
105
|
+
const previousLevel = linksData[linksData.length - 1]?.level;
|
|
106
|
+
const level = previousLevel ? previousLevel + 1 : DEFAULT_INITIAL_HEADING_LEVEL;
|
|
107
|
+
|
|
108
|
+
linksData.push({
|
|
109
|
+
linkElement,
|
|
110
|
+
level,
|
|
111
|
+
component,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Get next link component
|
|
115
|
+
const followingTextNodes = [...component.querySelectorAll(`* ${getElementSelector('link')}`)];
|
|
116
|
+
const followingTextNode = followingTextNodes.find((node) => node !== referenceNode);
|
|
117
|
+
|
|
118
|
+
if (!followingTextNode) return component;
|
|
119
|
+
|
|
120
|
+
const followingComponent = collectLinkData(followingTextNode);
|
|
121
|
+
|
|
122
|
+
// Place the anchor
|
|
123
|
+
if (followingComponent) {
|
|
124
|
+
const anchor = new Comment(ANCHOR_SELECTOR);
|
|
125
|
+
component.insertBefore(anchor, followingComponent);
|
|
126
|
+
followingComponent.remove();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return component;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// Init collection
|
|
133
|
+
collectLinkData(firstLinkTemplate);
|
|
134
|
+
|
|
135
|
+
return linksData;
|
|
136
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import slugify from 'slugify';
|
|
2
|
+
|
|
3
|
+
import { ZERO_WIDTH_CHARS_REGEXP } from '../utils/constants';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a wrapper element for a heading and identifies it.
|
|
7
|
+
* @param headingElement
|
|
8
|
+
* @returns The new wrapper element.
|
|
9
|
+
*/
|
|
10
|
+
export const createHeadingWrapper = (headingElement: HTMLHeadingElement) => {
|
|
11
|
+
const headingWrapper = document.createElement('div');
|
|
12
|
+
|
|
13
|
+
const { id, textContent } = headingElement;
|
|
14
|
+
const trimmedTextContent = textContent?.trim().replace(ZERO_WIDTH_CHARS_REGEXP, '');
|
|
15
|
+
|
|
16
|
+
if (!id && !trimmedTextContent) return;
|
|
17
|
+
|
|
18
|
+
if (id) {
|
|
19
|
+
headingElement.removeAttribute('id');
|
|
20
|
+
headingWrapper.id = ensureUniqueId(id);
|
|
21
|
+
} else if (trimmedTextContent) {
|
|
22
|
+
const slugified = slugify(trimmedTextContent, { lower: true, strict: true });
|
|
23
|
+
headingWrapper.id = ensureUniqueId(slugified);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return headingWrapper;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Ensures that an element ID is unique on the page by adding an index suffix if necessary.
|
|
31
|
+
* @param requestedId
|
|
32
|
+
* @returns The unique ID.
|
|
33
|
+
*/
|
|
34
|
+
const ensureUniqueId = (requestedId: string) => {
|
|
35
|
+
let proposedId = requestedId;
|
|
36
|
+
let index = 2;
|
|
37
|
+
|
|
38
|
+
while (document.getElementById(proposedId)) {
|
|
39
|
+
proposedId = `${requestedId}-${index}`;
|
|
40
|
+
index += 1;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return proposedId;
|
|
44
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { addListener, isElement } from '@finsweet/attributes-utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Prevents the TOC links from adding the hash in the URL.
|
|
5
|
+
* @param tocWrapper
|
|
6
|
+
* @param hideURLHash Defines if the URL hash should be hidden after clicking the links.
|
|
7
|
+
*
|
|
8
|
+
* @returns A callback to remove the event listener.
|
|
9
|
+
*/
|
|
10
|
+
export const listenTOCLinkClicks = (tocWrapper: HTMLElement, hideURLHash?: boolean) => {
|
|
11
|
+
const clickCleanup = addListener(tocWrapper, 'click', (e) => {
|
|
12
|
+
if (!isElement(e.target)) return;
|
|
13
|
+
|
|
14
|
+
const link = e.target.closest('a');
|
|
15
|
+
if (!link) return;
|
|
16
|
+
|
|
17
|
+
e.stopPropagation();
|
|
18
|
+
|
|
19
|
+
if (!hideURLHash) return;
|
|
20
|
+
|
|
21
|
+
window.setTimeout(() => {
|
|
22
|
+
const { origin, pathname, search } = window.location;
|
|
23
|
+
|
|
24
|
+
history.replaceState('', document.title, origin + pathname + search);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return clickCleanup;
|
|
29
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isHTMLAnchorElement } from '@finsweet/attributes-utils';
|
|
2
|
+
|
|
3
|
+
import type { TOCItem } from '../components/TOCItem';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Observes when the TOC links' state changes.
|
|
7
|
+
* @param tocWrapper
|
|
8
|
+
* @param tocItems
|
|
9
|
+
*
|
|
10
|
+
* @returns The MutationObserver.
|
|
11
|
+
*/
|
|
12
|
+
export const observeLinksState = (tocWrapper: HTMLElement, tocItems: TOCItem[]) => {
|
|
13
|
+
const observer = new MutationObserver((mutations) => {
|
|
14
|
+
for (const { target } of mutations) {
|
|
15
|
+
if (!isHTMLAnchorElement(target)) continue;
|
|
16
|
+
|
|
17
|
+
const tocItem = tocItems.find(({ linkElement }) => linkElement === target);
|
|
18
|
+
if (!tocItem) continue;
|
|
19
|
+
|
|
20
|
+
tocItem.updateState();
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
observer.observe(tocWrapper, {
|
|
25
|
+
attributes: true,
|
|
26
|
+
subtree: true,
|
|
27
|
+
attributeFilter: ['class'],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return observer;
|
|
31
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { cloneNode } from '@finsweet/attributes-utils';
|
|
2
|
+
|
|
3
|
+
import { TOCItem } from '../components/TOCItem';
|
|
4
|
+
import { ANCHOR_SELECTOR } from '../utils/constants';
|
|
5
|
+
import { getElementSelector, queryElement } from '../utils/selectors';
|
|
6
|
+
import type { HeadingData, LinkData } from '../utils/types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Populates all links using the headings data.
|
|
10
|
+
* @param headingsData
|
|
11
|
+
* @param linksData
|
|
12
|
+
* @param tocWrapper
|
|
13
|
+
*/
|
|
14
|
+
export const populateLinks = (headingsData: HeadingData[], linksData: LinkData[], tocWrapper: HTMLElement) => {
|
|
15
|
+
const tocItems: TOCItem[] = [];
|
|
16
|
+
const levelsMemo: TOCItem[] = [];
|
|
17
|
+
|
|
18
|
+
for (const headingData of headingsData) {
|
|
19
|
+
// Get the corresponding link data
|
|
20
|
+
const linkData = linksData.find((data) => data.level === headingData.level);
|
|
21
|
+
if (!linkData) continue;
|
|
22
|
+
|
|
23
|
+
// Get the level memo
|
|
24
|
+
for (let i = levelsMemo.length - 1; i >= 0; i--) {
|
|
25
|
+
if (headingData.level > levelsMemo[i].level) break;
|
|
26
|
+
|
|
27
|
+
levelsMemo.pop();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const levelMemo = levelsMemo[levelsMemo.length - 1];
|
|
31
|
+
|
|
32
|
+
// Create the component
|
|
33
|
+
const linkWrapper = levelMemo?.component || tocWrapper;
|
|
34
|
+
const component = cloneNode(linkData.component);
|
|
35
|
+
|
|
36
|
+
const referenceNode = queryElement('link', { scope: component });
|
|
37
|
+
if (!referenceNode) continue;
|
|
38
|
+
|
|
39
|
+
const linkElement = referenceNode.closest('a');
|
|
40
|
+
if (!linkElement) continue;
|
|
41
|
+
|
|
42
|
+
const anchor = [...linkWrapper.childNodes].find(
|
|
43
|
+
({ nodeType, nodeValue }) => nodeType === 8 && nodeValue === ANCHOR_SELECTOR
|
|
44
|
+
);
|
|
45
|
+
if (!anchor) continue;
|
|
46
|
+
|
|
47
|
+
const ixTrigger = component.querySelector<HTMLElement>(`:scope > ${getElementSelector('ix-trigger')}`);
|
|
48
|
+
|
|
49
|
+
const tocItem = new TOCItem({
|
|
50
|
+
linkWrapper,
|
|
51
|
+
component,
|
|
52
|
+
referenceNode,
|
|
53
|
+
linkElement,
|
|
54
|
+
ixTrigger,
|
|
55
|
+
anchor,
|
|
56
|
+
...headingData,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Store the new level memo
|
|
60
|
+
if (!levelMemo || headingData.level > levelMemo.level) {
|
|
61
|
+
levelsMemo.push(tocItem);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
tocItems.push(tocItem);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return tocItems;
|
|
68
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ANCHOR_SELECTOR } from '../utils/constants';
|
|
2
|
+
import { queryElement } from '../utils/selectors';
|
|
3
|
+
import type { LinkData } from '../utils/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Queries the TOC wrapper and replaces the template links for an anchor placeholder.
|
|
7
|
+
* @param linksData
|
|
8
|
+
* @param instance
|
|
9
|
+
*
|
|
10
|
+
* @returns The TOC wrapper element.
|
|
11
|
+
*/
|
|
12
|
+
export const prepareTOC = ([{ component: firstLinkComponent }]: LinkData[], instance: string | null) => {
|
|
13
|
+
const tocWrapper = queryElement('table', { instance }) || firstLinkComponent.parentElement;
|
|
14
|
+
if (!tocWrapper) return;
|
|
15
|
+
|
|
16
|
+
const anchor = new Comment(ANCHOR_SELECTOR);
|
|
17
|
+
const isDirectChild = firstLinkComponent.parentElement === tocWrapper;
|
|
18
|
+
|
|
19
|
+
if (isDirectChild) tocWrapper.insertBefore(anchor, firstLinkComponent);
|
|
20
|
+
else tocWrapper.append(anchor);
|
|
21
|
+
|
|
22
|
+
firstLinkComponent.remove();
|
|
23
|
+
|
|
24
|
+
return tocWrapper;
|
|
25
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { TOCItem } from '../components/TOCItem';
|
|
2
|
+
import { getElementSelector } from '../utils/selectors';
|
|
3
|
+
import type { ScrollOffsetStyles } from '../utils/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sets scroll offset to all headings using CSS scroll-margin.
|
|
7
|
+
* @param tocWrapper
|
|
8
|
+
* @param tocItems
|
|
9
|
+
* @param offsets
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export const setScrollOffsets = (tocItems: TOCItem[], offsets: ScrollOffsetStyles) => {
|
|
13
|
+
if (!Object.values(offsets).some(Boolean)) return;
|
|
14
|
+
|
|
15
|
+
document.documentElement.style.scrollBehavior = 'smooth';
|
|
16
|
+
|
|
17
|
+
for (const tocItem of tocItems) {
|
|
18
|
+
tocItem.setScrollOffset(offsets);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Scrolls into view the currently active hash anchor in the URL, only if it's part of the table of contents.
|
|
24
|
+
*/
|
|
25
|
+
export const scrollToAnchor = () => {
|
|
26
|
+
const { hash } = window.location;
|
|
27
|
+
if (!hash) return;
|
|
28
|
+
|
|
29
|
+
const id = hash.replace('#', '');
|
|
30
|
+
const headingWrapper = document.querySelector(`${getElementSelector('contents')} [id="${id}"]`);
|
|
31
|
+
|
|
32
|
+
if (headingWrapper) headingWrapper.scrollIntoView({ behavior: 'smooth' });
|
|
33
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { CURRENT_CSS_CLASS, Interaction } from '@finsweet/attributes-utils';
|
|
2
|
+
|
|
3
|
+
import type { ScrollOffsetStyles, TOCData } from '../utils/types';
|
|
4
|
+
|
|
5
|
+
export class TOCItem implements TOCData {
|
|
6
|
+
public readonly level: number;
|
|
7
|
+
public readonly linkWrapper: HTMLElement;
|
|
8
|
+
public readonly referenceNode: Element;
|
|
9
|
+
public readonly anchor: Node;
|
|
10
|
+
public readonly component: HTMLElement;
|
|
11
|
+
public readonly linkElement: HTMLAnchorElement;
|
|
12
|
+
public readonly headingElement?: HTMLHeadingElement;
|
|
13
|
+
public readonly headingWrapper?: HTMLDivElement;
|
|
14
|
+
public readonly id?: string;
|
|
15
|
+
public readonly ixTrigger: HTMLElement | null;
|
|
16
|
+
|
|
17
|
+
private readonly interaction?: Interaction;
|
|
18
|
+
|
|
19
|
+
private currentState?: boolean;
|
|
20
|
+
|
|
21
|
+
constructor({
|
|
22
|
+
level,
|
|
23
|
+
component,
|
|
24
|
+
linkElement,
|
|
25
|
+
linkWrapper,
|
|
26
|
+
headingElement,
|
|
27
|
+
headingWrapper,
|
|
28
|
+
id,
|
|
29
|
+
ixTrigger,
|
|
30
|
+
referenceNode,
|
|
31
|
+
anchor,
|
|
32
|
+
}: TOCData) {
|
|
33
|
+
this.level = level;
|
|
34
|
+
this.linkWrapper = linkWrapper;
|
|
35
|
+
this.referenceNode = referenceNode;
|
|
36
|
+
this.anchor = anchor;
|
|
37
|
+
this.component = component;
|
|
38
|
+
this.linkElement = linkElement;
|
|
39
|
+
this.headingElement = headingElement;
|
|
40
|
+
this.headingWrapper = headingWrapper;
|
|
41
|
+
this.id = id;
|
|
42
|
+
this.ixTrigger = ixTrigger;
|
|
43
|
+
this.interaction = ixTrigger ? new Interaction({ element: ixTrigger }) : undefined;
|
|
44
|
+
|
|
45
|
+
this.#render();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Populates and the link in the TOC.
|
|
50
|
+
*/
|
|
51
|
+
#render() {
|
|
52
|
+
const { headingElement, id, referenceNode, linkElement, linkWrapper, component, anchor } = this;
|
|
53
|
+
|
|
54
|
+
if (headingElement && id) {
|
|
55
|
+
referenceNode.textContent = headingElement.textContent;
|
|
56
|
+
linkElement.href = `#${id}`;
|
|
57
|
+
} else {
|
|
58
|
+
linkElement.remove();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
linkWrapper.insertBefore(component, anchor);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Sets scroll offset to the heading using CSS scroll-margin.
|
|
66
|
+
* @param offsets
|
|
67
|
+
*/
|
|
68
|
+
public setScrollOffset(offsets: ScrollOffsetStyles) {
|
|
69
|
+
const { headingWrapper } = this;
|
|
70
|
+
|
|
71
|
+
if (headingWrapper) Object.assign(headingWrapper.style, offsets);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Updates the `active` state of the link and triggers the correspondent interaction, if existing.
|
|
76
|
+
*/
|
|
77
|
+
public updateState() {
|
|
78
|
+
const { linkElement, interaction, currentState } = this;
|
|
79
|
+
|
|
80
|
+
const isActive = linkElement.classList.contains(CURRENT_CSS_CLASS);
|
|
81
|
+
|
|
82
|
+
if (isActive === currentState) return;
|
|
83
|
+
|
|
84
|
+
interaction?.trigger(isActive ? 'first' : 'second');
|
|
85
|
+
|
|
86
|
+
this.currentState = isActive;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { collectHeadingsData, collectLinksData } from './actions/collect';
|
|
2
|
+
import { listenTOCLinkClicks } from './actions/events';
|
|
3
|
+
import { observeLinksState } from './actions/observe';
|
|
4
|
+
import { populateLinks } from './actions/populate';
|
|
5
|
+
import { prepareTOC } from './actions/prepare';
|
|
6
|
+
import { setScrollOffsets } from './actions/scroll';
|
|
7
|
+
import { getAttribute, getInstance, hasAttributeValue, queryElement } from './utils/selectors';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Inits a TOC instance.
|
|
11
|
+
* @param contentsElement
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export const initTOCInstance = (contentsElement: HTMLElement) => {
|
|
15
|
+
const instance = getInstance(contentsElement);
|
|
16
|
+
|
|
17
|
+
const linkTemplate = queryElement('link', { instance });
|
|
18
|
+
if (!linkTemplate) return;
|
|
19
|
+
|
|
20
|
+
const headingsData = collectHeadingsData(contentsElement);
|
|
21
|
+
const linksData = collectLinksData(linkTemplate) || [];
|
|
22
|
+
|
|
23
|
+
if (!headingsData.length || !linksData.length) return;
|
|
24
|
+
|
|
25
|
+
const tocWrapper = prepareTOC(linksData, instance);
|
|
26
|
+
if (!tocWrapper) return;
|
|
27
|
+
|
|
28
|
+
const tocItems = populateLinks(headingsData, linksData, tocWrapper);
|
|
29
|
+
|
|
30
|
+
// Scroll offset
|
|
31
|
+
const scrollMarginTop = getAttribute(contentsElement, 'offsettop');
|
|
32
|
+
const scrollMarginBottom = getAttribute(contentsElement, 'offsetbottom');
|
|
33
|
+
|
|
34
|
+
setScrollOffsets(tocItems, { scrollMarginTop, scrollMarginBottom });
|
|
35
|
+
|
|
36
|
+
// Handle TOC link clicks
|
|
37
|
+
const hideURLHash = hasAttributeValue(contentsElement, 'hideurlhash', 'true');
|
|
38
|
+
const removeListener = listenTOCLinkClicks(tocWrapper, hideURLHash);
|
|
39
|
+
|
|
40
|
+
// Link States
|
|
41
|
+
const observer = observeLinksState(tocWrapper, tocItems);
|
|
42
|
+
|
|
43
|
+
return () => {
|
|
44
|
+
removeListener();
|
|
45
|
+
observer.disconnect();
|
|
46
|
+
};
|
|
47
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type FinsweetAttributeInit,
|
|
3
|
+
isNotEmpty,
|
|
4
|
+
restartWebflow,
|
|
5
|
+
waitAttributeLoaded,
|
|
6
|
+
waitWebflowReady,
|
|
7
|
+
} from '@finsweet/attributes-utils';
|
|
8
|
+
|
|
9
|
+
import { scrollToAnchor } from './actions/scroll';
|
|
10
|
+
import { initTOCInstance } from './factory';
|
|
11
|
+
import { queryAllElements } from './utils/selectors';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Inits the attribute.
|
|
15
|
+
*/
|
|
16
|
+
export const init: FinsweetAttributeInit = async () => {
|
|
17
|
+
await waitWebflowReady();
|
|
18
|
+
await waitAttributeLoaded('inject');
|
|
19
|
+
|
|
20
|
+
const contentsElements = queryAllElements('contents');
|
|
21
|
+
|
|
22
|
+
const cleanups = contentsElements.map(initTOCInstance).filter(isNotEmpty);
|
|
23
|
+
|
|
24
|
+
// URL hash Anchor
|
|
25
|
+
scrollToAnchor();
|
|
26
|
+
|
|
27
|
+
if (cleanups.length) {
|
|
28
|
+
await restartWebflow();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// TODO: Finish API
|
|
32
|
+
return {
|
|
33
|
+
destroy() {
|
|
34
|
+
for (const cleanup of cleanups) cleanup();
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type AttributeElements, type AttributeSettings, TOC_ATTRIBUTE } from '@finsweet/attributes-utils';
|
|
2
|
+
|
|
3
|
+
export const ELEMENTS = [
|
|
4
|
+
/**
|
|
5
|
+
* Defines the contents to use as the table source.
|
|
6
|
+
*/
|
|
7
|
+
'contents',
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* OPTIONAL. Defines the wrapper element that will hold all the TOC links.
|
|
11
|
+
* If not defined, the library will use the immediate parent of the link template elements.
|
|
12
|
+
*/
|
|
13
|
+
'table',
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Defines a link template element.
|
|
17
|
+
* If the attribute is set to a non-link element, the library will look up for the first parent element that is a link.
|
|
18
|
+
*/
|
|
19
|
+
'link',
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Defines an interaction trigger.
|
|
23
|
+
* This attribute must be added to a hidden div and place it inside the correspondent link wrapper.
|
|
24
|
+
* When the link is active, it will trigger the "First Click" interaction. When the link is unactive, it will trigger the "Second Click" interaction.
|
|
25
|
+
*/
|
|
26
|
+
'ix-trigger',
|
|
27
|
+
] as const satisfies AttributeElements;
|
|
28
|
+
|
|
29
|
+
export const SETTINGS = {
|
|
30
|
+
/**
|
|
31
|
+
* Defines a [scroll-margin-top](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-margin-top) value for the headers.
|
|
32
|
+
*/
|
|
33
|
+
offsettop: { key: 'offsettop' },
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Defines a [scroll-margin-bottom](https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-margin-bottom) value for the headers.
|
|
37
|
+
*/
|
|
38
|
+
offsetbottom: { key: 'offsetbottom' },
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Defines if the links hash should be removed from the URL.
|
|
42
|
+
*/
|
|
43
|
+
hideurlhash: { key: 'hideurlhash', values: ['true'] },
|
|
44
|
+
} as const satisfies AttributeSettings;
|
|
45
|
+
|
|
46
|
+
export const DEFAULT_INITIAL_HEADING_LEVEL = 2;
|
|
47
|
+
export const ANCHOR_SELECTOR = `fs-${TOC_ATTRIBUTE}-anchor`;
|
|
48
|
+
|
|
49
|
+
const ALLOWED_HEADINGS_REGEX = '[2-6]';
|
|
50
|
+
export const ALLOWED_HEADINGS_SELECTOR = 'h2, h3, h4, h5, h6';
|
|
51
|
+
|
|
52
|
+
export const OMIT_HEADING_REGEXP = new RegExp(`^\\[fs-${TOC_ATTRIBUTE}-omit\\]`, 'i');
|
|
53
|
+
export const CUSTOM_HEADING_REGEXP = new RegExp(`^\\[fs-${TOC_ATTRIBUTE}-h${ALLOWED_HEADINGS_REGEX}\\]`, 'i');
|
|
54
|
+
export const HEADING_LEVEL_REGEXP = new RegExp(ALLOWED_HEADINGS_REGEX);
|
|
55
|
+
export const ZERO_WIDTH_CHARS_REGEXP = /[\u200B-\u200D\uFEFF]/g;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { HEADING_LEVEL_REGEXP } from './constants';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Extracts the heading level from a heading tag.
|
|
5
|
+
* @param value The heading tag.
|
|
6
|
+
*
|
|
7
|
+
* @example ```
|
|
8
|
+
* extractHeadingLevel('h2') // 2
|
|
9
|
+
* extractHeadingLevel('h5') // 5
|
|
10
|
+
* extractHeadingLevel('5') // 5
|
|
11
|
+
* extractHeadingLevel('hh') // undefined
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export const extractHeadingLevel = (value: string) => {
|
|
16
|
+
const rawLevel = value.match(HEADING_LEVEL_REGEXP)?.[0];
|
|
17
|
+
if (!rawLevel) return;
|
|
18
|
+
|
|
19
|
+
const level = parseInt(rawLevel);
|
|
20
|
+
if (isNaN(level)) return;
|
|
21
|
+
|
|
22
|
+
return level;
|
|
23
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { generateSelectors, TOC_ATTRIBUTE } from '@finsweet/attributes-utils';
|
|
2
|
+
|
|
3
|
+
import { ELEMENTS, SETTINGS } from './constants';
|
|
4
|
+
|
|
5
|
+
export const { getElementSelector, queryElement, getInstance, getAttribute, hasAttributeValue, queryAllElements } =
|
|
6
|
+
generateSelectors(TOC_ATTRIBUTE, ELEMENTS, SETTINGS);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface HeadingData {
|
|
2
|
+
level: number;
|
|
3
|
+
headingElement?: HTMLHeadingElement;
|
|
4
|
+
id?: string;
|
|
5
|
+
headingWrapper?: HTMLDivElement;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface LinkData {
|
|
9
|
+
level: number;
|
|
10
|
+
linkElement: HTMLAnchorElement;
|
|
11
|
+
component: HTMLElement;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TOCData extends HeadingData, LinkData {
|
|
15
|
+
referenceNode: Element;
|
|
16
|
+
linkWrapper: HTMLElement;
|
|
17
|
+
ixTrigger: HTMLElement | null;
|
|
18
|
+
anchor: Node;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type ScrollOffsetStyles = Partial<Pick<HTMLElement['style'], 'scrollMarginTop' | 'scrollMarginBottom'>>;
|