acinguiux-preact-components 0.0.1
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/package.json +56 -0
- package/src/content/themes/theme-acinguiux-amg/theme-acinguiux-amg.css +23 -0
- package/src/content/themes/theme-acinguiux-cafe/theme-acinguiux-cafe.css +47 -0
- package/src/content/themes/theme-acinguiux-energy/theme-acinguiux-energy.css +45 -0
- package/src/content/themes/theme-acinguiux-livewire/theme-acinguiux-livewire.css +22 -0
- package/src/content/themes/theme-acinguiux-livewire-italy/theme-acinguiux-livewire-italy.css +22 -0
- package/src/content/themes/theme-acinguiux-recharge/theme-acinguiux-recharge.css +49 -0
- package/src/content/themes/theme-allon/theme-allon.css +25 -0
- package/src/content/themes/theme-atlas/theme-atlas.css +31 -0
- package/src/content/themes/theme-aurvana/resources/favicon/apple-touch-icon.png +0 -0
- package/src/content/themes/theme-aurvana/resources/favicon/favico.ico +0 -0
- package/src/content/themes/theme-aurvana/resources/favicon/favicon-96x96.png +0 -0
- package/src/content/themes/theme-aurvana/resources/favicon/favicon.ico +0 -0
- package/src/content/themes/theme-aurvana/resources/favicon/favicon.png +0 -0
- package/src/content/themes/theme-aurvana/resources/favicon/favicon.svg +13 -0
- package/src/content/themes/theme-aurvana/resources/favicon/google-touch-icon.png +0 -0
- package/src/content/themes/theme-aurvana/resources/favicon/manifest.json +14 -0
- package/src/content/themes/theme-aurvana/resources/favicon/site.webmanifest +21 -0
- package/src/content/themes/theme-aurvana/resources/favicon/web-app-manifest-192x192.png +0 -0
- package/src/content/themes/theme-aurvana/resources/favicon/web-app-manifest-512x512.png +0 -0
- package/src/content/themes/theme-aurvana/theme-aurvana.css +49 -0
- package/src/content/themes/theme-base/theme-base.css +49 -0
- package/src/content/themes/theme-base2/resources/favicon/android-chrome-192x192.png +0 -0
- package/src/content/themes/theme-base2/resources/favicon/android-chrome-512x512.png +0 -0
- package/src/content/themes/theme-base2/resources/favicon/apple-touch-icon.png +0 -0
- package/src/content/themes/theme-base2/resources/favicon/favico.ico +0 -0
- package/src/content/themes/theme-base2/resources/favicon/favicon-16x16.png +0 -0
- package/src/content/themes/theme-base2/resources/favicon/favicon-32x32.png +0 -0
- package/src/content/themes/theme-base2/resources/favicon/favicon-96x96.png +0 -0
- package/src/content/themes/theme-base2/resources/favicon/favicon.ico +0 -0
- package/src/content/themes/theme-base2/resources/favicon/favicon.png +0 -0
- package/src/content/themes/theme-base2/resources/favicon/favicon.svg +9 -0
- package/src/content/themes/theme-base2/resources/favicon/google-touch-icon.png +0 -0
- package/src/content/themes/theme-base2/resources/favicon/manifest.json +14 -0
- package/src/content/themes/theme-base2/resources/favicon/site.webmanifest +1 -0
- package/src/content/themes/theme-base2/resources/favicon/web-app-manifest-192x192.png +0 -0
- package/src/content/themes/theme-base2/resources/favicon/web-app-manifest-512x512.png +0 -0
- package/src/content/themes/theme-base2/resources/fonts/acinguiux-typeface-la-heavy-221208.woff2 +0 -0
- package/src/content/themes/theme-base2/theme-base2.css +47 -0
- package/src/content/themes/theme-eco-marathon/theme-eco-marathon.css +22 -0
- package/src/content/themes/theme-energy-transition-campus-amsterdam/theme-energy-transition-campus-amsterdam.css +26 -0
- package/src/content/themes/theme-evpass/theme-evpass.css +46 -0
- package/src/content/themes/theme-nam-2025/resources/favicon/apple-touch-icon.png +0 -0
- package/src/content/themes/theme-nam-2025/resources/favicon/favico.ico +0 -0
- package/src/content/themes/theme-nam-2025/resources/favicon/favicon-96x96.png +0 -0
- package/src/content/themes/theme-nam-2025/resources/favicon/favicon.ico +0 -0
- package/src/content/themes/theme-nam-2025/resources/favicon/favicon.png +0 -0
- package/src/content/themes/theme-nam-2025/resources/favicon/favicon.svg +9 -0
- package/src/content/themes/theme-nam-2025/resources/favicon/google-touch-icon.png +0 -0
- package/src/content/themes/theme-nam-2025/resources/favicon/manifest.json +14 -0
- package/src/content/themes/theme-nam-2025/resources/favicon/site.webmanifest +21 -0
- package/src/content/themes/theme-nam-2025/resources/favicon/web-app-manifest-192x192.png +0 -0
- package/src/content/themes/theme-nam-2025/resources/favicon/web-app-manifest-512x512.png +0 -0
- package/src/content/themes/theme-nam-2025/theme-nam-2025.css +47 -0
- package/src/content/themes/theme-pennzoil/theme-pennzoil.css +36 -0
- package/src/content/themes/theme-quaker-state/theme-quaker-state.css +63 -0
- package/src/content/themes/theme-tafawoq/theme-tafawoq.css +26 -0
- package/src/content/themes/theme-vegetable/resources/favicon/apple-touch-icon.png +0 -0
- package/src/content/themes/theme-vegetable/resources/favicon/favico.ico +0 -0
- package/src/content/themes/theme-vegetable/resources/favicon/favicon-96x96.png +0 -0
- package/src/content/themes/theme-vegetable/resources/favicon/favicon.ico +0 -0
- package/src/content/themes/theme-vegetable/resources/favicon/favicon.png +0 -0
- package/src/content/themes/theme-vegetable/resources/favicon/favicon.svg +13 -0
- package/src/content/themes/theme-vegetable/resources/favicon/google-touch-icon.png +0 -0
- package/src/content/themes/theme-vegetable/resources/favicon/manifest.json +14 -0
- package/src/content/themes/theme-vegetable/resources/favicon/site.webmanifest +21 -0
- package/src/content/themes/theme-vegetable/resources/favicon/web-app-manifest-192x192.png +0 -0
- package/src/content/themes/theme-vegetable/resources/favicon/web-app-manifest-512x512.png +0 -0
- package/src/content/themes/theme-vegetable/theme-vegetable.css +49 -0
- package/src/content/themes/theme-zeolyst/resources/fonts/type-ar-medium.woff2 +0 -0
- package/src/content/themes/theme-zeolyst/theme-zeolyst.css +29 -0
- package/src/main/atoms/audio.js +16 -0
- package/src/main/atoms/box.js +5 -0
- package/src/main/atoms/button.js +40 -0
- package/src/main/atoms/card.js +22 -0
- package/src/main/atoms/form.js +30 -0
- package/src/main/atoms/heading.js +17 -0
- package/src/main/atoms/icon.js +24 -0
- package/src/main/atoms/img.js +131 -0
- package/src/main/atoms/input.js +55 -0
- package/src/main/atoms/link-text.js +21 -0
- package/src/main/atoms/link.js +60 -0
- package/src/main/atoms/list.js +12 -0
- package/src/main/atoms/logo.js +9 -0
- package/src/main/atoms/menu.js +10 -0
- package/src/main/atoms/message.js +5 -0
- package/src/main/atoms/nav-link.js +49 -0
- package/src/main/atoms/popup.js +47 -0
- package/src/main/atoms/rich-text.js +128 -0
- package/src/main/atoms/scroller.js +224 -0
- package/src/main/atoms/svg.js +65 -0
- package/src/main/atoms/table.js +32 -0
- package/src/main/atoms/textarea.js +10 -0
- package/src/main/atoms/time.js +12 -0
- package/src/main/atoms/video.js +100 -0
- package/src/main/export-main.js +12 -0
- package/src/main/export-matter.js +86 -0
- package/src/main/export-preact-hooks.js +1 -0
- package/src/main/export-preact.js +1 -0
- package/src/main/index.js +13 -0
- package/src/main/molecules/asset.js +23 -0
- package/src/main/molecules/glossary.js +44 -0
- package/src/main/molecules/links.js +23 -0
- package/src/main/molecules/promo-text.js +27 -0
- package/src/main/molecules/tags.js +15 -0
- package/src/main/molecules/tree.js +51 -0
- package/src/main/organisms/accordion-item.js +106 -0
- package/src/main/organisms/author.js +29 -0
- package/src/main/organisms/breadcrumb.js +69 -0
- package/src/main/organisms/call-to-action.js +24 -0
- package/src/main/organisms/carousel.js +178 -0
- package/src/main/organisms/cart-item.js +156 -0
- package/src/main/organisms/cart.js +162 -0
- package/src/main/organisms/contact-form.js +141 -0
- package/src/main/organisms/container/ab-test.js +47 -0
- package/src/main/organisms/container/default.js +6 -0
- package/src/main/organisms/container/filtered-section.js +293 -0
- package/src/main/organisms/container/footer.js +12 -0
- package/src/main/organisms/container/grid.js +44 -0
- package/src/main/organisms/container/header.js +13 -0
- package/src/main/organisms/container/list.js +7 -0
- package/src/main/organisms/container/main.js +6 -0
- package/src/main/organisms/container/raw.js +7 -0
- package/src/main/organisms/container/section.js +28 -0
- package/src/main/organisms/container.js +29 -0
- package/src/main/organisms/content-owner.js +15 -0
- package/src/main/organisms/date-entry.js +56 -0
- package/src/main/organisms/external-search.js +73 -0
- package/src/main/organisms/filtered-item.js +163 -0
- package/src/main/organisms/footer-item.js +17 -0
- package/src/main/organisms/image-gallery.js +164 -0
- package/src/main/organisms/last-modified.js +20 -0
- package/src/main/organisms/legal-footer.js +16 -0
- package/src/main/organisms/list-item.js +48 -0
- package/src/main/organisms/metadata.js +11 -0
- package/src/main/organisms/navigation.js +232 -0
- package/src/main/organisms/notification.js +87 -0
- package/src/main/organisms/order-tracker.js +203 -0
- package/src/main/organisms/page-header-banner.js +26 -0
- package/src/main/organisms/page-header.js +33 -0
- package/src/main/organisms/page-tags.js +14 -0
- package/src/main/organisms/page.js +260 -0
- package/src/main/organisms/press-release.js +24 -0
- package/src/main/organisms/product-admin.js +204 -0
- package/src/main/organisms/promo-banner.js +28 -0
- package/src/main/organisms/promo-bottom.js +23 -0
- package/src/main/organisms/promo-button.js +8 -0
- package/src/main/organisms/promo-card-cover.js +35 -0
- package/src/main/organisms/promo-card.js +33 -0
- package/src/main/organisms/promo-full.js +20 -0
- package/src/main/organisms/promo-image.js +22 -0
- package/src/main/organisms/promo-lure.js +22 -0
- package/src/main/organisms/promo-product-card.js +187 -0
- package/src/main/organisms/promo-product-full.js +293 -0
- package/src/main/organisms/promo-simple.js +23 -0
- package/src/main/organisms/quote.js +21 -0
- package/src/main/organisms/search-form.js +42 -0
- package/src/main/organisms/search-nav.js +66 -0
- package/src/main/organisms/search-result.js +53 -0
- package/src/main/organisms/slider.js +26 -0
- package/src/main/organisms/standalone-asset.js +22 -0
- package/src/main/organisms/tabs.js +277 -0
- package/src/main/organisms/topbar.js +83 -0
- package/src/main/organisms/web-component.js +53 -0
- package/src/main/routing/annotation.js +9 -0
- package/src/main/routing/component.js +138 -0
- package/src/main/routing/empty.js +5 -0
- package/src/main/routing/error-handler.js +64 -0
- package/src/main/routing/placeholder-image.svg +5 -0
- package/src/main/routing/router.js +219 -0
- package/src/main/shared/analytics.js +677 -0
- package/src/main/shared/bubble-event.js +11 -0
- package/src/main/shared/custom-element.js +21 -0
- package/src/main/shared/deep-selector.js +28 -0
- package/src/main/shared/disable-transparency.js +10 -0
- package/src/main/shared/format-time.js +8 -0
- package/src/main/shared/get-id.js +5 -0
- package/src/main/shared/get-meta.js +3 -0
- package/src/main/shared/get-size-class.js +3 -0
- package/src/main/shared/get-size.js +11 -0
- package/src/main/shared/h.js +88 -0
- package/src/main/shared/hash-jump.js +33 -0
- package/src/main/shared/icons/arrow-back.svg +1 -0
- package/src/main/shared/icons/arrow-down.svg +1 -0
- package/src/main/shared/icons/arrow-next.svg +1 -0
- package/src/main/shared/icons/arrow-tail-right.svg +1 -0
- package/src/main/shared/icons/arrow-tail-up.svg +1 -0
- package/src/main/shared/icons/arrow-up.svg +1 -0
- package/src/main/shared/icons/asset-download.svg +1 -0
- package/src/main/shared/icons/logo.svg +5 -0
- package/src/main/shared/icons/low-carbon-placeholder.svg +9 -0
- package/src/main/shared/icons/media-pause.svg +1 -0
- package/src/main/shared/icons/media-play.svg +1 -0
- package/src/main/shared/icons/navigation-burger.svg +1 -0
- package/src/main/shared/icons/navigation-close.svg +1 -0
- package/src/main/shared/icons/navigation-link.svg +1 -0
- package/src/main/shared/icons/navigation-refresh.svg +1 -0
- package/src/main/shared/icons/navigation-search.svg +1 -0
- package/src/main/shared/icons/navigation-share.svg +1 -0
- package/src/main/shared/icons/toggle-newwindow.svg +1 -0
- package/src/main/shared/icons.js +18 -0
- package/src/main/shared/id-from-string.js +5 -0
- package/src/main/shared/mark-selection.js +19 -0
- package/src/main/shared/register.js +26 -0
- package/src/main/shared/renderer.js +43 -0
- package/src/main/shared/simple-consent-api.js +70 -0
- package/src/main/shared/split-links.js +11 -0
- package/src/main/shared/t.js +60 -0
- package/src/main/shared/twind.js +837 -0
- package/src/main/shared/update-head.js +34 -0
- package/src/main/shared/update-scrollbar-width.js +30 -0
- package/src/main/shared/use-link.js +151 -0
- package/src/main/shared/use-persistent-state.js +42 -0
- package/src/main/shared/wait-for-dom-ready.js +6 -0
- package/src/main/shared/wcm-mode.js +4 -0
- package/src/wcs/components/acinguiux-preact-doc/acinguiux-preact-doc.js +207 -0
- package/src/wcs/components/admin-dashboard/admin-dashboard.js +487 -0
- package/src/wcs/components/admin-login/admin-login.js +91 -0
- package/src/wcs/components/bazaar-voice/bazaar-voice.js +56 -0
- package/src/wcs/components/chatbot-koreai/chatbot-koreai.js +176 -0
- package/src/wcs/components/chatbot-koreai/koreai-transport.js +217 -0
- package/src/wcs/components/chatbot-ms/chatbot-ms.js +210 -0
- package/src/wcs/components/chatbot-test/chatbot-test.js +44 -0
- package/src/wcs/components/comparison-chart/comparison-chart.js +111 -0
- package/src/wcs/components/consent-banner/consent-banner.js +248 -0
- package/src/wcs/components/consent-banner/icons/ccpa.svg +6 -0
- package/src/wcs/components/consent-banner/icons/info.svg +1 -0
- package/src/wcs/components/consent-banner/provider-onetrust.js +131 -0
- package/src/wcs/components/decision-tree/arrow-back.svg +3 -0
- package/src/wcs/components/decision-tree/badges.js +37 -0
- package/src/wcs/components/decision-tree/decision-tree.js +162 -0
- package/src/wcs/components/dynamic-contact-details/dynamic-contact-details.js +111 -0
- package/src/wcs/components/example-accordion/example-accordion.js +10 -0
- package/src/wcs/components/example-asset/example-asset.js +12 -0
- package/src/wcs/components/example-form/example-form.js +59 -0
- package/src/wcs/components/example-nested/example-nested.js +10 -0
- package/src/wcs/components/example-routing/example-routing.js +51 -0
- package/src/wcs/components/example-rtl/example-rtl.js +28 -0
- package/src/wcs/components/example-tabs/example-tabs.js +12 -0
- package/src/wcs/components/example-web-component/example-web-component.js +34 -0
- package/src/wcs/components/floating-button/floating-button.js +17 -0
- package/src/wcs/components/formstack-form/fields/address.js +38 -0
- package/src/wcs/components/formstack-form/fields/checkbox.js +42 -0
- package/src/wcs/components/formstack-form/fields/date.js +22 -0
- package/src/wcs/components/formstack-form/fields/description.js +8 -0
- package/src/wcs/components/formstack-form/fields/input.js +8 -0
- package/src/wcs/components/formstack-form/fields/name.js +39 -0
- package/src/wcs/components/formstack-form/fields/radio.js +24 -0
- package/src/wcs/components/formstack-form/fields/rating.js +53 -0
- package/src/wcs/components/formstack-form/fields/section.js +8 -0
- package/src/wcs/components/formstack-form/fields/select.js +10 -0
- package/src/wcs/components/formstack-form/fields/textarea.js +8 -0
- package/src/wcs/components/formstack-form/fields/wrapper.js +11 -0
- package/src/wcs/components/formstack-form/formstack-form.js +280 -0
- package/src/wcs/components/fuel-prices/fuel-prices.js +45 -0
- package/src/wcs/components/furniture-overview/furniture-overview.js +115 -0
- package/src/wcs/components/gauge-value/gauge-value.js +65 -0
- package/src/wcs/components/help-centre/api.js +150 -0
- package/src/wcs/components/help-centre/help-centre.js +400 -0
- package/src/wcs/components/help-centre/icon-search.svg +1 -0
- package/src/wcs/components/image-gen/admin-panel.js +248 -0
- package/src/wcs/components/image-gen/image-gen.js +385 -0
- package/src/wcs/components/image-gen/labels.js +37 -0
- package/src/wcs/components/image-gen/use-api.js +392 -0
- package/src/wcs/components/inspired-gallery/inspired-gallery.js +118 -0
- package/src/wcs/components/launch-container/launch-container.js +95 -0
- package/src/wcs/components/launch-container/ledger.js +140 -0
- package/src/wcs/components/lng-map/lng-map.js +44 -0
- package/src/wcs/components/mouseflow-analytics/mouseflow-analytics.js +39 -0
- package/src/wcs/components/msds-search/msds-search.js +127 -0
- package/src/wcs/components/msds-search/navigation-search.svg +3 -0
- package/src/wcs/components/product-catalogue/icon-back.svg +3 -0
- package/src/wcs/components/product-catalogue/icon-cart.svg +3 -0
- package/src/wcs/components/product-catalogue/icon-close.svg +3 -0
- package/src/wcs/components/product-catalogue/product-catalogue.js +215 -0
- package/src/wcs/components/product-links/icon-cart.svg +3 -0
- package/src/wcs/components/product-links/product-links.js +43 -0
- package/src/wcs/components/rio-iframe/rio-iframe.js +137 -0
- package/src/wcs/components/salsify-products/filter-tools.js +60 -0
- package/src/wcs/components/salsify-products/icon-cart.svg +3 -0
- package/src/wcs/components/salsify-products/process-products.js +53 -0
- package/src/wcs/components/salsify-products/route-tools.js +54 -0
- package/src/wcs/components/salsify-products/salsify-products.js +281 -0
- package/src/wcs/components/shout-out/shout-out.js +51 -0
- package/src/wcs/components/simple-chart/simple-chart.js +53 -0
- package/src/wcs/components/single-stat/single-stat.js +85 -0
- package/src/wcs/components/site-feedback/site-feedback.js +56 -0
- package/src/wcs/components/skds-search/navigation-search.svg +3 -0
- package/src/wcs/components/skds-search/skds-search.js +103 -0
- package/src/wcs/components/smart-banner/smart-banner.js +104 -0
- package/src/wcs/components/standalone-table/arrow-up-down.svg +3 -0
- package/src/wcs/components/standalone-table/arrow-up.svg +3 -0
- package/src/wcs/components/standalone-table/standalone-table.js +440 -0
- package/src/wcs/components/station-locator/station-locator.js +49 -0
- package/src/wcs/components/store-badges/badges.js +60 -0
- package/src/wcs/components/store-badges/store-badges.js +93 -0
- package/src/wcs/components/topbar-button/person.svg +1 -0
- package/src/wcs/components/topbar-button/topbar-button.js +22 -0
- package/src/wcs/components/universal-gallery/universal-gallery.js +308 -0
- package/src/wcs/components/zendesk-chat/zendesk-chat.js +133 -0
- package/src/wcs/shared/chat-bot/README.md +61 -0
- package/src/wcs/shared/chat-bot/chat-bot.js +216 -0
- package/src/wcs/shared/chat-bot/resources/arrow-next.svg +1 -0
- package/src/wcs/shared/chat-bot/resources/navigation-close.svg +1 -0
- package/src/wcs/shared/chat-bot/resources/person.svg +1 -0
- package/src/wcs/shared/chat-bot/resources/upload.svg +1 -0
- package/src/wcs/shared/filtered-data/README.md +52 -0
- package/src/wcs/shared/filtered-data/fetch-data.js +33 -0
- package/src/wcs/shared/filtered-data/filtered-data.js +337 -0
- package/src/wcs/shared/promo-with-popup/icon-close.svg +3 -0
- package/src/wcs/shared/promo-with-popup/icon-next.svg +3 -0
- package/src/wcs/shared/promo-with-popup/icon-prev.svg +3 -0
- package/src/wcs/shared/promo-with-popup/promo-with-popup.js +93 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function findElement (name, attrs) {
|
|
2
|
+
const attrString = Object.entries(attrs).map(([k, v]) => `[${k}="${v}"]`).join('')
|
|
3
|
+
const selector = `${name}${attrString}`
|
|
4
|
+
|
|
5
|
+
return document.querySelector(selector)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function setAttrs (element, attrs) {
|
|
9
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
10
|
+
// Set only if different. Prevents re-setting styles.
|
|
11
|
+
if (element.getAttribute(k) !== v) {
|
|
12
|
+
element.setAttribute(k, v)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default function updateHead (name, attrsToSearch, attrsToSet) {
|
|
18
|
+
const remove = Object.values(attrsToSet).every(a => a === null || a === undefined)
|
|
19
|
+
let element = findElement(name, attrsToSearch)
|
|
20
|
+
|
|
21
|
+
if (remove) {
|
|
22
|
+
element?.remove()
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!element) {
|
|
27
|
+
// Create element if does not exist.
|
|
28
|
+
element = document.createElement(name)
|
|
29
|
+
setAttrs(element, attrsToSearch)
|
|
30
|
+
document.head.appendChild(element)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setAttrs(element, attrsToSet)
|
|
34
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const STYLE = [
|
|
2
|
+
'overflow-y: scroll',
|
|
3
|
+
'width: 100px',
|
|
4
|
+
'height: 100px',
|
|
5
|
+
'position: absolute',
|
|
6
|
+
'top: -9999'
|
|
7
|
+
].join('; ')
|
|
8
|
+
const DEBOUNCE = 500
|
|
9
|
+
|
|
10
|
+
function setScrollbarWidthProperty () {
|
|
11
|
+
const div = document.createElement('div')
|
|
12
|
+
div.setAttribute('style', STYLE)
|
|
13
|
+
document.body.appendChild(div)
|
|
14
|
+
const scrollbarWidth = div.offsetWidth - div.clientWidth
|
|
15
|
+
div.remove()
|
|
16
|
+
|
|
17
|
+
document.documentElement.style.setProperty('--scrollbar-width', `${scrollbarWidth}px`)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function updateScrollbarWidth () {
|
|
21
|
+
setScrollbarWidthProperty()
|
|
22
|
+
|
|
23
|
+
let resizeId = null
|
|
24
|
+
window.addEventListener('resize', () => {
|
|
25
|
+
clearTimeout(resizeId)
|
|
26
|
+
resizeId = setTimeout(() => {
|
|
27
|
+
setScrollbarWidthProperty()
|
|
28
|
+
}, DEBOUNCE)
|
|
29
|
+
})
|
|
30
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/* global location, confirm, history */
|
|
2
|
+
import { useLayoutEffect, useState } from 'preact/hooks'
|
|
3
|
+
import getMeta from './get-meta.js'
|
|
4
|
+
import getSize from './get-size.js'
|
|
5
|
+
|
|
6
|
+
const DOWNLOADABLE_EXTENSIONS = new Set(['zip', 'pdf', 'docx', 'xlsx', 'pptx', 'txt', 'csv', 'xps'])
|
|
7
|
+
const DOMAIN_WHITELIST = [
|
|
8
|
+
'google.com',
|
|
9
|
+
'facebook.com',
|
|
10
|
+
'fuelrewards.com',
|
|
11
|
+
'instagram.com',
|
|
12
|
+
'linkedin.com',
|
|
13
|
+
'primeenergy.com.br',
|
|
14
|
+
'raizen.com',
|
|
15
|
+
'raizen.com.br',
|
|
16
|
+
'sonnen.de',
|
|
17
|
+
'twitter.com',
|
|
18
|
+
'ubitricity.com',
|
|
19
|
+
'vk.com',
|
|
20
|
+
'weibo.com',
|
|
21
|
+
'x.com',
|
|
22
|
+
'youku.com',
|
|
23
|
+
'youtube.com',
|
|
24
|
+
'share.google',
|
|
25
|
+
]
|
|
26
|
+
// Treat localhost as a trusted domain (similar behaviour to acinguiux domains) to ensure consistent behaviour in dev and prod.
|
|
27
|
+
const LITERAL_WHITELIST = ['i.youku.com', 'localhost', 'wa.me']
|
|
28
|
+
const WHITELIST = new Set([...DOMAIN_WHITELIST.flatMap(w => [w, `www.${w}`]), ...LITERAL_WHITELIST])
|
|
29
|
+
|
|
30
|
+
// -----------------------------------------------------------------------------
|
|
31
|
+
// Main export
|
|
32
|
+
// -----------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+
// Simple link cache.
|
|
35
|
+
const cache = {}
|
|
36
|
+
|
|
37
|
+
export default function useLink ({ href, text, target }) {
|
|
38
|
+
const [state, setState] = useState({ text, target })
|
|
39
|
+
// Resolve cached links.
|
|
40
|
+
const key = `${href} :: ${text} :: ${target}`
|
|
41
|
+
if (cache[key]) {
|
|
42
|
+
return cache[key]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
useLayoutEffect(() => {
|
|
46
|
+
const resolveLink = async () => {
|
|
47
|
+
if (!href) {
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Javascript link sanitisation.
|
|
52
|
+
const urlObj = new URL(href, location)
|
|
53
|
+
|
|
54
|
+
// eslint-disable-next-line sonarjs/code-eval
|
|
55
|
+
if (['javascript:', 'vbscript:', 'data:'].some(p => href.startsWith(p))) {
|
|
56
|
+
console.error(`Invalid URL: '${href}'`)
|
|
57
|
+
return null
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const newState = { ...state, text, href }
|
|
61
|
+
|
|
62
|
+
if (isHashOnlyLink(urlObj)) {
|
|
63
|
+
return newState
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (isDownloadLink(urlObj)) {
|
|
67
|
+
const downloadSuffix = await getDownloadSuffix(href)
|
|
68
|
+
return { ...newState, text: text + downloadSuffix, target: '_blank', isDownload: true }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (isExternalLink(urlObj) && isTrustedLink(urlObj)) {
|
|
72
|
+
return { ...newState, onClick: target === '_blank' ? undefined : navigationHandler }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (isExternalLink(urlObj)) {
|
|
76
|
+
return { ...newState, target: '_blank', onClick: getDisclaimerHandler('external-disclaimer-text') }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (isPageLink(urlObj)) {
|
|
80
|
+
// Do not handle navigation when forced to new window.
|
|
81
|
+
return { ...newState, onClick: target === '_blank' ? undefined : navigationHandler }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return newState
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
resolveLink().then(newState => {
|
|
88
|
+
newState && setState(newState)
|
|
89
|
+
cache[key] = newState ?? state
|
|
90
|
+
})
|
|
91
|
+
}, [href, text, target])
|
|
92
|
+
|
|
93
|
+
return state
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// -----------------------------------------------------------------------------
|
|
97
|
+
// Helpers
|
|
98
|
+
// -----------------------------------------------------------------------------
|
|
99
|
+
|
|
100
|
+
export function isDownloadLink ({ href }) {
|
|
101
|
+
const ext = href?.substring?.(href?.lastIndexOf?.('.') + 1)
|
|
102
|
+
return DOWNLOADABLE_EXTENSIONS.has(ext)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function isTrustedLink ({ hostname }) {
|
|
106
|
+
return hostname?.includes?.('acinguiux') || WHITELIST.has(hostname)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function isExternalLink ({ hostname }) {
|
|
110
|
+
return hostname && hostname !== location.hostname
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function isHashOnlyLink ({ hash, href }) {
|
|
114
|
+
return hash && href.replace(/#.*/, '') === location.href.replace(/#.*/, '')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function isPageLink ({ hostname, pathname }) {
|
|
118
|
+
return location.hostname === hostname && (pathname.endsWith('/') || pathname.includes('.html'))
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function getDisclaimerHandler (meta) {
|
|
122
|
+
const disclaimerText = getMeta(meta)
|
|
123
|
+
return disclaimerText ? event => !confirm(disclaimerText) && event.preventDefault() : null
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function getDownloadSuffix (href) {
|
|
127
|
+
const ext = href.substring(href.lastIndexOf('.') + 1)
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const res = await fetch(href, { headers: { Range: 'bytes=0-0' } })
|
|
131
|
+
const contentRange = res.headers.get('content-range')
|
|
132
|
+
const length = /bytes \d+-\d+\/(\d+)/.exec(contentRange)?.[1]
|
|
133
|
+
const fileSize = getSize(length)
|
|
134
|
+
return ` (${ext.toUpperCase()}, ${fileSize})`
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.log(`Unable to resolve file size: ${href}`, error)
|
|
137
|
+
return ` (${ext.toUpperCase()})`
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function navigationHandler (event) {
|
|
142
|
+
const el = event.currentTarget
|
|
143
|
+
const elUrl = el.getAttribute('action') || el.getAttribute('href')
|
|
144
|
+
|
|
145
|
+
// Disable handler when forcing a new tab (ctrl + click).
|
|
146
|
+
if (!event.defaultPrevented && !event.ctrlKey && !event.altKey && !event.metaKey) {
|
|
147
|
+
history.pushState({}, '', elUrl)
|
|
148
|
+
globalThis.dispatchEvent(new Event('popstate'))
|
|
149
|
+
event.preventDefault()
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useState, useLayoutEffect } from 'preact/hooks'
|
|
2
|
+
|
|
3
|
+
const PREFIX = 'acinguiux-preact_'
|
|
4
|
+
|
|
5
|
+
export default function usePersistentState (key, initialState) {
|
|
6
|
+
const [state, setState] = useState(getGlobal(key) ?? initialState)
|
|
7
|
+
setGlobal(key, state) // Save initial state.
|
|
8
|
+
|
|
9
|
+
useLayoutEffect(() => {
|
|
10
|
+
// Update local state when the global state changes.
|
|
11
|
+
const listener = () => {
|
|
12
|
+
// Prevent empty state.
|
|
13
|
+
const globalState = getGlobal(key) ?? initialState
|
|
14
|
+
setState(globalState)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
globalThis.addEventListener('storage', listener)
|
|
18
|
+
return () => globalThis.removeEventListener('storage', listener)
|
|
19
|
+
}, [key])
|
|
20
|
+
|
|
21
|
+
const setPersistentState = callback => {
|
|
22
|
+
const newState = callback(getGlobal(key))
|
|
23
|
+
|
|
24
|
+
// Update both global and local states.
|
|
25
|
+
if (JSON.stringify(newState) !== JSON.stringify(state)) {
|
|
26
|
+
setGlobal(key, newState)
|
|
27
|
+
// Force change in the same window.
|
|
28
|
+
globalThis.dispatchEvent(new Event('storage'))
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return [state, setPersistentState]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getGlobal (key) {
|
|
36
|
+
const value = localStorage.getItem(`${PREFIX}${key}`)
|
|
37
|
+
return value ? JSON.parse(value) : null
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function setGlobal (key, value) {
|
|
41
|
+
localStorage.setItem(`${PREFIX}${key}`, JSON.stringify(value))
|
|
42
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/* global location */
|
|
2
|
+
import { marked } from 'marked'
|
|
3
|
+
import { UTILS } from '#acinguiux-preact/main/shared/twind.js'
|
|
4
|
+
import idFromString from '#acinguiux-preact/main/shared/id-from-string.js'
|
|
5
|
+
|
|
6
|
+
const { h, register, matter, preactHooks, dataset, version } = globalThis.ami
|
|
7
|
+
const { Box, Link, RichText, List, Table, Heading } = matter
|
|
8
|
+
const { useState, useEffect } = preactHooks
|
|
9
|
+
|
|
10
|
+
const JS_EXAMPLE_PATTERN = /```js example(.+?(?=```))```/gs
|
|
11
|
+
const MATTER = Object.keys(globalThis.ami.matter).map(key => `const ${key} = window.ami.matter.${key}`).join('\n')
|
|
12
|
+
|
|
13
|
+
function getData () {
|
|
14
|
+
const signature = new URL(location.href)
|
|
15
|
+
signature.pathname = signature.pathname.replace(/.html$/, '.model.json')
|
|
16
|
+
signature.search = ''
|
|
17
|
+
signature.hash = ''
|
|
18
|
+
|
|
19
|
+
const data = dataset[signature.href]
|
|
20
|
+
?.children[0] // WebComponent
|
|
21
|
+
?.model
|
|
22
|
+
?.text
|
|
23
|
+
|
|
24
|
+
return { data }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getTitleAndText (topicData) {
|
|
28
|
+
let title = ''
|
|
29
|
+
const text = topicData
|
|
30
|
+
// Add hash links.
|
|
31
|
+
.replaceAll(/(Atoms|Molecules|Organisms|Misc)\.([A-Za-z0-9]+)/gm, (match, _p1, p2) => `[${match}](#${p2.toLowerCase()})`)
|
|
32
|
+
// Remove examples.
|
|
33
|
+
.replaceAll(JS_EXAMPLE_PATTERN, '')
|
|
34
|
+
.replaceAll(/^# (.*)$/gm, (_match, g1) => {
|
|
35
|
+
title = g1
|
|
36
|
+
return ''
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
return [title, text]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getExamples (topicData) {
|
|
43
|
+
const examples = []
|
|
44
|
+
topicData.replaceAll(JS_EXAMPLE_PATTERN, (_match, p1) => {
|
|
45
|
+
examples.push(p1.trim())
|
|
46
|
+
return ''
|
|
47
|
+
})
|
|
48
|
+
return examples
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getElementByHash () {
|
|
52
|
+
return document.getElementsByTagName('acinguiux-preact-doc')?.[0].shadowRoot.getElementById(location.hash?.substring(1))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function Styles () {
|
|
56
|
+
return h('div', { className: 'space-y-4 mt-6' },
|
|
57
|
+
h(Heading, { _level: 2, _size: 4 }, 'Utility class reference'),
|
|
58
|
+
h(Table,
|
|
59
|
+
h('tr',
|
|
60
|
+
h('th', { className: 'w-1/5' }, 'Name'),
|
|
61
|
+
h('th', 'Style')
|
|
62
|
+
),
|
|
63
|
+
Array.from(UTILS).map(([util, css]) => h('tr',
|
|
64
|
+
h('td',
|
|
65
|
+
h('code', { className: 'text-xs' }, util)
|
|
66
|
+
),
|
|
67
|
+
h('td',
|
|
68
|
+
h('pre',
|
|
69
|
+
h('code', { className: 'text-xs break-all whitespace-pre-wrap' }, css.replace(' }', '}'))
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
))
|
|
73
|
+
)
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function Markdown ({ content }) {
|
|
78
|
+
const renderer = {
|
|
79
|
+
heading ({ text, depth }) {
|
|
80
|
+
const level = depth === 2 ? 3 : depth
|
|
81
|
+
// Decrease the size of H2 for better readability.
|
|
82
|
+
return `<h${depth} _level="${level}">${text}</h${depth}>`
|
|
83
|
+
},
|
|
84
|
+
code ({ text }) {
|
|
85
|
+
return `<pre><code>${sanitizeTags(text)}</code></pre>`
|
|
86
|
+
},
|
|
87
|
+
codespan ({ text }) {
|
|
88
|
+
return `<code data-topic-code>${sanitizeTags(text)}</code>`
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
marked.use({ renderer })
|
|
92
|
+
const markedText = marked(content)
|
|
93
|
+
return h(RichText, markedText)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function TopicLink ({ topic }) {
|
|
97
|
+
return h(Link, {
|
|
98
|
+
_variant: 'underline',
|
|
99
|
+
_model: { name: topic, value: `#${topic.toLowerCase()}` }
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function Preview ({ example }) {
|
|
104
|
+
const code = `(function () {
|
|
105
|
+
const { h, preactHooks } = window.ami
|
|
106
|
+
const { useState } = preactHooks
|
|
107
|
+
${MATTER}
|
|
108
|
+
return ${example}
|
|
109
|
+
})()
|
|
110
|
+
`
|
|
111
|
+
|
|
112
|
+
let result
|
|
113
|
+
try {
|
|
114
|
+
result = (0, eval)(code) // eslint-disable-line no-eval
|
|
115
|
+
} catch (error) {
|
|
116
|
+
console.error(code)
|
|
117
|
+
console.error(error)
|
|
118
|
+
result = 'ERROR: Unable to parse!'
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return result
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function Example ({ example }) {
|
|
125
|
+
return h('div', { className: 'lg:grid grid-cols-2 bg-bga text-txa border-txa/20 border-t' },
|
|
126
|
+
h('div', { className: 'col-span-1 p-4 border-l border-r bg-bga text-txa border-txa/20' },
|
|
127
|
+
h('div', { className: 'bg-bga text-txa border-txa/20' },
|
|
128
|
+
h(Preview, { example })
|
|
129
|
+
)
|
|
130
|
+
),
|
|
131
|
+
h('div', { className: 'col-span-1 p-4 border-r bg-bga text-txa border-txa/20 md:border sm:border sm:break-all' },
|
|
132
|
+
h('pre', { className: 'text-sm' },
|
|
133
|
+
h('code', { className: 'whitespace-pre-wrap break-all' }, example)
|
|
134
|
+
)
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Define Preact component.
|
|
140
|
+
function AcinguiuxPreactDoc () {
|
|
141
|
+
const [state, setState] = useState({})
|
|
142
|
+
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
setState(getData())
|
|
145
|
+
// Jump to element on hash change.
|
|
146
|
+
globalThis.addEventListener('hashchange', () => {
|
|
147
|
+
getElementByHash()?.scrollIntoView()
|
|
148
|
+
})
|
|
149
|
+
}, [])
|
|
150
|
+
|
|
151
|
+
if (!state.data) {
|
|
152
|
+
return null
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Get topics.
|
|
156
|
+
const sections = []
|
|
157
|
+
for (const [category, categoryData] of Object.entries(state.data)) {
|
|
158
|
+
for (const [topic, topicData] of Object.entries(categoryData)) {
|
|
159
|
+
const [title, text] = getTitleAndText(topicData)
|
|
160
|
+
const examples = getExamples(topicData)
|
|
161
|
+
|
|
162
|
+
sections.push(h(Box,
|
|
163
|
+
// Use z-10 for sticky elements.
|
|
164
|
+
h('div', { className: 'sticky top-0 bg-bga border-txa/20 border-b pb-2 z-10' },
|
|
165
|
+
h(Heading, { _level: 1, id: idFromString(title) },
|
|
166
|
+
h(Link, {
|
|
167
|
+
_variant: 'simple',
|
|
168
|
+
_model: { name: `${category} :: ${title}`, value: `#${title.toLowerCase()}` }
|
|
169
|
+
})
|
|
170
|
+
)
|
|
171
|
+
),
|
|
172
|
+
h('div', { className: 'space-y-2' },
|
|
173
|
+
text && h(Markdown, { content: text }),
|
|
174
|
+
examples.length > 0 && h('div', { className: 'bg-bga text-txa border-txa/20 lg:border-b md:space-y-5 sm:space-y-5' }, examples.map(example =>
|
|
175
|
+
h(Example, { key: topic, example })
|
|
176
|
+
)),
|
|
177
|
+
topic === 'Styles' && h(Styles)
|
|
178
|
+
)
|
|
179
|
+
))
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return state.data && h('div', { className: 'bg-bga text-txa' },
|
|
184
|
+
h('div', { className: 'lg:flex m-auto', style: 'max-width: 1500px' },
|
|
185
|
+
// Navigation.
|
|
186
|
+
h(Box, { className: 'grow-0 shrink-0' },
|
|
187
|
+
h('p', version),
|
|
188
|
+
Object.keys(state.data).map(category => [
|
|
189
|
+
h('h3', { className: 'font-custom text-2xl' }, category),
|
|
190
|
+
h(List, Object.keys(state.data[category]).map(topic =>
|
|
191
|
+
h('li',
|
|
192
|
+
h(TopicLink, { topic })
|
|
193
|
+
)
|
|
194
|
+
))
|
|
195
|
+
])
|
|
196
|
+
),
|
|
197
|
+
// Topic body.
|
|
198
|
+
h('div', sections)
|
|
199
|
+
)
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function sanitizeTags (text) {
|
|
204
|
+
return text.replaceAll('<', '<').replaceAll('>', '>')
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
register(AcinguiuxPreactDoc, 'acinguiux-preact-doc')
|