{"version":3,"file":"page_gallery_controller-PTPsyqEu.js","names":[],"sources":["../../../app/javascript/controllers/page_share_controller.js","../../../app/javascript/controllers/page_gallery_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\"\n\n// \"Save this page\" on a QR code page (AccountPagesHelper#account_page_save).\n//\n// A web page can't add a bookmark by itself — no phone browser allows it — so\n// the button hands the page's address to the phone's own share sheet, where the\n// shopper bookmarks it, texts it or mails it to themselves with their own apps.\n// Nothing is sent by us. Where a browser has no share sheet (most desktops) the\n// button copies the link instead and says so.\n//\n// The button is rendered hidden and shown here, so a page without script never\n// shows a button that does nothing: it keeps the two plain links under it,\n// which open the shopper's mail and messages with the address filled in. Those\n// links step aside once the share sheet is on offer.\n//\n//
\n// \n//

…mailto: and sms: links…

\n// \n//
\nexport default class extends Controller {\n static targets = [\"button\", \"links\", \"done\"]\n static values = { url: String }\n\n connect() {\n this.buttonTarget.hidden = false\n if (navigator.share) this.linksTarget.hidden = true\n }\n\n async share() {\n const url = this.urlValue || window.location.href\n\n if (navigator.share) {\n // Closing the sheet without picking anything is not a failure.\n try { await navigator.share({ title: document.title, url }) } catch (error) { if (error.name !== \"AbortError\") console.error(\"Share failed\", error) }\n return\n }\n\n await this.copy(url)\n this.doneTarget.hidden = false\n }\n\n // The async Clipboard API only exists on a secure page; a plain-http page\n // (development) falls back to the old selection copy.\n async copy(text) {\n if (navigator.clipboard && window.isSecureContext) return navigator.clipboard.writeText(text)\n\n const field = Object.assign(document.createElement(\"textarea\"), { value: text })\n field.setAttribute(\"readonly\", \"\")\n field.style.position = \"fixed\"\n field.style.opacity = \"0\"\n document.body.append(field)\n field.select()\n document.execCommand(\"copy\")\n field.remove()\n }\n}\n","import { Controller } from \"@hotwired/stimulus\"\n\n// A gallery on a QR code page (AccountPagesHelper#account_page_gallery): one\n// picture at a time, sliding across to the next.\n//\n// The sliding itself is the stylesheet's — the pictures sit in a row that\n// snaps one to the frame, so a finger swipes through them with no script at\n// all. This adds what a swipe can't do: the gallery moves on by itself every\n// few seconds, arrows step it for somebody with a mouse, and the dots under it\n// say how many pictures there are and which one is showing.\n//\n// The arrows and dots are rendered hidden and shown here, so a page without\n// script shows no button that does nothing. Once somebody takes over — an\n// arrow, a dot, a swipe — it stops moving by itself: nothing is worse than a\n// picture leaving while you look at it. It never moves by itself for somebody\n// who asked their device for less motion, nor on the builder's canvas\n// (interval 0), where it would slide about under the person editing it.\n//\n//
\n//
\n// \n// \n// \n//
\nexport default class extends Controller {\n static targets = [\"track\", \"control\", \"dot\"]\n static values = { interval: { type: Number, default: 4500 } }\n\n connect() {\n if (this.count < 2) return\n\n this.controlTargets.forEach((control) => { control.hidden = false })\n this.mark = this.mark.bind(this)\n this.rest = this.rest.bind(this)\n this.begin = this.begin.bind(this)\n this.trackTarget.addEventListener(\"scroll\", this.mark, { passive: true })\n // A finger or a wheel on the pictures: they are being looked at.\n this.trackTarget.addEventListener(\"pointerdown\", this.rest, { passive: true })\n this.trackTarget.addEventListener(\"wheel\", this.rest, { passive: true })\n this.listening = true\n this.mark()\n\n // Not before the page itself has arrived: the first picture comes first.\n if (document.readyState === \"complete\") this.begin()\n else window.addEventListener(\"load\", this.begin, { once: true })\n }\n\n disconnect() {\n this.rest()\n if (!this.listening) return\n\n this.listening = false\n window.removeEventListener(\"load\", this.begin)\n this.trackTarget.removeEventListener(\"scroll\", this.mark)\n this.trackTarget.removeEventListener(\"pointerdown\", this.rest)\n this.trackTarget.removeEventListener(\"wheel\", this.rest)\n }\n\n previous() {\n this.rest()\n this.show(this.index - 1)\n }\n\n next() {\n this.rest()\n this.show(this.index + 1)\n }\n\n go(event) {\n this.rest()\n this.show(event.params.index)\n }\n\n get count() {\n return this.trackTarget.children.length\n }\n\n // Which picture fills the frame: how many frame-widths the row has moved.\n get index() {\n const width = this.trackTarget.clientWidth\n return width ? Math.round(this.trackTarget.scrollLeft / width) : 0\n }\n\n // Past the last picture comes the first again, and the other way round.\n show(index) {\n const to = ((index % this.count) + this.count) % this.count\n this.trackTarget.scrollTo({ left: to * this.trackTarget.clientWidth, behavior: \"smooth\" })\n }\n\n mark() {\n const index = this.index\n this.dotTargets.forEach((dot, place) => dot.setAttribute(\"aria-current\", String(place === index)))\n }\n\n // The page has loaded. The pictures waiting their turn are fetched now: they\n // are marked lazy, and a browser fetches a lazy picture in a row only as it\n // comes into view — which here would be halfway through its slide. Then the\n // gallery starts moving, unless somebody has already taken over.\n begin() {\n this.trackTarget.querySelectorAll(\"img[loading='lazy']\").forEach((picture) => { picture.loading = \"eager\" })\n if (this.resting || !this.intervalValue || window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return\n\n this.timer = setInterval(() => this.show(this.index + 1), this.intervalValue)\n }\n\n // Stop moving by itself, for good: somebody is looking.\n rest() {\n this.resting = true\n clearInterval(this.timer)\n this.timer = null\n }\n}\n"],"mappings":"2CAoBA,IAAA,EAAA,cAA6B,CAAW,CACtC,OAAO,QAAU,CAAC,SAAU,QAAS,OAAO,CAC5C,OAAO,OAAS,CAAE,IAAK,OAAQ,CAE/B,SAAU,CACR,KAAK,aAAa,OAAS,GACvB,UAAU,QAAO,KAAK,YAAY,OAAS,IAGjD,MAAM,OAAQ,CACZ,IAAM,EAAM,KAAK,UAAY,OAAO,SAAS,KAE7C,GAAI,UAAU,MAAO,CAEnB,GAAI,CAAE,MAAM,UAAU,MAAM,CAAE,MAAO,SAAS,MAAO,MAAK,CAAC,OAAU,EAAO,CAAM,EAAM,OAAS,cAAc,QAAQ,MAAM,eAAgB,EAAM,CACnJ,OAGF,MAAM,KAAK,KAAK,EAAI,CACpB,KAAK,WAAW,OAAS,GAK3B,MAAM,KAAK,EAAM,CACf,GAAI,UAAU,WAAa,OAAO,gBAAiB,OAAO,UAAU,UAAU,UAAU,EAAK,CAE7F,IAAM,EAAQ,OAAO,OAAO,SAAS,cAAc,WAAW,CAAE,CAAE,MAAO,EAAM,CAAC,CAChF,EAAM,aAAa,WAAY,GAAG,CAClC,EAAM,MAAM,SAAW,QACvB,EAAM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