studio-engine 0.135.2 → 0.137.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +64 -11
- data/README.md +10 -0
- data/app/assets/javascripts/studio/cropper-1.6.2.min.js +10 -0
- data/app/assets/javascripts/studio/page_transition_reveal.js +3 -0
- data/app/assets/stylesheets/studio/cropper-1.6.2.min.css +9 -0
- data/app/controllers/concerns/studio/connection_flow.rb +215 -0
- data/app/controllers/concerns/studio/error_handling.rb +58 -1
- data/app/controllers/studio/connections_controller.rb +13 -0
- data/app/helpers/studio/page_header_helper.rb +26 -0
- data/app/helpers/studio_navbar_helper.rb +22 -0
- data/app/javascript/studio/application.js +1 -0
- data/app/javascript/studio/cropper.js +2 -2
- data/app/javascript/studio/page_header_self_styled.js +194 -0
- data/app/javascript/studio/page_transitions.js +42 -11
- data/app/javascript/studio/reload_visits.js +93 -0
- data/app/models/studio/connection.rb +137 -0
- data/app/models/studio/user_session.rb +216 -21
- data/app/views/layouts/_navbar.html.erb +11 -4
- data/app/views/studio/_cropper_assets.html.erb +14 -9
- data/app/views/studio/_legal_page.html.erb +52 -0
- data/app/views/studio/_page_header.html.erb +12 -2
- data/app/views/studio/page_header/_assets.html.erb +151 -0
- data/db/migrate/20261108120000_add_device_revocation_to_studio_user_sessions.rb +28 -0
- data/db/migrate/20261108130000_create_studio_connections.rb +35 -0
- data/lib/generators/studio/connections/connections_generator.rb +93 -0
- data/lib/studio/connections/stand_in.rb +89 -0
- data/lib/studio/connections.rb +483 -0
- data/lib/studio/engine.rb +14 -1
- data/lib/studio/host_schema.rb +53 -2
- data/lib/studio/page_header.rb +11 -2
- data/lib/studio/version.rb +1 -1
- data/lib/studio.rb +70 -0
- metadata +16 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 448f5dc2b80db8f30bb9d05849d581065592b28f2189062424bfd26c25acdc63
|
|
4
|
+
data.tar.gz: 68b40d7dd6cbc3bc2f8c9e19f409755e1c7e1d1ece531e1689542f32fdeccb7c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 93377b901882007a34b2bb4ffc855ed5078cfb02e8cc35a58e9afe102df2d832d046f7531d95996a4899259a6bbfe0359d6a64ebd32370e7ca8fb274a27cd3bb
|
|
7
|
+
data.tar.gz: 4781ef35c39d5cdde579d71cf8ad93e26abb5896895480aece83c315b2e944fc48b959b09589c34e6c62354dbe2d7aa1a7746980dafd299d24023e80e74a9ae8
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,49 @@ The format is [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This pro
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.137.0 — 2026-11-08
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **Connections: generic OAuth 2.0 connection tooling.** A host declares each provider it connects with `Studio.define_connection`: static or per-account endpoints with strict account validation, scopes, form or HTTP Basic client auth, and one of three refresh policies (`:rotating`, which refreshes and stores the new refresh token under the row's lock before use; `:cached`, which keeps the access token until near expiry; `:memory`, the client-credentials grant with no stored token). The engine gives it `Studio::Connection` (one `studio_connections` table, tokens encrypted; install with `bin/rails g studio:connections`), the connect, callback and disconnect actions (`Studio::ConnectionFlow`, or the engine's `Studio::ConnectionsController`) behind `Studio.connection_admin_guard`, `Studio.draw_connection_routes`, a log filter by exact key for the keys a provider names, and `Studio::Connections::StandIn` for the e2e lane. The engine names no provider, and nothing changes until a host declares one. See `docs/CONNECTIONS.md`.
|
|
12
|
+
|
|
13
|
+
## 0.136.0 — 2026-11-08
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- **The page header styles itself in a plain-CSS app.** `config.page_header_self_styled = true` (or a callable receiving the view) makes the first `studio/_page_header` on a page render its own scoped CSS and a small script (`studio/page_header/_assets`, `studio_page_header_assets`), as the site footer does: the stuck bar under the app's own sticky masthead, the tab fades, and the Links menu's `aria-expanded`, with no Tailwind, Stimulus or import map. It reads the theme tokens (`--color-text`, `--color-surface`, `--color-border`, `--color-primary`, `--btn-primary-fg`, ...), so light and dark follow the app. Off by default, and off it renders nothing, so a Tailwind app's row is the same to the byte. See docs/PAGE_HEADER.md, "In a plain-CSS app".
|
|
18
|
+
- **`studio/_legal_page`, the shared privacy and terms frame.** `render layout: "studio/legal_page", locals: { title:, updated: }` draws the standard page header, a "Last updated" line and a readable 46rem column with its own scoped prose styles, for the apps that each hand-build the same page. See docs/PAGE_HEADER.md, "The legal page".
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- **A shared chat head morphs on a slow device too.** On a first visit to a page,
|
|
23
|
+
`studio/page_transitions` reads the new page's `data-vt-morph` names from the
|
|
24
|
+
response and lets the shared name through before the browser takes the old
|
|
25
|
+
page's picture. That read raced Turbo's own read of the same response: under
|
|
26
|
+
load Turbo could start the view transition first, and the element faded
|
|
27
|
+
instead of morphing (2 of 6 visits under an 8x CPU throttle). Turbo now reads
|
|
28
|
+
the response through the module's read, so the names are always known first.
|
|
29
|
+
`studio/reload_visits` hid the race where it loads first; the module no longer
|
|
30
|
+
depends on that. Nothing for a consumer to change.
|
|
31
|
+
- **One h1 per page: the navbar's brand gives way to the page's own h1.** The
|
|
32
|
+
navbar drew the brand as an h1 unless the layout passed `brand_heading: false`,
|
|
33
|
+
so a page with the standard header (`studio/_page_header`) carried two h1s, and
|
|
34
|
+
an app that passed `false` everywhere left pages with none (the profile, the
|
|
35
|
+
error logs). Now `studio/_page_header` records its h1, the navbar also reads
|
|
36
|
+
the page body for an `<h1>` tag (`studio_page_has_h1?`), and the brand is a div
|
|
37
|
+
with the same classes only when the page has its own. An explicit
|
|
38
|
+
`brand_heading:` still wins, and a `preview: true` navbar keeps the h1. A
|
|
39
|
+
consumer test that selects the brand as `h1.nav-title` on a page with its own
|
|
40
|
+
h1 must select `.nav-title`; an app that passes `brand_heading: false` on every
|
|
41
|
+
page, or computes it from the page body, can drop the local.
|
|
42
|
+
- **A Turbo visit into a page that reloads no longer raises "Transition was skipped".** With smooth load or the page transition on, Turbo opened its view transition before it read the response, so a visit into a page answering `turbo-visit-control: reload` (turf-monster's /wallet and /account), or one with a changed `data-turbo-track="reload"` asset, started a transition that the full load then skipped. Turbo awaits only `finished`, so `ready` rejected unhandled. The new boot module `studio/reload_visits` asks Turbo's own `PageRenderer` about each response at `turbo:before-fetch-response` and, for one Turbo will not render, takes the view-transition meta out of the HTML Turbo parses, so no transition opens and the full load plays the one motion. No promise is marked handled, so a real transition failure still surfaces. Nothing to do in a host: it arrives with the engine bump.
|
|
43
|
+
- **Cropper.js loads from the engine, not cdnjs.** `studio/_cropper_assets` loaded `cropper.min.js` (deferred) and `cropper.min.css` from cdnjs, and a cdnjs connection that never answered held the load event of every page that renders it (avatar, banner and contest editors). The engine now ships the cropperjs 1.6.2 npm package's dist files byte for byte as `studio/cropper-1.6.2.min.js` and `studio/cropper-1.6.2.min.css`, served by the host's asset pipeline under the same sha384 integrity pins. `bin/cropper-sri-live` checks them against the npm tarball and cdnjs. A host whose CSP names `https://cdnjs.cloudflare.com/ajax/libs/cropperjs/1.6.2/cropper.min.js` or `.css` may remove those entries after the bump; `'self'` covers the new files.
|
|
44
|
+
|
|
45
|
+
### Security
|
|
46
|
+
|
|
47
|
+
- **A logged-out device can no longer open a `/cable` socket, and its session check is no longer silent when it cannot run.** `Studio::UserSession.ended?(session)` is the one check a host's `ApplicationCable::Connection` makes (the hub and Cyvasse call it; guard it with `respond_to?(:ended?)` on older engines). `start!` reads a kept sid again before it reuses it, so a sign-in on a logged-out cookie mints a new sid instead of bringing the ended one back. A failed check writes an `ErrorLog` row, at most once per 5 minutes per process. The boot logs a warning (and a Sentry warning) when `studio_user_sessions` lacks `sid`/`revoked_at`, in every environment and never raising. See [`docs/DEVICE_SESSIONS.md`](docs/DEVICE_SESSIONS.md).
|
|
48
|
+
- **A logout ends that device's session on the server.** The cookie store kept the whole session in the browser, so a copy of the pre-logout cookie still signed in. A sign-in now writes a `studio_user_sessions` row with a random `sid` and puts the sid in the app's session mark; every signed-in request reads that row (one query on the `sid` index), and a logout (`clear_app_session` or `reset_session`) stamps `revoked_at`, so a replayed copy is signed out. Other devices of the same user stay signed in. Install the new migration (`AddDeviceRevocationToStudioUserSessions`; the release sweep does it). A cookie from before the change is accepted and given a sid until `Studio::UserSession.legacy_grace_until` (2026-12-08); rows idle for 90 days are pruned. No host code change. See [`docs/DEVICE_SESSIONS.md`](docs/DEVICE_SESSIONS.md).
|
|
49
|
+
|
|
7
50
|
## 0.135.2 — 2026-11-08
|
|
8
51
|
|
|
9
52
|
### Fixed
|
|
@@ -138,8 +181,6 @@ The format is [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This pro
|
|
|
138
181
|
|
|
139
182
|
## 0.132.0 — 2026-11-06
|
|
140
183
|
|
|
141
|
-
## 0.131.0 — 2026-11-05
|
|
142
|
-
|
|
143
184
|
### Added
|
|
144
185
|
|
|
145
186
|
- **A carousel opens where you tell it: `start:`, and a spotlight opens on its middle
|
|
@@ -150,6 +191,26 @@ The format is [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This pro
|
|
|
150
191
|
controller jumps there on connect, with no glide and an empty status line. The dots,
|
|
151
192
|
`data-current` and both arrows' `aria-disabled` are right from the server. A
|
|
152
193
|
`#fragment` inside the row wins over the start (task `carousel-start-and-button-glass`).
|
|
194
|
+
|
|
195
|
+
### Changed
|
|
196
|
+
|
|
197
|
+
- **A dark, full-size lit button's fill drops from 0.85 to 0.65 alpha** (`--lit-fill-alpha`),
|
|
198
|
+
Alex McRitchie's "even more transparent". White label on the primary, measured from painted
|
|
199
|
+
pixels at the label's median: a dark page 3.95 to 5.62, the lab photo 3.16 to 3.29, a mid-grey
|
|
200
|
+
backdrop (#808080) 3.25 to 3.42, a lighter one (#a0a0a0) 3.06 to 2.98. Light pages stay solid
|
|
201
|
+
(3.10).
|
|
202
|
+
- **A spotlight's arrows say "Previous slide" and "Next slide"**: they move one slide. A
|
|
203
|
+
standard row keeps "slides".
|
|
204
|
+
|
|
205
|
+
### Fixed
|
|
206
|
+
|
|
207
|
+
- **A standard carousel's `caption:` is a styled line** (small body text under each slide),
|
|
208
|
+
not bare text; the partial's docs and the README say which style shows which captions.
|
|
209
|
+
|
|
210
|
+
## 0.131.0 — 2026-11-05
|
|
211
|
+
|
|
212
|
+
### Added
|
|
213
|
+
|
|
153
214
|
- **`.studio-border-glow--clear`.** The border glow on a clear button: no fill, only the
|
|
154
215
|
moving rainbow ring and its halo, with the heading ink as the label (16:1 light, 18:1 dark,
|
|
155
216
|
measured). `<button class="btn studio-border-glow studio-border-glow--clear">`. Under
|
|
@@ -178,8 +239,7 @@ The format is [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This pro
|
|
|
178
239
|
same carousel, arrows, dots and keys, but each slide snaps to the centre. The centred
|
|
179
240
|
slide is full size and colour, with an optional `caption:` line under it (a callable on
|
|
180
241
|
the item); its neighbours are smaller (0.75), faded and grey, and the next ones peek at
|
|
181
|
-
the edges. An arrow
|
|
182
|
-
slide gets a dot. It opens on its middle slide (`start:`, below). Where the browser
|
|
242
|
+
the edges. An arrow or key moves one slide, and every slide gets a dot. Where the browser
|
|
183
243
|
has scroll-driven animations (`animation-timeline: view()`), each slide's own view
|
|
184
244
|
timeline drives the look, so it follows the finger; elsewhere the controller marks the
|
|
185
245
|
centred slide `data-current` and CSS transitions it. Reduced motion scales and greys
|
|
@@ -227,11 +287,6 @@ The format is [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This pro
|
|
|
227
287
|
|
|
228
288
|
### Changed
|
|
229
289
|
|
|
230
|
-
- **A dark, full-size lit button's fill drops from 0.85 to 0.65 alpha** (`--lit-fill-alpha`),
|
|
231
|
-
Alex McRitchie's "even more transparent". White label on the primary, measured from painted
|
|
232
|
-
pixels at the label's median: a dark page 3.95 to 5.62, the lab photo 3.16 to 3.29, a mid-grey
|
|
233
|
-
backdrop (#808080) 3.25 to 3.42, a lighter one (#a0a0a0) 3.06 to 2.98. Light pages stay solid
|
|
234
|
-
(3.10).
|
|
235
290
|
- **Back plays the app's page move the other way.** Browser Back (a Turbo restore that Turbo
|
|
236
291
|
marks `back`, or a full load that traverses to an earlier entry) and a click on a link with
|
|
237
292
|
`data-page-transition-back` (every ancestor crumb and the phone's parent link) play the
|
|
@@ -243,8 +298,6 @@ The format is [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). This pro
|
|
|
243
298
|
|
|
244
299
|
### Fixed
|
|
245
300
|
|
|
246
|
-
- **A standard carousel's `caption:` is a styled line** (small body text under each slide),
|
|
247
|
-
not bare text; the partial's docs and the README say which style shows which captions.
|
|
248
301
|
- **Review follow-ups on the sidebar, the carousel and the page header** (/tasks/engine-ui-polish-follow-ups).
|
|
249
302
|
The link sidebar's focus ring (its rows, close button, Log out, trigger and geo rows) is
|
|
250
303
|
`ring-primary-ink`, a new ring colour from the theme's primary ink: measured 5.4 to 8.9:1
|
data/README.md
CHANGED
|
@@ -33,6 +33,7 @@ resolved.
|
|
|
33
33
|
- **Authentication**: Passwordless magic-link auth, optional password auth, Google OAuth via OmniAuth (ships ready: strategy, default `User.from_omniauth` and a setup modal until the OAuth client is set; docs/GOOGLE_AUTH_SETUP.md), Solana wallet sign-in, and optional one-way SSO patterns; one standard sign-in card (Google, or, email magic link) as a page partial and a modal ([`docs/SIGN_IN_CARD.md`](docs/SIGN_IN_CARD.md))
|
|
34
34
|
- **Error handling**: `Studio::ErrorHandling` concern with `rescue_and_log`, `ErrorLog` model with `capture!`, error log viewer at `/error_logs`. `rescue_and_log` writes one row per failure: an unsaved `target:` or `parent:` is named on the row by its slug (else `unsaved User`), never linked, so the logger never saves it. If the row itself cannot be written, the original error still raises and `Rails.logger.error` records both.
|
|
35
35
|
- **Session drift**: every page carries a session stamp and loads `window.StudioSession`, which notices when another tab signs in or out, the session expires, or the server revokes it; `session:changed` / `session:mismatch` events, cross-tab sync, an identity-source plug-in interface, and `expectChange` holds for deliberate switches. The rehydrate endpoint (`GET /session/state`) is opt-in. See [`docs/SESSION_DRIFT.md`](docs/SESSION_DRIFT.md).
|
|
36
|
+
- **Device sessions**: a logout ends that device's session on the server, so a copy of the pre-logout cookie no longer signs in; other devices stay signed in. One indexed lookup per signed-in request, legacy cookies accepted until a grace date, rows pruned after 90 idle days, no host code. See [`docs/DEVICE_SESSIONS.md`](docs/DEVICE_SESSIONS.md).
|
|
36
37
|
- **Theme system**: Dynamic CSS custom properties generated from 7 role colors (primary, dark, light, success, accent, warning, danger). Dark/light mode toggle. Admin theme editor at `/admin/theme`.
|
|
37
38
|
- **UI primitives**: Shared component partials and CSS primitives such as `components/emoji_swap` for nav/sidebar emoji hover transitions.
|
|
38
39
|
- **Operator tooling**: Shared `studio/banners/environment` banner with Dev Mode + email connector controls and `studio/banners/impersonation`.
|
|
@@ -50,6 +51,7 @@ resolved.
|
|
|
50
51
|
- **Voice profile**: an opt-in row on `/profile` ("Set up your voice"): the person reads three phrases with a live level meter, their device turns each take into a speaker embedding (WeSpeaker via transformers.js), and only the averaged vector is saved on their user, never audio. `Studio::VoiceMatch.identify(embedding, among: User.all, model:)` answers who is speaking. Turn it on with `config.voice_profile = true` after installing the migration. See [`docs/VOICE_PROFILE.md`](docs/VOICE_PROFILE.md).
|
|
51
52
|
- **Voice capture**: the microphone chip (names the microphone a page records from, picks another, Chrome help dialog), one level meter, and a record button that refuses a silent take and hands a heard one to the page as a `studio:voice-recorder:take` event with the blob; it uploads nothing. Render `studio/voice/microphone_chip` and `studio/voice/recorder`. See [`docs/VOICE_CAPTURE.md`](docs/VOICE_CAPTURE.md).
|
|
52
53
|
- **Voice transcription**: `POST /voice/takes` (opt-in, `config.voice_transcription = true`) turns a signed-in user's take into `{text, speaker, score}`: a mock-first transcriber (OpenAI `gpt-4o-transcribe` in production, a mock elsewhere, a no-live-calls trap in every test environment) and `Studio::VoiceMatch` against the user's own saved voice. Nothing is kept. See [`docs/VOICE_TRANSCRIPTION.md`](docs/VOICE_TRANSCRIPTION.md).
|
|
54
|
+
- **Connections**: generic OAuth 2.0 tooling to connect a third-party account. A host declares each provider with `Studio.define_connection` (endpoints, static or per-account; scopes; form or HTTP Basic client auth; a rotating, cached or client-credentials refresh policy). The engine gives it `Studio::Connection` (one table, tokens encrypted, `bin/rails g studio:connections`), the connect, callback and disconnect actions (`Studio::ConnectionFlow`) behind the host's admin guard, `Studio.draw_connection_routes`, an exact-key log filter, and a stand-in for the e2e lane. The engine names no provider. See [`docs/CONNECTIONS.md`](docs/CONNECTIONS.md).
|
|
53
55
|
- **Surveys**: define a survey in app code (`config/surveys/*.rb`, `Studio.define_survey`) with six question types — emoji scale, 1–5 rating, single and multiple choice, short and long text — and the engine serves it at `/surveys/:slug`: one question per screen, autosave, resume, keyboard shortcuts, and a no-JavaScript fallback. `config.on_survey_completed` and `config.survey_ref_resolver` let the app fire its own goals and attribute email arrivals. An admin panel at `/admin/surveys` breaks results down per question and exports CSV. Opt in with `config.draw_survey_routes = true` and `config.draw_admin_survey_routes = true`. See [`docs/SURVEYS.md`](docs/SURVEYS.md).
|
|
54
56
|
|
|
55
57
|
## Tailwind
|
|
@@ -253,6 +255,8 @@ Set `Studio.draw_booking_routes = true` to add the booking page (`GET /schedule`
|
|
|
253
255
|
|
|
254
256
|
Set `Studio.draw_survey_routes = true` to add the public survey pages (`/surveys/:slug`, helper `studio_survey_path`) and `Studio.draw_admin_survey_routes = true` to add the admin results panel (`/admin/surveys`, helpers `admin_surveys_path` / `admin_survey_path`) — both off by default because an app may already own those paths. Both need the `studio_survey_responses` table ([`docs/SURVEYS.md`](docs/SURVEYS.md)).
|
|
255
257
|
|
|
258
|
+
For each connection provider a host declares, `Studio.draw_connection_routes(self, :files, path: "admin/files")` adds its connect (`GET`/`POST /admin/files/connect`), callback (`GET /admin/files/callback`, the redirect URI to register) and disconnect (`DELETE /admin/files/connections/:id`) routes. Nothing is drawn for a provider the host has not declared. They need the `studio_connections` table (`bin/rails g studio:connections`; [`docs/CONNECTIONS.md`](docs/CONNECTIONS.md)).
|
|
259
|
+
|
|
256
260
|
**Magic links need the `studio_links` table.** Install it with `bin/rails studio_engine:install:migrations && bin/rails db:migrate` (install all of them) before enabling `:magic_link` — never by hand-copying the migration, which collides with the task's own copy on `class CreateStudioLinks`. Without the table, the first sign-in raises `Studio::Link::MissingTable`.
|
|
257
261
|
|
|
258
262
|
Set `Studio.agent_chat_souls = %w[alex]` to add the shared agent chat's proxy (`POST /agent_chat/messages`, `GET /agent_chat/turns`), which forwards to the McRitchie Studio hub with the app's `AGENT_CHAT_TOKEN`; then `render "studio/agent_chat/chat", soul: "alex", name: "Alex", portrait: ...` on any page, with `voice: true` for hold to talk in the composer ([`docs/AGENT_CHAT.md`](docs/AGENT_CHAT.md)). To open that chat in a modal from any button, render `studio/agent_chat/talk_modal` once and mark the buttons with `studio_talk_to_agent_link` ([`docs/AGENT_CHAT.md`](docs/AGENT_CHAT.md), "Talk to an agent in a modal").
|
|
@@ -312,6 +316,12 @@ the navbar, in the pinned stack so a table's sticky header sits under it
|
|
|
312
316
|
`actions_html:` is deprecated for one release; the decision rule for which kind a link is
|
|
313
317
|
lives in [`docs/PAGE_HEADER.md`](docs/PAGE_HEADER.md#the-four-kinds-of-control).
|
|
314
318
|
|
|
319
|
+
A plain-CSS app (no engine Tailwind build) sets `config.page_header_self_styled = true`, and
|
|
320
|
+
the row brings its own scoped CSS and script, once per page, as the site footer does
|
|
321
|
+
([`docs/PAGE_HEADER.md`](docs/PAGE_HEADER.md#in-a-plain-css-app)). `studio/_legal_page` is the
|
|
322
|
+
shared privacy and terms frame: the header and a readable column
|
|
323
|
+
([`docs/PAGE_HEADER.md`](docs/PAGE_HEADER.md#the-legal-page)).
|
|
324
|
+
|
|
315
325
|
### The section header — `studio/_section_header`
|
|
316
326
|
|
|
317
327
|
A section's title that sticks under the page row until the next section's takes its place,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Cropper.js v1.6.2
|
|
3
|
+
* https://fengyuanchen.github.io/cropperjs
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2015-present Chen Fengyuan
|
|
6
|
+
* Released under the MIT license
|
|
7
|
+
*
|
|
8
|
+
* Date: 2024-04-21T07:43:05.335Z
|
|
9
|
+
*/
|
|
10
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Cropper=e()}(this,function(){"use strict";function C(e,t){var i,a=Object.keys(e);return Object.getOwnPropertySymbols&&(i=Object.getOwnPropertySymbols(e),t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),a.push.apply(a,i)),a}function S(a){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?C(Object(n),!0).forEach(function(t){var e,i;e=a,i=n[t=t],(t=D(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(n)):C(Object(n)).forEach(function(t){Object.defineProperty(a,t,Object.getOwnPropertyDescriptor(n,t))})}return a}function D(t){t=function(t,e){if("object"!=typeof t||!t)return t;var i=t[Symbol.toPrimitive];if(void 0===i)return("string"===e?String:Number)(t);if("object"!=typeof(i=i.call(t,e||"default")))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}(t,"string");return"symbol"==typeof t?t:t+""}function j(t){return(j="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function A(t,e){for(var i=0;i<e.length;i++){var a=e[i];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,D(a.key),a)}}function P(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){var i;if(t)return"string"==typeof t?a(t,e):"Map"===(i="Object"===(i=Object.prototype.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:i)||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?a(t,e):void 0}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,a=new Array(e);i<e;i++)a[i]=t[i];return a}var t="undefined"!=typeof window&&void 0!==window.document,h=t?window:{},e=!(!t||!h.document.documentElement)&&"ontouchstart"in h.document.documentElement,i=t&&"PointerEvent"in h,c="cropper",I="all",U="crop",q="move",$="zoom",B="e",k="w",O="s",T="n",E="ne",W="nw",H="se",N="sw",Q="".concat(c,"-crop"),K="".concat(c,"-disabled"),L="".concat(c,"-hidden"),Z="".concat(c,"-hide"),G="".concat(c,"-invisible"),n="".concat(c,"-modal"),V="".concat(c,"-move"),d="".concat(c,"Action"),m="".concat(c,"Preview"),F="crop",J="move",_="none",tt="crop",et="cropend",it="cropmove",at="cropstart",nt="dblclick",ot=i?"pointerdown":e?"touchstart":"mousedown",ht=i?"pointermove":e?"touchmove":"mousemove",rt=i?"pointerup pointercancel":e?"touchend touchcancel":"mouseup",st="zoom",ct="image/jpeg",dt=/^e|w|s|n|se|sw|ne|nw|all|crop|move|zoom$/,lt=/^data:/,pt=/^data:image\/jpeg;base64,/,mt=/^img|canvas$/i,ut={viewMode:0,dragMode:F,initialAspectRatio:NaN,aspectRatio:NaN,data:null,preview:"",responsive:!0,restore:!0,checkCrossOrigin:!0,checkOrientation:!0,modal:!0,guides:!0,center:!0,highlight:!0,background:!0,autoCrop:!0,autoCropArea:.8,movable:!0,rotatable:!0,scalable:!0,zoomable:!0,zoomOnTouch:!0,zoomOnWheel:!0,wheelZoomRatio:.1,cropBoxMovable:!0,cropBoxResizable:!0,toggleDragModeOnDblclick:!0,minCanvasWidth:0,minCanvasHeight:0,minCropBoxWidth:0,minCropBoxHeight:0,minContainerWidth:200,minContainerHeight:100,ready:null,cropstart:null,cropmove:null,cropend:null,crop:null,zoom:null},gt=Number.isNaN||h.isNaN;function p(t){return"number"==typeof t&&!gt(t)}function ft(t){return 0<t&&t<1/0}function vt(t){return void 0===t}function o(t){return"object"===j(t)&&null!==t}var wt=Object.prototype.hasOwnProperty;function u(t){if(!o(t))return!1;try{var e=t.constructor,i=e.prototype;return e&&i&&wt.call(i,"isPrototypeOf")}catch(t){return!1}}function l(t){return"function"==typeof t}var bt=Array.prototype.slice;function yt(t){return Array.from?Array.from(t):bt.call(t)}function z(i,a){return i&&l(a)&&(Array.isArray(i)||p(i.length)?yt(i).forEach(function(t,e){a.call(i,t,e,i)}):o(i)&&Object.keys(i).forEach(function(t){a.call(i,i[t],t,i)})),i}var g=Object.assign||function(i){for(var t=arguments.length,e=new Array(1<t?t-1:0),a=1;a<t;a++)e[a-1]=arguments[a];return o(i)&&0<e.length&&e.forEach(function(e){o(e)&&Object.keys(e).forEach(function(t){i[t]=e[t]})}),i},xt=/\.\d*(?:0|9){12}\d*$/;function Y(t,e){e=1<arguments.length&&void 0!==e?e:1e11;return xt.test(t)?Math.round(t*e)/e:t}var Mt=/^width|height|left|top|marginLeft|marginTop$/;function f(t,e){var i=t.style;z(e,function(t,e){Mt.test(e)&&p(t)&&(t="".concat(t,"px")),i[e]=t})}function v(t,e){var i;e&&(p(t.length)?z(t,function(t){v(t,e)}):t.classList?t.classList.add(e):(i=t.className.trim())?i.indexOf(e)<0&&(t.className="".concat(i," ").concat(e)):t.className=e)}function X(t,e){e&&(p(t.length)?z(t,function(t){X(t,e)}):t.classList?t.classList.remove(e):0<=t.className.indexOf(e)&&(t.className=t.className.replace(e,"")))}function r(t,e,i){e&&(p(t.length)?z(t,function(t){r(t,e,i)}):(i?v:X)(t,e))}var Ct=/([a-z\d])([A-Z])/g;function Dt(t){return t.replace(Ct,"$1-$2").toLowerCase()}function Bt(t,e){return o(t[e])?t[e]:t.dataset?t.dataset[e]:t.getAttribute("data-".concat(Dt(e)))}function w(t,e,i){o(i)?t[e]=i:t.dataset?t.dataset[e]=i:t.setAttribute("data-".concat(Dt(e)),i)}var kt,Ot,Tt=/\s\s*/,Et=(Ot=!1,t&&(kt=!1,i=function(){},e=Object.defineProperty({},"once",{get:function(){return Ot=!0,kt},set:function(t){kt=t}}),h.addEventListener("test",i,e),h.removeEventListener("test",i,e)),Ot);function s(i,t,a,e){var n=3<arguments.length&&void 0!==e?e:{},o=a;t.trim().split(Tt).forEach(function(t){var e;Et||(e=i.listeners)&&e[t]&&e[t][a]&&(o=e[t][a],delete e[t][a],0===Object.keys(e[t]).length&&delete e[t],0===Object.keys(e).length)&&delete i.listeners,i.removeEventListener(t,o,n)})}function b(o,t,h,e){var r=3<arguments.length&&void 0!==e?e:{},s=h;t.trim().split(Tt).forEach(function(a){var t,n;r.once&&!Et&&(t=o.listeners,s=function(){delete n[a][h],o.removeEventListener(a,s,r);for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];h.apply(o,e)},(n=void 0===t?{}:t)[a]||(n[a]={}),n[a][h]&&o.removeEventListener(a,n[a][h],r),n[a][h]=s,o.listeners=n),o.addEventListener(a,s,r)})}function y(t,e,i){var a;return l(Event)&&l(CustomEvent)?a=new CustomEvent(e,{detail:i,bubbles:!0,cancelable:!0}):(a=document.createEvent("CustomEvent")).initCustomEvent(e,!0,!0,i),t.dispatchEvent(a)}function Wt(t){t=t.getBoundingClientRect();return{left:t.left+(window.pageXOffset-document.documentElement.clientLeft),top:t.top+(window.pageYOffset-document.documentElement.clientTop)}}var Ht=h.location,Nt=/^(\w+:)\/\/([^:/?#]*):?(\d*)/i;function Lt(t){t=t.match(Nt);return null!==t&&(t[1]!==Ht.protocol||t[2]!==Ht.hostname||t[3]!==Ht.port)}function zt(t){var e="timestamp=".concat((new Date).getTime());return t+(-1===t.indexOf("?")?"?":"&")+e}function x(t){var e=t.rotate,i=t.scaleX,a=t.scaleY,n=t.translateX,t=t.translateY,o=[],n=(p(n)&&0!==n&&o.push("translateX(".concat(n,"px)")),p(t)&&0!==t&&o.push("translateY(".concat(t,"px)")),p(e)&&0!==e&&o.push("rotate(".concat(e,"deg)")),p(i)&&1!==i&&o.push("scaleX(".concat(i,")")),p(a)&&1!==a&&o.push("scaleY(".concat(a,")")),o.length?o.join(" "):"none");return{WebkitTransform:n,msTransform:n,transform:n}}function M(t,e){var i=t.pageX,t=t.pageY,a={endX:i,endY:t};return e?a:S({startX:i,startY:t},a)}function R(t,e){var i,a=t.aspectRatio,n=t.height,t=t.width,e=1<arguments.length&&void 0!==e?e:"contain",o=ft(t),h=ft(n);return o&&h?(i=n*a,"contain"===e&&t<i||"cover"===e&&i<t?n=t/a:t=n*a):o?n=t/a:h&&(t=n*a),{width:t,height:n}}var Yt=String.fromCharCode;var Xt=/^data:.*,/;function Rt(t){var e,i,a,n,o,h,r,s=new DataView(t);try{if(255===s.getUint8(0)&&216===s.getUint8(1))for(var c=s.byteLength,d=2;d+1<c;){if(255===s.getUint8(d)&&225===s.getUint8(d+1)){i=d;break}d+=1}if(a=i&&(n=i+10,"Exif"===function(t,e,i){var a="";i+=e;for(var n=e;n<i;n+=1)a+=Yt(t.getUint8(n));return a}(s,i+4,4))&&((r=18761===(o=s.getUint16(n)))||19789===o)&&42===s.getUint16(n+2,r)&&8<=(h=s.getUint32(n+4,r))?n+h:a)for(var l,p=s.getUint16(a,r),m=0;m<p;m+=1)if(l=a+12*m+2,274===s.getUint16(l,r)){l+=8,e=s.getUint16(l,r),s.setUint16(l,1,r);break}}catch(t){e=1}return e}var t={render:function(){this.initContainer(),this.initCanvas(),this.initCropBox(),this.renderCanvas(),this.cropped&&this.renderCropBox()},initContainer:function(){var t=this.element,e=this.options,i=this.container,a=this.cropper,n=Number(e.minContainerWidth),e=Number(e.minContainerHeight),n=(v(a,L),X(t,L),{width:Math.max(i.offsetWidth,0<=n?n:200),height:Math.max(i.offsetHeight,0<=e?e:100)});f(a,{width:(this.containerData=n).width,height:n.height}),v(t,L),X(a,L)},initCanvas:function(){var t=this.containerData,e=this.imageData,i=this.options.viewMode,a=Math.abs(e.rotate)%180==90,n=a?e.naturalHeight:e.naturalWidth,a=a?e.naturalWidth:e.naturalHeight,e=n/a,o=t.width,h=t.height,e=(t.height*e>t.width?3===i?o=t.height*e:h=t.width/e:3===i?h=t.width/e:o=t.height*e,{aspectRatio:e,naturalWidth:n,naturalHeight:a,width:o,height:h});this.canvasData=e,this.limited=1===i||2===i,this.limitCanvas(!0,!0),e.width=Math.min(Math.max(e.width,e.minWidth),e.maxWidth),e.height=Math.min(Math.max(e.height,e.minHeight),e.maxHeight),e.left=(t.width-e.width)/2,e.top=(t.height-e.height)/2,e.oldLeft=e.left,e.oldTop=e.top,this.initialCanvasData=g({},e)},limitCanvas:function(t,e){var i=this.options,a=this.containerData,n=this.canvasData,o=this.cropBoxData,h=i.viewMode,r=n.aspectRatio,s=this.cropped&&o;t&&(t=Number(i.minCanvasWidth)||0,i=Number(i.minCanvasHeight)||0,1<h?(t=Math.max(t,a.width),i=Math.max(i,a.height),3===h&&(t<i*r?t=i*r:i=t/r)):0<h&&(t?t=Math.max(t,s?o.width:0):i?i=Math.max(i,s?o.height:0):s&&((t=o.width)<(i=o.height)*r?t=i*r:i=t/r)),t=(r=R({aspectRatio:r,width:t,height:i})).width,i=r.height,n.minWidth=t,n.minHeight=i,n.maxWidth=1/0,n.maxHeight=1/0),e&&((s?0:1)<h?(r=a.width-n.width,t=a.height-n.height,n.minLeft=Math.min(0,r),n.minTop=Math.min(0,t),n.maxLeft=Math.max(0,r),n.maxTop=Math.max(0,t),s&&this.limited&&(n.minLeft=Math.min(o.left,o.left+(o.width-n.width)),n.minTop=Math.min(o.top,o.top+(o.height-n.height)),n.maxLeft=o.left,n.maxTop=o.top,2===h)&&(n.width>=a.width&&(n.minLeft=Math.min(0,r),n.maxLeft=Math.max(0,r)),n.height>=a.height)&&(n.minTop=Math.min(0,t),n.maxTop=Math.max(0,t))):(n.minLeft=-n.width,n.minTop=-n.height,n.maxLeft=a.width,n.maxTop=a.height))},renderCanvas:function(t,e){var i,a,n,o,h=this.canvasData,r=this.imageData;e&&(e={width:r.naturalWidth*Math.abs(r.scaleX||1),height:r.naturalHeight*Math.abs(r.scaleY||1),degree:r.rotate||0},r=e.width,o=e.height,e=e.degree,i=90==(e=Math.abs(e)%180)?{width:o,height:r}:(a=e%90*Math.PI/180,i=Math.sin(a),n=r*(a=Math.cos(a))+o*i,r=r*i+o*a,90<e?{width:r,height:n}:{width:n,height:r}),a=h.width*((o=i.width)/h.naturalWidth),n=h.height*((e=i.height)/h.naturalHeight),h.left-=(a-h.width)/2,h.top-=(n-h.height)/2,h.width=a,h.height=n,h.aspectRatio=o/e,h.naturalWidth=o,h.naturalHeight=e,this.limitCanvas(!0,!1)),(h.width>h.maxWidth||h.width<h.minWidth)&&(h.left=h.oldLeft),(h.height>h.maxHeight||h.height<h.minHeight)&&(h.top=h.oldTop),h.width=Math.min(Math.max(h.width,h.minWidth),h.maxWidth),h.height=Math.min(Math.max(h.height,h.minHeight),h.maxHeight),this.limitCanvas(!1,!0),h.left=Math.min(Math.max(h.left,h.minLeft),h.maxLeft),h.top=Math.min(Math.max(h.top,h.minTop),h.maxTop),h.oldLeft=h.left,h.oldTop=h.top,f(this.canvas,g({width:h.width,height:h.height},x({translateX:h.left,translateY:h.top}))),this.renderImage(t),this.cropped&&this.limited&&this.limitCropBox(!0,!0)},renderImage:function(t){var e=this.canvasData,i=this.imageData,a=i.naturalWidth*(e.width/e.naturalWidth),n=i.naturalHeight*(e.height/e.naturalHeight);g(i,{width:a,height:n,left:(e.width-a)/2,top:(e.height-n)/2}),f(this.image,g({width:i.width,height:i.height},x(g({translateX:i.left,translateY:i.top},i)))),t&&this.output()},initCropBox:function(){var t=this.options,e=this.canvasData,i=t.aspectRatio||t.initialAspectRatio,t=Number(t.autoCropArea)||.8,a={width:e.width,height:e.height};i&&(e.height*i>e.width?a.height=a.width/i:a.width=a.height*i),this.cropBoxData=a,this.limitCropBox(!0,!0),a.width=Math.min(Math.max(a.width,a.minWidth),a.maxWidth),a.height=Math.min(Math.max(a.height,a.minHeight),a.maxHeight),a.width=Math.max(a.minWidth,a.width*t),a.height=Math.max(a.minHeight,a.height*t),a.left=e.left+(e.width-a.width)/2,a.top=e.top+(e.height-a.height)/2,a.oldLeft=a.left,a.oldTop=a.top,this.initialCropBoxData=g({},a)},limitCropBox:function(t,e){var i,a,n=this.options,o=this.containerData,h=this.canvasData,r=this.cropBoxData,s=this.limited,c=n.aspectRatio;t&&(t=Number(n.minCropBoxWidth)||0,n=Number(n.minCropBoxHeight)||0,i=s?Math.min(o.width,h.width,h.width+h.left,o.width-h.left):o.width,a=s?Math.min(o.height,h.height,h.height+h.top,o.height-h.top):o.height,t=Math.min(t,o.width),n=Math.min(n,o.height),c&&(t&&n?t<n*c?n=t/c:t=n*c:t?n=t/c:n&&(t=n*c),i<a*c?a=i/c:i=a*c),r.minWidth=Math.min(t,i),r.minHeight=Math.min(n,a),r.maxWidth=i,r.maxHeight=a),e&&(s?(r.minLeft=Math.max(0,h.left),r.minTop=Math.max(0,h.top),r.maxLeft=Math.min(o.width,h.left+h.width)-r.width,r.maxTop=Math.min(o.height,h.top+h.height)-r.height):(r.minLeft=0,r.minTop=0,r.maxLeft=o.width-r.width,r.maxTop=o.height-r.height))},renderCropBox:function(){var t=this.options,e=this.containerData,i=this.cropBoxData;(i.width>i.maxWidth||i.width<i.minWidth)&&(i.left=i.oldLeft),(i.height>i.maxHeight||i.height<i.minHeight)&&(i.top=i.oldTop),i.width=Math.min(Math.max(i.width,i.minWidth),i.maxWidth),i.height=Math.min(Math.max(i.height,i.minHeight),i.maxHeight),this.limitCropBox(!1,!0),i.left=Math.min(Math.max(i.left,i.minLeft),i.maxLeft),i.top=Math.min(Math.max(i.top,i.minTop),i.maxTop),i.oldLeft=i.left,i.oldTop=i.top,t.movable&&t.cropBoxMovable&&w(this.face,d,i.width>=e.width&&i.height>=e.height?q:I),f(this.cropBox,g({width:i.width,height:i.height},x({translateX:i.left,translateY:i.top}))),this.cropped&&this.limited&&this.limitCanvas(!0,!0),this.disabled||this.output()},output:function(){this.preview(),y(this.element,tt,this.getData())}},i={initPreview:function(){var t=this.element,i=this.crossOrigin,e=this.options.preview,a=i?this.crossOriginUrl:this.url,n=t.alt||"The image to preview",o=document.createElement("img");i&&(o.crossOrigin=i),o.src=a,o.alt=n,this.viewBox.appendChild(o),this.viewBoxImage=o,e&&("string"==typeof(o=e)?o=t.ownerDocument.querySelectorAll(e):e.querySelector&&(o=[e]),z(this.previews=o,function(t){var e=document.createElement("img");w(t,m,{width:t.offsetWidth,height:t.offsetHeight,html:t.innerHTML}),i&&(e.crossOrigin=i),e.src=a,e.alt=n,e.style.cssText='display:block;width:100%;height:auto;min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;image-orientation:0deg!important;"',t.innerHTML="",t.appendChild(e)}))},resetPreview:function(){z(this.previews,function(e){var i=Bt(e,m),i=(f(e,{width:i.width,height:i.height}),e.innerHTML=i.html,e),e=m;if(o(i[e]))try{delete i[e]}catch(t){i[e]=void 0}else if(i.dataset)try{delete i.dataset[e]}catch(t){i.dataset[e]=void 0}else i.removeAttribute("data-".concat(Dt(e)))})},preview:function(){var h=this.imageData,t=this.canvasData,e=this.cropBoxData,r=e.width,s=e.height,c=h.width,d=h.height,l=e.left-t.left-h.left,p=e.top-t.top-h.top;this.cropped&&!this.disabled&&(f(this.viewBoxImage,g({width:c,height:d},x(g({translateX:-l,translateY:-p},h)))),z(this.previews,function(t){var e=Bt(t,m),i=e.width,e=e.height,a=i,n=e,o=1;r&&(n=s*(o=i/r)),s&&e<n&&(a=r*(o=e/s),n=e),f(t,{width:a,height:n}),f(t.getElementsByTagName("img")[0],g({width:c*o,height:d*o},x(g({translateX:-l*o,translateY:-p*o},h))))}))}},e={bind:function(){var t=this.element,e=this.options,i=this.cropper;l(e.cropstart)&&b(t,at,e.cropstart),l(e.cropmove)&&b(t,it,e.cropmove),l(e.cropend)&&b(t,et,e.cropend),l(e.crop)&&b(t,tt,e.crop),l(e.zoom)&&b(t,st,e.zoom),b(i,ot,this.onCropStart=this.cropStart.bind(this)),e.zoomable&&e.zoomOnWheel&&b(i,"wheel",this.onWheel=this.wheel.bind(this),{passive:!1,capture:!0}),e.toggleDragModeOnDblclick&&b(i,nt,this.onDblclick=this.dblclick.bind(this)),b(t.ownerDocument,ht,this.onCropMove=this.cropMove.bind(this)),b(t.ownerDocument,rt,this.onCropEnd=this.cropEnd.bind(this)),e.responsive&&b(window,"resize",this.onResize=this.resize.bind(this))},unbind:function(){var t=this.element,e=this.options,i=this.cropper;l(e.cropstart)&&s(t,at,e.cropstart),l(e.cropmove)&&s(t,it,e.cropmove),l(e.cropend)&&s(t,et,e.cropend),l(e.crop)&&s(t,tt,e.crop),l(e.zoom)&&s(t,st,e.zoom),s(i,ot,this.onCropStart),e.zoomable&&e.zoomOnWheel&&s(i,"wheel",this.onWheel,{passive:!1,capture:!0}),e.toggleDragModeOnDblclick&&s(i,nt,this.onDblclick),s(t.ownerDocument,ht,this.onCropMove),s(t.ownerDocument,rt,this.onCropEnd),e.responsive&&s(window,"resize",this.onResize)}},St={resize:function(){var t,e,i,a,n,o,h;this.disabled||(t=this.options,a=this.container,e=this.containerData,i=a.offsetWidth/e.width,a=a.offsetHeight/e.height,1!=(n=Math.abs(i-1)>Math.abs(a-1)?i:a)&&(t.restore&&(o=this.getCanvasData(),h=this.getCropBoxData()),this.render(),t.restore)&&(this.setCanvasData(z(o,function(t,e){o[e]=t*n})),this.setCropBoxData(z(h,function(t,e){h[e]=t*n}))))},dblclick:function(){var t,e;this.disabled||this.options.dragMode===_||this.setDragMode((t=this.dragBox,e=Q,(t.classList?t.classList.contains(e):-1<t.className.indexOf(e))?J:F))},wheel:function(t){var e=this,i=Number(this.options.wheelZoomRatio)||.1,a=1;this.disabled||(t.preventDefault(),this.wheeling)||(this.wheeling=!0,setTimeout(function(){e.wheeling=!1},50),t.deltaY?a=0<t.deltaY?1:-1:t.wheelDelta?a=-t.wheelDelta/120:t.detail&&(a=0<t.detail?1:-1),this.zoom(-a*i,t))},cropStart:function(t){var e,i=t.buttons,a=t.button;this.disabled||("mousedown"===t.type||"pointerdown"===t.type&&"mouse"===t.pointerType)&&(p(i)&&1!==i||p(a)&&0!==a||t.ctrlKey)||(i=this.options,e=this.pointers,t.changedTouches?z(t.changedTouches,function(t){e[t.identifier]=M(t)}):e[t.pointerId||0]=M(t),a=1<Object.keys(e).length&&i.zoomable&&i.zoomOnTouch?$:Bt(t.target,d),dt.test(a)&&!1!==y(this.element,at,{originalEvent:t,action:a})&&(t.preventDefault(),this.action=a,this.cropping=!1,a===U)&&(this.cropping=!0,v(this.dragBox,n)))},cropMove:function(t){var e,i=this.action;!this.disabled&&i&&(e=this.pointers,t.preventDefault(),!1!==y(this.element,it,{originalEvent:t,action:i}))&&(t.changedTouches?z(t.changedTouches,function(t){g(e[t.identifier]||{},M(t,!0))}):g(e[t.pointerId||0]||{},M(t,!0)),this.change(t))},cropEnd:function(t){var e,i;this.disabled||(e=this.action,i=this.pointers,t.changedTouches?z(t.changedTouches,function(t){delete i[t.identifier]}):delete i[t.pointerId||0],e&&(t.preventDefault(),Object.keys(i).length||(this.action=""),this.cropping&&(this.cropping=!1,r(this.dragBox,n,this.cropped&&this.options.modal)),y(this.element,et,{originalEvent:t,action:e})))}},jt={change:function(t){function e(t){switch(t){case B:f+D.x>y&&(D.x=y-f);break;case k:p+D.x<w&&(D.x=w-p);break;case T:m+D.y<b&&(D.y=b-m);break;case O:v+D.y>x&&(D.y=x-v)}}var i,a,o,n=this.options,h=this.canvasData,r=this.containerData,s=this.cropBoxData,c=this.pointers,d=this.action,l=n.aspectRatio,p=s.left,m=s.top,u=s.width,g=s.height,f=p+u,v=m+g,w=0,b=0,y=r.width,x=r.height,M=!0,C=(!l&&t.shiftKey&&(l=u&&g?u/g:1),this.limited&&(w=s.minLeft,b=s.minTop,y=w+Math.min(r.width,h.width,h.left+h.width),x=b+Math.min(r.height,h.height,h.top+h.height)),c[Object.keys(c)[0]]),D={x:C.endX-C.startX,y:C.endY-C.startY};switch(d){case I:p+=D.x,m+=D.y;break;case B:0<=D.x&&(y<=f||l&&(m<=b||x<=v))?M=!1:(e(B),(u+=D.x)<0&&(d=k,p-=u=-u),l&&(m+=(s.height-(g=u/l))/2));break;case T:D.y<=0&&(m<=b||l&&(p<=w||y<=f))?M=!1:(e(T),g-=D.y,m+=D.y,g<0&&(d=O,m-=g=-g),l&&(p+=(s.width-(u=g*l))/2));break;case k:D.x<=0&&(p<=w||l&&(m<=b||x<=v))?M=!1:(e(k),u-=D.x,p+=D.x,u<0&&(d=B,p-=u=-u),l&&(m+=(s.height-(g=u/l))/2));break;case O:0<=D.y&&(x<=v||l&&(p<=w||y<=f))?M=!1:(e(O),(g+=D.y)<0&&(d=T,m-=g=-g),l&&(p+=(s.width-(u=g*l))/2));break;case E:if(l){if(D.y<=0&&(m<=b||y<=f)){M=!1;break}e(T),g-=D.y,m+=D.y,u=g*l}else e(T),e(B),!(0<=D.x)||f<y?u+=D.x:D.y<=0&&m<=b&&(M=!1),(!(D.y<=0)||b<m)&&(g-=D.y,m+=D.y);u<0&&g<0?(d=N,m-=g=-g,p-=u=-u):u<0?(d=W,p-=u=-u):g<0&&(d=H,m-=g=-g);break;case W:if(l){if(D.y<=0&&(m<=b||p<=w)){M=!1;break}e(T),g-=D.y,m+=D.y,p+=s.width-(u=g*l)}else e(T),e(k),!(D.x<=0)||w<p?(u-=D.x,p+=D.x):D.y<=0&&m<=b&&(M=!1),(!(D.y<=0)||b<m)&&(g-=D.y,m+=D.y);u<0&&g<0?(d=H,m-=g=-g,p-=u=-u):u<0?(d=E,p-=u=-u):g<0&&(d=N,m-=g=-g);break;case N:if(l){if(D.x<=0&&(p<=w||x<=v)){M=!1;break}e(k),u-=D.x,p+=D.x,g=u/l}else e(O),e(k),!(D.x<=0)||w<p?(u-=D.x,p+=D.x):0<=D.y&&x<=v&&(M=!1),(!(0<=D.y)||v<x)&&(g+=D.y);u<0&&g<0?(d=E,m-=g=-g,p-=u=-u):u<0?(d=H,p-=u=-u):g<0&&(d=W,m-=g=-g);break;case H:if(l){if(0<=D.x&&(y<=f||x<=v)){M=!1;break}e(B),g=(u+=D.x)/l}else e(O),e(B),!(0<=D.x)||f<y?u+=D.x:0<=D.y&&x<=v&&(M=!1),(!(0<=D.y)||v<x)&&(g+=D.y);u<0&&g<0?(d=W,m-=g=-g,p-=u=-u):u<0?(d=N,p-=u=-u):g<0&&(d=E,m-=g=-g);break;case q:this.move(D.x,D.y),M=!1;break;case $:this.zoom((a=S({},i=c),o=0,z(i,function(n,t){delete a[t],z(a,function(t){var e=Math.abs(n.startX-t.startX),i=Math.abs(n.startY-t.startY),a=Math.abs(n.endX-t.endX),t=Math.abs(n.endY-t.endY),e=Math.sqrt(e*e+i*i),i=(Math.sqrt(a*a+t*t)-e)/e;Math.abs(i)>Math.abs(o)&&(o=i)})}),o),t),M=!1;break;case U:D.x&&D.y?(i=Wt(this.cropper),p=C.startX-i.left,m=C.startY-i.top,u=s.minWidth,g=s.minHeight,0<D.x?d=0<D.y?H:E:D.x<0&&(p-=u,d=0<D.y?N:W),D.y<0&&(m-=g),this.cropped||(X(this.cropBox,L),this.cropped=!0,this.limited&&this.limitCropBox(!0,!0))):M=!1}M&&(s.width=u,s.height=g,s.left=p,s.top=m,this.action=d,this.renderCropBox()),z(c,function(t){t.startX=t.endX,t.startY=t.endY})}},At={crop:function(){return!this.ready||this.cropped||this.disabled||(this.cropped=!0,this.limitCropBox(!0,!0),this.options.modal&&v(this.dragBox,n),X(this.cropBox,L),this.setCropBoxData(this.initialCropBoxData)),this},reset:function(){return this.ready&&!this.disabled&&(this.imageData=g({},this.initialImageData),this.canvasData=g({},this.initialCanvasData),this.cropBoxData=g({},this.initialCropBoxData),this.renderCanvas(),this.cropped)&&this.renderCropBox(),this},clear:function(){return this.cropped&&!this.disabled&&(g(this.cropBoxData,{left:0,top:0,width:0,height:0}),this.cropped=!1,this.renderCropBox(),this.limitCanvas(!0,!0),this.renderCanvas(),X(this.dragBox,n),v(this.cropBox,L)),this},replace:function(e){var t=1<arguments.length&&void 0!==arguments[1]&&arguments[1];return!this.disabled&&e&&(this.isImg&&(this.element.src=e),t?(this.url=e,this.image.src=e,this.ready&&(this.viewBoxImage.src=e,z(this.previews,function(t){t.getElementsByTagName("img")[0].src=e}))):(this.isImg&&(this.replaced=!0),this.options.data=null,this.uncreate(),this.load(e))),this},enable:function(){return this.ready&&this.disabled&&(this.disabled=!1,X(this.cropper,K)),this},disable:function(){return this.ready&&!this.disabled&&(this.disabled=!0,v(this.cropper,K)),this},destroy:function(){var t=this.element;return t[c]&&(t[c]=void 0,this.isImg&&this.replaced&&(t.src=this.originalUrl),this.uncreate()),this},move:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:t,i=this.canvasData,a=i.left,i=i.top;return this.moveTo(vt(t)?t:a+Number(t),vt(e)?e:i+Number(e))},moveTo:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:t,i=this.canvasData,a=!1;return t=Number(t),e=Number(e),this.ready&&!this.disabled&&this.options.movable&&(p(t)&&(i.left=t,a=!0),p(e)&&(i.top=e,a=!0),a)&&this.renderCanvas(!0),this},zoom:function(t,e){var i=this.canvasData;return t=Number(t),this.zoomTo(i.width*(t=t<0?1/(1-t):1+t)/i.naturalWidth,null,e)},zoomTo:function(t,e,i){var a,n,o,h=this.options,r=this.canvasData,s=r.width,c=r.height,d=r.naturalWidth,l=r.naturalHeight;if(0<=(t=Number(t))&&this.ready&&!this.disabled&&h.zoomable){h=d*t,l=l*t;if(!1===y(this.element,st,{ratio:t,oldRatio:s/d,originalEvent:i}))return this;i?(t=this.pointers,d=Wt(this.cropper),t=t&&Object.keys(t).length?(o=n=a=0,z(t,function(t){var e=t.startX,t=t.startY;a+=e,n+=t,o+=1}),{pageX:a/=o,pageY:n/=o}):{pageX:i.pageX,pageY:i.pageY},r.left-=(h-s)*((t.pageX-d.left-r.left)/s),r.top-=(l-c)*((t.pageY-d.top-r.top)/c)):u(e)&&p(e.x)&&p(e.y)?(r.left-=(h-s)*((e.x-r.left)/s),r.top-=(l-c)*((e.y-r.top)/c)):(r.left-=(h-s)/2,r.top-=(l-c)/2),r.width=h,r.height=l,this.renderCanvas(!0)}return this},rotate:function(t){return this.rotateTo((this.imageData.rotate||0)+Number(t))},rotateTo:function(t){return p(t=Number(t))&&this.ready&&!this.disabled&&this.options.rotatable&&(this.imageData.rotate=t%360,this.renderCanvas(!0,!0)),this},scaleX:function(t){var e=this.imageData.scaleY;return this.scale(t,p(e)?e:1)},scaleY:function(t){var e=this.imageData.scaleX;return this.scale(p(e)?e:1,t)},scale:function(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:t,i=this.imageData,a=!1;return t=Number(t),e=Number(e),this.ready&&!this.disabled&&this.options.scalable&&(p(t)&&(i.scaleX=t,a=!0),p(e)&&(i.scaleY=e,a=!0),a)&&this.renderCanvas(!0,!0),this},getData:function(){var i,a,t=0<arguments.length&&void 0!==arguments[0]&&arguments[0],e=this.options,n=this.imageData,o=this.canvasData,h=this.cropBoxData;return this.ready&&this.cropped?(i={x:h.left-o.left,y:h.top-o.top,width:h.width,height:h.height},a=n.width/n.naturalWidth,z(i,function(t,e){i[e]=t/a}),t&&(o=Math.round(i.y+i.height),h=Math.round(i.x+i.width),i.x=Math.round(i.x),i.y=Math.round(i.y),i.width=h-i.x,i.height=o-i.y)):i={x:0,y:0,width:0,height:0},e.rotatable&&(i.rotate=n.rotate||0),e.scalable&&(i.scaleX=n.scaleX||1,i.scaleY=n.scaleY||1),i},setData:function(t){var e,i=this.options,a=this.imageData,n=this.canvasData,o={};return this.ready&&!this.disabled&&u(t)&&(e=!1,i.rotatable&&p(t.rotate)&&t.rotate!==a.rotate&&(a.rotate=t.rotate,e=!0),i.scalable&&(p(t.scaleX)&&t.scaleX!==a.scaleX&&(a.scaleX=t.scaleX,e=!0),p(t.scaleY))&&t.scaleY!==a.scaleY&&(a.scaleY=t.scaleY,e=!0),e&&this.renderCanvas(!0,!0),i=a.width/a.naturalWidth,p(t.x)&&(o.left=t.x*i+n.left),p(t.y)&&(o.top=t.y*i+n.top),p(t.width)&&(o.width=t.width*i),p(t.height)&&(o.height=t.height*i),this.setCropBoxData(o)),this},getContainerData:function(){return this.ready?g({},this.containerData):{}},getImageData:function(){return this.sized?g({},this.imageData):{}},getCanvasData:function(){var e=this.canvasData,i={};return this.ready&&z(["left","top","width","height","naturalWidth","naturalHeight"],function(t){i[t]=e[t]}),i},setCanvasData:function(t){var e=this.canvasData,i=e.aspectRatio;return this.ready&&!this.disabled&&u(t)&&(p(t.left)&&(e.left=t.left),p(t.top)&&(e.top=t.top),p(t.width)?(e.width=t.width,e.height=t.width/i):p(t.height)&&(e.height=t.height,e.width=t.height*i),this.renderCanvas(!0)),this},getCropBoxData:function(){var t,e=this.cropBoxData;return(t=this.ready&&this.cropped?{left:e.left,top:e.top,width:e.width,height:e.height}:t)||{}},setCropBoxData:function(t){var e,i,a=this.cropBoxData,n=this.options.aspectRatio;return this.ready&&this.cropped&&!this.disabled&&u(t)&&(p(t.left)&&(a.left=t.left),p(t.top)&&(a.top=t.top),p(t.width)&&t.width!==a.width&&(e=!0,a.width=t.width),p(t.height)&&t.height!==a.height&&(i=!0,a.height=t.height),n&&(e?a.height=a.width/n:i&&(a.width=a.height*n)),this.renderCropBox()),this},getCroppedCanvas:function(){var t,e,i,a,n,o,h,r,s,c,d,l,p,m,u,g,f,v,w,b,y,x,M,C,D,B,k,O=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return this.ready&&window.HTMLCanvasElement?(B=this.canvasData,u=this.image,l=this.imageData,a=B,v=O,g=l.aspectRatio,e=l.naturalWidth,n=l.naturalHeight,c=void 0===(c=l.rotate)?0:c,d=void 0===(d=l.scaleX)?1:d,l=void 0===(l=l.scaleY)?1:l,i=a.aspectRatio,r=a.naturalWidth,a=a.naturalHeight,h=void 0===(h=v.fillColor)?"transparent":h,p=void 0===(p=v.imageSmoothingEnabled)||p,m=void 0===(m=v.imageSmoothingQuality)?"low":m,o=void 0===(o=v.maxWidth)?1/0:o,k=void 0===(k=v.maxHeight)?1/0:k,t=void 0===(t=v.minWidth)?0:t,v=void 0===(v=v.minHeight)?0:v,w=document.createElement("canvas"),f=w.getContext("2d"),s=R({aspectRatio:i,width:o,height:k}),i=R({aspectRatio:i,width:t,height:v},"cover"),r=Math.min(s.width,Math.max(i.width,r)),s=Math.min(s.height,Math.max(i.height,a)),i=R({aspectRatio:g,width:o,height:k}),a=R({aspectRatio:g,width:t,height:v},"cover"),o=Math.min(i.width,Math.max(a.width,e)),k=Math.min(i.height,Math.max(a.height,n)),g=[-o/2,-k/2,o,k],w.width=Y(r),w.height=Y(s),f.fillStyle=h,f.fillRect(0,0,r,s),f.save(),f.translate(r/2,s/2),f.rotate(c*Math.PI/180),f.scale(d,l),f.imageSmoothingEnabled=p,f.imageSmoothingQuality=m,f.drawImage.apply(f,[u].concat(P(g.map(function(t){return Math.floor(Y(t))})))),f.restore(),t=w,this.cropped?(e=(v=this.getData(O.rounded)).x,i=v.y,a=v.width,n=v.height,1!=(o=t.width/Math.floor(B.naturalWidth))&&(e*=o,i*=o,a*=o,n*=o),h=R({aspectRatio:k=a/n,width:O.maxWidth||1/0,height:O.maxHeight||1/0}),r=R({aspectRatio:k,width:O.minWidth||0,height:O.minHeight||0},"cover"),c=(s=R({aspectRatio:k,width:O.width||(1!=o?t.width:a),height:O.height||(1!=o?t.height:n)})).width,d=s.height,c=Math.min(h.width,Math.max(r.width,c)),d=Math.min(h.height,Math.max(r.height,d)),p=(l=document.createElement("canvas")).getContext("2d"),l.width=Y(c),l.height=Y(d),p.fillStyle=O.fillColor||"transparent",p.fillRect(0,0,c,d),m=O.imageSmoothingEnabled,u=O.imageSmoothingQuality,p.imageSmoothingEnabled=void 0===m||m,u&&(p.imageSmoothingQuality=u),g=t.width,f=t.height,w=i,(v=e)<=-a||g<v?C=x=b=v=0:v<=0?(x=-v,v=0,C=b=Math.min(g,a+v)):v<=g&&(x=0,C=b=Math.min(a,g-v)),b<=0||w<=-n||f<w?D=M=y=w=0:w<=0?(M=-w,w=0,D=y=Math.min(f,n+w)):w<=f&&(M=0,D=y=Math.min(n,f-w)),B=[v,w,b,y],0<C&&0<D&&B.push(x*(k=c/a),M*k,C*k,D*k),p.drawImage.apply(p,[t].concat(P(B.map(function(t){return Math.floor(Y(t))})))),l):t):null},setAspectRatio:function(t){var e=this.options;return this.disabled||vt(t)||(e.aspectRatio=Math.max(0,t)||NaN,this.ready&&(this.initCropBox(),this.cropped)&&this.renderCropBox()),this},setDragMode:function(t){var e,i,a=this.options,n=this.dragBox,o=this.face;return this.ready&&!this.disabled&&(i=a.movable&&t===J,a.dragMode=t=(e=t===F)||i?t:_,w(n,d,t),r(n,Q,e),r(n,V,i),a.cropBoxMovable||(w(o,d,t),r(o,Q,e),r(o,V,i))),this}},Pt=h.Cropper,It=function(){function n(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=this,a=n;if(!(i instanceof a))throw new TypeError("Cannot call a class as a function");if(!t||!mt.test(t.tagName))throw new Error("The first argument is required and must be an <img> or <canvas> element.");this.element=t,this.options=g({},ut,u(e)&&e),this.cropped=!1,this.disabled=!1,this.pointers={},this.ready=!1,this.reloading=!1,this.replaced=!1,this.sized=!1,this.sizing=!1,this.init()}return t=n,i=[{key:"noConflict",value:function(){return window.Cropper=Pt,n}},{key:"setDefaults",value:function(t){g(ut,u(t)&&t)}}],(e=[{key:"init",value:function(){var t,e=this.element,i=e.tagName.toLowerCase();if(!e[c]){if(e[c]=this,"img"===i){if(this.isImg=!0,t=e.getAttribute("src")||"",!(this.originalUrl=t))return;t=e.src}else"canvas"===i&&window.HTMLCanvasElement&&(t=e.toDataURL());this.load(t)}}},{key:"load",value:function(t){var e,i,a,n,o,h,r=this;t&&(this.url=t,this.imageData={},e=this.element,(i=this.options).rotatable||i.scalable||(i.checkOrientation=!1),i.checkOrientation&&window.ArrayBuffer?lt.test(t)?pt.test(t)?this.read((h=(h=t).replace(Xt,""),a=atob(h),h=new ArrayBuffer(a.length),z(n=new Uint8Array(h),function(t,e){n[e]=a.charCodeAt(e)}),h)):this.clone():(o=new XMLHttpRequest,h=this.clone.bind(this),this.reloading=!0,(this.xhr=o).onabort=h,o.onerror=h,o.ontimeout=h,o.onprogress=function(){o.getResponseHeader("content-type")!==ct&&o.abort()},o.onload=function(){r.read(o.response)},o.onloadend=function(){r.reloading=!1,r.xhr=null},i.checkCrossOrigin&&Lt(t)&&e.crossOrigin&&(t=zt(t)),o.open("GET",t,!0),o.responseType="arraybuffer",o.withCredentials="use-credentials"===e.crossOrigin,o.send()):this.clone())}},{key:"read",value:function(t){var e=this.options,i=this.imageData,a=Rt(t),n=0,o=1,h=1;1<a&&(this.url=function(t,e){for(var i=[],a=new Uint8Array(t);0<a.length;)i.push(Yt.apply(null,yt(a.subarray(0,8192)))),a=a.subarray(8192);return"data:".concat(e,";base64,").concat(btoa(i.join("")))}(t,ct),n=(t=function(t){var e=0,i=1,a=1;switch(t){case 2:i=-1;break;case 3:e=-180;break;case 4:a=-1;break;case 5:e=90,a=-1;break;case 6:e=90;break;case 7:e=90,i=-1;break;case 8:e=-90}return{rotate:e,scaleX:i,scaleY:a}}(a)).rotate,o=t.scaleX,h=t.scaleY),e.rotatable&&(i.rotate=n),e.scalable&&(i.scaleX=o,i.scaleY=h),this.clone()}},{key:"clone",value:function(){var t=this.element,e=this.url,i=t.crossOrigin,a=e,n=(this.options.checkCrossOrigin&&Lt(e)&&(i=i||"anonymous",a=zt(e)),this.crossOrigin=i,this.crossOriginUrl=a,document.createElement("img"));i&&(n.crossOrigin=i),n.src=a||e,n.alt=t.alt||"The image to crop",(this.image=n).onload=this.start.bind(this),n.onerror=this.stop.bind(this),v(n,Z),t.parentNode.insertBefore(n,t.nextSibling)}},{key:"start",value:function(){function t(t,e){g(a.imageData,{naturalWidth:t,naturalHeight:e,aspectRatio:t/e}),a.initialImageData=g({},a.imageData),a.sizing=!1,a.sized=!0,a.build()}var e,i,a=this,n=this.image,o=(n.onload=null,n.onerror=null,this.sizing=!0,h.navigator&&/(?:iPad|iPhone|iPod).*?AppleWebKit/i.test(h.navigator.userAgent));n.naturalWidth&&!o?t(n.naturalWidth,n.naturalHeight):(e=document.createElement("img"),i=document.body||document.documentElement,(this.sizingImage=e).onload=function(){t(e.width,e.height),o||i.removeChild(e)},e.src=n.src,o||(e.style.cssText="left:0;max-height:none!important;max-width:none!important;min-height:0!important;min-width:0!important;opacity:0;position:absolute;top:0;z-index:-1;",i.appendChild(e)))}},{key:"stop",value:function(){var t=this.image;t.onload=null,t.onerror=null,t.parentNode.removeChild(t),this.image=null}},{key:"build",value:function(){var t,e,i,a,n,o,h,r,s;this.sized&&!this.ready&&(t=this.element,e=this.options,i=this.image,a=t.parentNode,(n=document.createElement("div")).innerHTML='<div class="cropper-container" touch-action="none"><div class="cropper-wrap-box"><div class="cropper-canvas"></div></div><div class="cropper-drag-box"></div><div class="cropper-crop-box"><span class="cropper-view-box"></span><span class="cropper-dashed dashed-h"></span><span class="cropper-dashed dashed-v"></span><span class="cropper-center"></span><span class="cropper-face"></span><span class="cropper-line line-e" data-cropper-action="e"></span><span class="cropper-line line-n" data-cropper-action="n"></span><span class="cropper-line line-w" data-cropper-action="w"></span><span class="cropper-line line-s" data-cropper-action="s"></span><span class="cropper-point point-e" data-cropper-action="e"></span><span class="cropper-point point-n" data-cropper-action="n"></span><span class="cropper-point point-w" data-cropper-action="w"></span><span class="cropper-point point-s" data-cropper-action="s"></span><span class="cropper-point point-ne" data-cropper-action="ne"></span><span class="cropper-point point-nw" data-cropper-action="nw"></span><span class="cropper-point point-sw" data-cropper-action="sw"></span><span class="cropper-point point-se" data-cropper-action="se"></span></div></div>',o=(n=n.querySelector(".".concat(c,"-container"))).querySelector(".".concat(c,"-canvas")),h=n.querySelector(".".concat(c,"-drag-box")),s=(r=n.querySelector(".".concat(c,"-crop-box"))).querySelector(".".concat(c,"-face")),this.container=a,this.cropper=n,this.canvas=o,this.dragBox=h,this.cropBox=r,this.viewBox=n.querySelector(".".concat(c,"-view-box")),this.face=s,o.appendChild(i),v(t,L),a.insertBefore(n,t.nextSibling),X(i,Z),this.initPreview(),this.bind(),e.initialAspectRatio=Math.max(0,e.initialAspectRatio)||NaN,e.aspectRatio=Math.max(0,e.aspectRatio)||NaN,e.viewMode=Math.max(0,Math.min(3,Math.round(e.viewMode)))||0,v(r,L),e.guides||v(r.getElementsByClassName("".concat(c,"-dashed")),L),e.center||v(r.getElementsByClassName("".concat(c,"-center")),L),e.background&&v(n,"".concat(c,"-bg")),e.highlight||v(s,G),e.cropBoxMovable&&(v(s,V),w(s,d,I)),e.cropBoxResizable||(v(r.getElementsByClassName("".concat(c,"-line")),L),v(r.getElementsByClassName("".concat(c,"-point")),L)),this.render(),this.ready=!0,this.setDragMode(e.dragMode),e.autoCrop&&this.crop(),this.setData(e.data),l(e.ready)&&b(t,"ready",e.ready,{once:!0}),y(t,"ready"))}},{key:"unbuild",value:function(){var t;this.ready&&(this.ready=!1,this.unbind(),this.resetPreview(),(t=this.cropper.parentNode)&&t.removeChild(this.cropper),X(this.element,L))}},{key:"uncreate",value:function(){this.ready?(this.unbuild(),this.ready=!1,this.cropped=!1):this.sizing?(this.sizingImage.onload=null,this.sizing=!1,this.sized=!1):this.reloading?(this.xhr.onabort=null,this.xhr.abort()):this.image&&this.stop()}}])&&A(t.prototype,e),i&&A(t,i),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e,i}();return g(It.prototype,t,i,e,St,jt,At),It});
|
|
@@ -53,6 +53,9 @@
|
|
|
53
53
|
if (!transition) return
|
|
54
54
|
var direction = document.querySelector('meta[name="page-transition-direction"]')
|
|
55
55
|
if (!style || !direction) {
|
|
56
|
+
// The skip is chosen here, so its `ready` rejection is expected: handled, as in
|
|
57
|
+
// studio/page_transitions' skipOwnTransition. Chrome leaves it unhandled otherwise.
|
|
58
|
+
if (transition.ready && typeof transition.ready.catch === "function") transition.ready.catch(function () {})
|
|
56
59
|
transition.skipTransition()
|
|
57
60
|
return
|
|
58
61
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Cropper.js v1.6.2
|
|
3
|
+
* https://fengyuanchen.github.io/cropperjs
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2015-present Chen Fengyuan
|
|
6
|
+
* Released under the MIT license
|
|
7
|
+
*
|
|
8
|
+
* Date: 2024-04-21T07:43:02.731Z
|
|
9
|
+
*/.cropper-container{-webkit-touch-callout:none;direction:ltr;font-size:0;line-height:0;position:relative;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.cropper-container img{backface-visibility:hidden;display:block;height:100%;image-orientation:0deg;max-height:none!important;max-width:none!important;min-height:0!important;min-width:0!important;width:100%}.cropper-canvas,.cropper-crop-box,.cropper-drag-box,.cropper-modal,.cropper-wrap-box{bottom:0;left:0;position:absolute;right:0;top:0}.cropper-canvas,.cropper-wrap-box{overflow:hidden}.cropper-drag-box{background-color:#fff;opacity:0}.cropper-modal{background-color:#000;opacity:.5}.cropper-view-box{display:block;height:100%;outline:1px solid #39f;outline-color:rgba(51,153,255,.75);overflow:hidden;width:100%}.cropper-dashed{border:0 dashed #eee;display:block;opacity:.5;position:absolute}.cropper-dashed.dashed-h{border-bottom-width:1px;border-top-width:1px;height:33.33333%;left:0;top:33.33333%;width:100%}.cropper-dashed.dashed-v{border-left-width:1px;border-right-width:1px;height:100%;left:33.33333%;top:0;width:33.33333%}.cropper-center{display:block;height:0;left:50%;opacity:.75;position:absolute;top:50%;width:0}.cropper-center:after,.cropper-center:before{background-color:#eee;content:" ";display:block;position:absolute}.cropper-center:before{height:1px;left:-3px;top:0;width:7px}.cropper-center:after{height:7px;left:0;top:-3px;width:1px}.cropper-face,.cropper-line,.cropper-point{display:block;height:100%;opacity:.1;position:absolute;width:100%}.cropper-face{background-color:#fff;left:0;top:0}.cropper-line{background-color:#39f}.cropper-line.line-e{cursor:ew-resize;right:-3px;top:0;width:5px}.cropper-line.line-n{cursor:ns-resize;height:5px;left:0;top:-3px}.cropper-line.line-w{cursor:ew-resize;left:-3px;top:0;width:5px}.cropper-line.line-s{bottom:-3px;cursor:ns-resize;height:5px;left:0}.cropper-point{background-color:#39f;height:5px;opacity:.75;width:5px}.cropper-point.point-e{cursor:ew-resize;margin-top:-3px;right:-3px;top:50%}.cropper-point.point-n{cursor:ns-resize;left:50%;margin-left:-3px;top:-3px}.cropper-point.point-w{cursor:ew-resize;left:-3px;margin-top:-3px;top:50%}.cropper-point.point-s{bottom:-3px;cursor:s-resize;left:50%;margin-left:-3px}.cropper-point.point-ne{cursor:nesw-resize;right:-3px;top:-3px}.cropper-point.point-nw{cursor:nwse-resize;left:-3px;top:-3px}.cropper-point.point-sw{bottom:-3px;cursor:nesw-resize;left:-3px}.cropper-point.point-se{bottom:-3px;cursor:nwse-resize;height:20px;opacity:1;right:-3px;width:20px}@media (min-width:768px){.cropper-point.point-se{height:15px;width:15px}}@media (min-width:992px){.cropper-point.point-se{height:10px;width:10px}}@media (min-width:1200px){.cropper-point.point-se{height:5px;opacity:.75;width:5px}}.cropper-point.point-se:before{background-color:#39f;bottom:-50%;content:" ";display:block;height:200%;opacity:0;position:absolute;right:-50%;width:200%}.cropper-invisible{opacity:0}.cropper-bg{background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC")}.cropper-hide{display:block;height:0;position:absolute;width:0}.cropper-hidden{display:none!important}.cropper-move{cursor:move}.cropper-crop{cursor:crosshair}.cropper-disabled .cropper-drag-box,.cropper-disabled .cropper-face,.cropper-disabled .cropper-line,.cropper-disabled .cropper-point{cursor:not-allowed}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Studio
|
|
4
|
+
# The connect, callback and disconnect actions for any provider a host
|
|
5
|
+
# declared with Studio.define_connection (docs/CONNECTIONS.md). Included by
|
|
6
|
+
# Studio::ConnectionsController; a host includes it in its own admin
|
|
7
|
+
# controller instead when that controller also serves the provider's page
|
|
8
|
+
# (its `show`, with the provider's live read), and names that controller in
|
|
9
|
+
# Studio.draw_connection_routes.
|
|
10
|
+
#
|
|
11
|
+
# connect checks the encryption keys and the client, keeps a fresh OAuth
|
|
12
|
+
# state (and, for an account named before Connect, the checked
|
|
13
|
+
# account) in the session, and redirects to the provider
|
|
14
|
+
# callback checks the state first, then the provider's refusal, its own
|
|
15
|
+
# callback check and the account; exchanges the code (a code
|
|
16
|
+
# grant); names the account with the host's describe hook; and
|
|
17
|
+
# stores Studio::Connection. The account named before Connect
|
|
18
|
+
# is read from the session, never from the callback's query.
|
|
19
|
+
# disconnect revokes the grant at the provider when it has a revoke
|
|
20
|
+
# endpoint, forgets an in-memory token, deletes the row, and
|
|
21
|
+
# says whether the provider confirmed
|
|
22
|
+
#
|
|
23
|
+
# No token, and no part of one, is rendered, flashed or logged here. A
|
|
24
|
+
# refused exchange, describe or revoke is kept in the error log
|
|
25
|
+
# (Studio::ErrorHandling#rescue_and_log) as well as said on the page.
|
|
26
|
+
#
|
|
27
|
+
# WHO MAY: the host's admin guard, Studio.connection_admin_guard (a method
|
|
28
|
+
# name on the controller, :require_admin by default, or a callable taking
|
|
29
|
+
# the controller). WHERE IT COMES BACK: return_to, honoured only when it is
|
|
30
|
+
# exactly one of the route's return paths (never an open redirect).
|
|
31
|
+
module ConnectionFlow
|
|
32
|
+
extend ActiveSupport::Concern
|
|
33
|
+
|
|
34
|
+
included do
|
|
35
|
+
before_action :require_connection_admin
|
|
36
|
+
# The callback's URL carries a single-use code: no cache keeps the page.
|
|
37
|
+
before_action(only: :callback) { response.headers["Cache-Control"] = "no-store" }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def connect
|
|
41
|
+
provider = connection_provider
|
|
42
|
+
# An account typed at Connect is accepted only on a CSRF-checked POST,
|
|
43
|
+
# even when a host draws a GET route by hand.
|
|
44
|
+
return head(:method_not_allowed) if provider.account_source == :connect && !request.post?
|
|
45
|
+
|
|
46
|
+
back = connection_return_to(params[:return_to])
|
|
47
|
+
return redirect_to(back, alert: connection_encryption_message) unless Studio::Connections.encryption_ready?
|
|
48
|
+
|
|
49
|
+
account = nil
|
|
50
|
+
if provider.account_source == :connect
|
|
51
|
+
account = provider.normalize_account(params[provider.account_param]) or
|
|
52
|
+
return redirect_to(back, alert: "That is not a #{provider.label} account. Check what you entered, then press Connect again.")
|
|
53
|
+
end
|
|
54
|
+
url = provider.authorize_url(redirect_uri: connection_callback_url, state: new_connection_state, account:)
|
|
55
|
+
session[connection_session_key(:account)] = account
|
|
56
|
+
session[connection_session_key(:return_to)] = back
|
|
57
|
+
redirect_to url, allow_other_host: true
|
|
58
|
+
rescue Studio::Connections::NotConfigured
|
|
59
|
+
redirect_to back, alert: connection_keys_message
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def callback
|
|
63
|
+
provider = connection_provider
|
|
64
|
+
expected = session.delete(connection_session_key(:state)).to_s
|
|
65
|
+
kept_account = session.delete(connection_session_key(:account))
|
|
66
|
+
back = connection_return_to(session.delete(connection_session_key(:return_to)))
|
|
67
|
+
account = provider.account_source == :connect ? provider.normalize_account(kept_account) : nil
|
|
68
|
+
unless connection_state_matches?(expected) && (provider.account_source != :connect || account)
|
|
69
|
+
return render(plain: "OAuth state mismatch: start the connection again.", status: :bad_request)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
return redirect_to(back, alert: connection_refusal(provider, params[:error].to_s)) if params[:error].present?
|
|
73
|
+
return redirect_to(back, alert: connection_encryption_message) unless Studio::Connections.encryption_ready?
|
|
74
|
+
|
|
75
|
+
problem = provider.callback_check&.call(params)
|
|
76
|
+
return redirect_to(back, alert: problem.to_s) if problem.present?
|
|
77
|
+
|
|
78
|
+
if provider.account_source == :callback
|
|
79
|
+
account = provider.normalize_account(params[provider.account_param]) or
|
|
80
|
+
return redirect_to(back, alert: "#{provider.label} came back without naming a valid account. Nothing was connected; start again.")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
grant = {}
|
|
84
|
+
if provider.grant == :authorization_code
|
|
85
|
+
grant = rescue_and_log(target: current_user) do
|
|
86
|
+
provider.exchange_code(code: params[:code].to_s, redirect_uri: connection_callback_url, account:)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
described = describe_connection(provider, grant, account)
|
|
90
|
+
account ||= described[:account]
|
|
91
|
+
return redirect_to(back, alert: "#{provider.label} answered, but did not say which account it was. Nothing was connected.") if account.blank?
|
|
92
|
+
|
|
93
|
+
connection = rescue_and_log(target: current_user) do
|
|
94
|
+
Studio::Connection.store!(provider, grant, account:, by: connection_actor,
|
|
95
|
+
label: described[:label], metadata: described[:metadata] || {})
|
|
96
|
+
end
|
|
97
|
+
redirect_to back, notice: "#{provider.label} connected: #{connection.label}."
|
|
98
|
+
rescue ActiveRecord::RecordInvalid => e
|
|
99
|
+
redirect_to back, alert: "#{provider.label} answered, but the connection was not saved: #{e.record.errors.full_messages.to_sentence}."
|
|
100
|
+
rescue Studio::Connections::InvalidAccount
|
|
101
|
+
redirect_to back, alert: "#{provider.label} came back without naming a valid account. Nothing was connected; start again."
|
|
102
|
+
rescue Studio::Connections::NotConfigured
|
|
103
|
+
redirect_to back, alert: connection_keys_message
|
|
104
|
+
rescue Studio::Connections::Error => e
|
|
105
|
+
redirect_to back, alert: "#{provider.label} refused to exchange the sign-in code (#{e.message}). Start again: a code works once."
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def disconnect
|
|
109
|
+
provider = connection_provider
|
|
110
|
+
back = connection_return_to(params[:return_to])
|
|
111
|
+
connection = Studio::Connection.for_provider(provider.key).find_by(id: params[:id])
|
|
112
|
+
return redirect_to(back, notice: "That #{provider.label} account was not connected, so nothing changed.", status: :see_other) unless connection
|
|
113
|
+
|
|
114
|
+
label = connection.label
|
|
115
|
+
revoked = revoke_connection(provider, connection)
|
|
116
|
+
rescue_and_log(target: current_user) do
|
|
117
|
+
provider.forget!(connection.account_id) if provider.refresh == :memory && connection.readable?
|
|
118
|
+
connection.destroy!
|
|
119
|
+
end
|
|
120
|
+
Rails.logger.info("[studio_connection] disconnect provider=#{provider.key} row=#{connection.id} " \
|
|
121
|
+
"by=#{connection_actor} at=#{Time.current.utc.iso8601} revoked=#{revoked.inspect}")
|
|
122
|
+
notice = case revoked
|
|
123
|
+
when true then "#{provider.label} disconnected for #{label}: #{provider.label} revoked the grant and the stored connection was deleted here."
|
|
124
|
+
when nil then "#{provider.label} disconnected for #{label}: the stored connection was deleted here. #{provider.revoke_note}"
|
|
125
|
+
else "#{provider.label} disconnected for #{label}: the stored connection was deleted here, but #{provider.label} did not confirm the revoke. #{provider.revoke_note}"
|
|
126
|
+
end
|
|
127
|
+
redirect_to back, notice:, status: :see_other
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
private
|
|
131
|
+
|
|
132
|
+
# The provider this request is for: the route's `studio_connection` default.
|
|
133
|
+
def connection_provider
|
|
134
|
+
@connection_provider ||= Studio::Connections.fetch(params[:studio_connection])
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def connection_route = Studio::Connections.route(connection_provider.key)
|
|
138
|
+
|
|
139
|
+
# A method guard refuses the way a before_action does: it renders or
|
|
140
|
+
# redirects. A callable guard may do the same, or answer: false or nil
|
|
141
|
+
# refuses with 403, so `->(c) { c.current_user&.admin? }` is safe.
|
|
142
|
+
def require_connection_admin
|
|
143
|
+
guard = Studio.connection_admin_guard
|
|
144
|
+
return send(guard) unless guard.respond_to?(:call)
|
|
145
|
+
|
|
146
|
+
allowed = guard.call(self)
|
|
147
|
+
head(:forbidden) unless allowed || performed?
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Who connected it, as connected_by records: the user's slug, else their id.
|
|
151
|
+
def connection_actor
|
|
152
|
+
user = respond_to?(:current_user, true) ? current_user : nil
|
|
153
|
+
return nil unless user
|
|
154
|
+
|
|
155
|
+
(user.respond_to?(:slug) && user.slug.presence) || user.id.to_s
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# The host's describe hook: { account:, label:, metadata: } for the account
|
|
159
|
+
# just connected (a whoami, a company name). A provider error there is kept
|
|
160
|
+
# in the error log and the connection stores under the provider's label.
|
|
161
|
+
def describe_connection(provider, grant, account)
|
|
162
|
+
return {} unless provider.describe
|
|
163
|
+
|
|
164
|
+
rescue_and_log(target: current_user) do
|
|
165
|
+
provider.describe.call(grant:, account:, provider:).to_h.symbolize_keys
|
|
166
|
+
end
|
|
167
|
+
rescue Studio::Connections::Error
|
|
168
|
+
{}
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# True when the provider took the revoke, nil when it has no revoke
|
|
172
|
+
# endpoint, false when it refused or the row cannot be read.
|
|
173
|
+
def revoke_connection(provider, connection)
|
|
174
|
+
return nil unless provider.revocable?
|
|
175
|
+
return false unless connection.readable?
|
|
176
|
+
|
|
177
|
+
rescue_and_log(target: connection) { provider.revoke(connection) }
|
|
178
|
+
rescue Studio::Connections::Error
|
|
179
|
+
false
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def connection_refusal(provider, code)
|
|
183
|
+
return "The sign-in was declined on #{provider.label}. Nothing was connected." if provider.declined_errors.include?(code)
|
|
184
|
+
|
|
185
|
+
"#{provider.label} refused the sign-in (#{code[0, 100]}). #{provider.refusal_hint}"
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def connection_keys_message
|
|
189
|
+
"#{connection_provider.label} connections are not set up on this server: #{connection_provider.env_names.join(' and ')} are not set."
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
def connection_encryption_message
|
|
193
|
+
"This server cannot store a connection: its encryption keys are not set " \
|
|
194
|
+
"(#{Studio::Connections::ENCRYPTION_ENV.join(', ')}). Nothing was asked of #{connection_provider.label}."
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def connection_return_to(value)
|
|
198
|
+
paths = connection_route.return_paths
|
|
199
|
+
paths.include?(value) ? value : paths.first
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def connection_callback_url = public_send(:"#{connection_route.as}_callback_url")
|
|
203
|
+
|
|
204
|
+
def connection_session_key(name) = "studio_connection_#{connection_provider.key}_#{name}"
|
|
205
|
+
|
|
206
|
+
def connection_state_matches?(expected)
|
|
207
|
+
params[:state].present? && expected.present? &&
|
|
208
|
+
ActiveSupport::SecurityUtils.secure_compare(params[:state].to_s, expected)
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def new_connection_state
|
|
212
|
+
SecureRandom.hex(16).tap { |state| session[connection_session_key(:state)] = state }
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
@@ -23,6 +23,9 @@ module Studio
|
|
|
23
23
|
rescue_from "Sluggable::SlugRefused", with: :handle_slug_refused
|
|
24
24
|
rescue_from ActionController::InvalidAuthenticityToken, with: :handle_invalid_authenticity_token
|
|
25
25
|
|
|
26
|
+
# First, ahead of every host filter: a revoked device session is signed out
|
|
27
|
+
# before anything reads current_user (docs/DEVICE_SESSIONS.md).
|
|
28
|
+
prepend_before_action :end_revoked_device_session
|
|
26
29
|
before_action :require_authentication
|
|
27
30
|
after_action :track_user_session
|
|
28
31
|
|
|
@@ -39,11 +42,63 @@ module Studio
|
|
|
39
42
|
return unless session[Studio.session_key]
|
|
40
43
|
|
|
41
44
|
user = respond_to?(:true_user, true) ? true_user : current_user
|
|
42
|
-
Studio::UserSession.track(session, user) if user
|
|
45
|
+
Studio::UserSession.track(session, user, row: @_studio_device_session_row) if user
|
|
43
46
|
rescue StandardError => e
|
|
44
47
|
Rails.logger&.warn("[user_session] #{e.class}: #{e.message}")
|
|
45
48
|
end
|
|
46
49
|
|
|
50
|
+
# A copy of a cookie whose device logged out still carries that device's sid,
|
|
51
|
+
# and the server row says it ended: sign this request out (this app's keys
|
|
52
|
+
# only, through the host's own clear_app_session), so it runs as a visitor.
|
|
53
|
+
# One indexed query when the cookie carries a sid; none when signed out.
|
|
54
|
+
def end_revoked_device_session
|
|
55
|
+
return unless session[Studio.session_key]
|
|
56
|
+
|
|
57
|
+
verdict, @_studio_device_session_row = Studio::UserSession.verdict(session)
|
|
58
|
+
return unless verdict == :ended
|
|
59
|
+
|
|
60
|
+
Rails.logger&.info("[user_session] ended device session presented; signing the request out")
|
|
61
|
+
session.delete(Studio::UserSession.cookie_key)
|
|
62
|
+
clear_app_session
|
|
63
|
+
remove_instance_variable(:@current_user) if instance_variable_defined?(:@current_user)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Ends this device's session on the server: the row of its sid is revoked, so
|
|
67
|
+
# a copy of this cookie no longer signs in. Other devices are untouched. A
|
|
68
|
+
# failed write is logged to ErrorLog and the logout still goes on: the browser's
|
|
69
|
+
# copy is dropped either way, which is what logout did before.
|
|
70
|
+
def end_device_session
|
|
71
|
+
Studio::UserSession.revoke!(session)
|
|
72
|
+
rescue StandardError => e
|
|
73
|
+
log_device_session_failure(e)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Starts the device session a sign-in opens (Studio::UserSession.start!). A
|
|
77
|
+
# failure is logged and the sign-in goes on; this request's track retries.
|
|
78
|
+
def start_device_session(user)
|
|
79
|
+
Studio::UserSession.start!(session, user)
|
|
80
|
+
rescue StandardError => e
|
|
81
|
+
log_device_session_failure(e, target: user)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# rescue_and_log's logging without its re-raise: the auth step this guards
|
|
85
|
+
# must finish even when the bookkeeping write fails.
|
|
86
|
+
def log_device_session_failure(exception, target: nil)
|
|
87
|
+
error_log = create_error_log(exception)
|
|
88
|
+
attach_error_context(error_log, :target, target)
|
|
89
|
+
error_log.save!
|
|
90
|
+
rescue StandardError => log_error
|
|
91
|
+
log_error_write_failed(log_error, exception)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Rails' reset_session, ending the device session first. Hosts call it on
|
|
95
|
+
# logout (Turf) and before a sign-in by a different identity; both end the
|
|
96
|
+
# session this cookie held.
|
|
97
|
+
def reset_session
|
|
98
|
+
end_device_session if request
|
|
99
|
+
super
|
|
100
|
+
end
|
|
101
|
+
|
|
47
102
|
def current_user
|
|
48
103
|
return @current_user if defined?(@current_user)
|
|
49
104
|
@current_user = User.find_by(id: session[Studio.session_key])
|
|
@@ -52,6 +107,7 @@ module Studio
|
|
|
52
107
|
def set_app_session(user)
|
|
53
108
|
# App-specific session (only this app reads this key)
|
|
54
109
|
session[Studio.session_key] = user.id
|
|
110
|
+
start_device_session(user)
|
|
55
111
|
|
|
56
112
|
# OPSEC-045: bind a rotating per-user token into the cookie. The
|
|
57
113
|
# verify_session_token filter compares it to user.session_token on every
|
|
@@ -86,6 +142,7 @@ module Studio
|
|
|
86
142
|
end
|
|
87
143
|
|
|
88
144
|
def clear_app_session
|
|
145
|
+
end_device_session
|
|
89
146
|
session.delete(Studio.session_key)
|
|
90
147
|
session.delete(:session_token)
|
|
91
148
|
session.delete(:onchain)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Studio
|
|
4
|
+
# The engine's own home for a provider's connect, callback and disconnect
|
|
5
|
+
# (Studio::ConnectionFlow), for a host that serves the provider's page from
|
|
6
|
+
# elsewhere or not at all. Studio.draw_connection_routes points here unless
|
|
7
|
+
# the host names its own controller. It inherits the host's
|
|
8
|
+
# ApplicationController, so the host's layout, session, current_user and
|
|
9
|
+
# Studio::ErrorHandling (rescue_and_log, require_admin) apply.
|
|
10
|
+
class ConnectionsController < ::ApplicationController
|
|
11
|
+
include Studio::ConnectionFlow
|
|
12
|
+
end
|
|
13
|
+
end
|