@rocket/js 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +224 -2
- package/dist-types/exports/MainMenu.d.ts +2 -0
- package/dist-types/exports/MainMenu.d.ts.map +1 -0
- package/dist-types/exports/PageData.d.ts +2 -0
- package/dist-types/exports/PageData.d.ts.map +1 -0
- package/dist-types/exports/RocketCodeBlock.d.ts +2 -0
- package/dist-types/exports/RocketCodeBlock.d.ts.map +1 -0
- package/dist-types/exports/RocketIcon.d.ts +2 -0
- package/dist-types/exports/RocketIcon.d.ts.map +1 -0
- package/dist-types/exports/RocketJsDemo.d.ts +2 -0
- package/dist-types/exports/RocketJsDemo.d.ts.map +1 -0
- package/dist-types/exports/RocketRequestDemo.d.ts +2 -0
- package/dist-types/exports/RocketRequestDemo.d.ts.map +1 -0
- package/dist-types/exports/SocialPreviewPlayground.d.ts +2 -0
- package/dist-types/exports/SocialPreviewPlayground.d.ts.map +1 -0
- package/dist-types/exports/adapters/netlify.d.ts +2 -0
- package/dist-types/exports/adapters/netlify.d.ts.map +1 -0
- package/dist-types/exports/asyncMessage.d.ts +2 -0
- package/dist-types/exports/asyncMessage.d.ts.map +1 -0
- package/dist-types/exports/component-hydration.d.ts +2 -0
- package/dist-types/exports/component-hydration.d.ts.map +1 -0
- package/dist-types/exports/components/web-awesome.d.ts +3 -0
- package/dist-types/exports/components/web-awesome.d.ts.map +1 -0
- package/dist-types/exports/components.d.ts +2 -0
- package/dist-types/exports/components.d.ts.map +1 -0
- package/dist-types/exports/config.d.ts +2 -0
- package/dist-types/exports/config.d.ts.map +1 -0
- package/dist-types/exports/debounce.d.ts +2 -0
- package/dist-types/exports/debounce.d.ts.map +1 -0
- package/dist-types/exports/define/RocketCodeBlock.d.ts +2 -0
- package/dist-types/exports/define/RocketCodeBlock.d.ts.map +1 -0
- package/dist-types/exports/define/RocketIcon.d.ts +2 -0
- package/dist-types/exports/define/RocketIcon.d.ts.map +1 -0
- package/dist-types/exports/define/RocketJsDemo.d.ts +2 -0
- package/dist-types/exports/define/RocketJsDemo.d.ts.map +1 -0
- package/dist-types/exports/define/RocketRequestDemo.d.ts +2 -0
- package/dist-types/exports/define/RocketRequestDemo.d.ts.map +1 -0
- package/dist-types/exports/define/menus.d.ts +2 -0
- package/dist-types/exports/define/menus.d.ts.map +1 -0
- package/dist-types/exports/extractCode.d.ts +2 -0
- package/dist-types/exports/extractCode.d.ts.map +1 -0
- package/dist-types/exports/globalData.d.ts +2 -0
- package/dist-types/exports/globalData.d.ts.map +1 -0
- package/dist-types/exports/hydration/hydrationLoader.d.ts +2 -0
- package/dist-types/exports/hydration/hydrationLoader.d.ts.map +1 -0
- package/dist-types/exports/icons.d.ts +2 -0
- package/dist-types/exports/icons.d.ts.map +1 -0
- package/dist-types/exports/layout-helper.d.ts +2 -0
- package/dist-types/exports/layout-helper.d.ts.map +1 -0
- package/dist-types/exports/layout.d.ts +2 -0
- package/dist-types/exports/layout.d.ts.map +1 -0
- package/dist-types/exports/layouts/atlasDoc.d.ts +2 -0
- package/dist-types/exports/layouts/atlasDoc.d.ts.map +1 -0
- package/dist-types/exports/layouts/atlasHero.d.ts +2 -0
- package/dist-types/exports/layouts/atlasHero.d.ts.map +1 -0
- package/dist-types/exports/layouts/atlasNotFound.d.ts +2 -0
- package/dist-types/exports/layouts/atlasNotFound.d.ts.map +1 -0
- package/dist-types/exports/loaded-page-module.d.ts +2 -0
- package/dist-types/exports/loaded-page-module.d.ts.map +1 -0
- package/dist-types/exports/markdownHook.d.ts +2 -0
- package/dist-types/exports/markdownHook.d.ts.map +1 -0
- package/dist-types/exports/menu.d.ts +2 -0
- package/dist-types/exports/menu.d.ts.map +1 -0
- package/dist-types/exports/menus.d.ts +6 -0
- package/dist-types/exports/menus.d.ts.map +1 -0
- package/dist-types/exports/page-runtime.d.ts +2 -0
- package/dist-types/exports/page-runtime.d.ts.map +1 -0
- package/dist-types/exports/pages.d.ts +2 -0
- package/dist-types/exports/pages.d.ts.map +1 -0
- package/dist-types/exports/resolve.d.ts +2 -0
- package/dist-types/exports/resolve.d.ts.map +1 -0
- package/dist-types/exports/ssr.d.ts +2 -0
- package/dist-types/exports/ssr.d.ts.map +1 -0
- package/dist-types/exports/standalone-demo-url.d.ts +2 -0
- package/dist-types/exports/standalone-demo-url.d.ts.map +1 -0
- package/dist-types/exports/transform.d.ts +2 -0
- package/dist-types/exports/transform.d.ts.map +1 -0
- package/dist-types/exports/types/hydration.d.ts +23 -0
- package/dist-types/exports/types/hydration.d.ts.map +1 -0
- package/dist-types/exports/types/rocket.d.ts +504 -0
- package/dist-types/exports/types/rocket.d.ts.map +1 -0
- package/dist-types/exports/types.d.ts +3 -0
- package/dist-types/exports/types.d.ts.map +1 -0
- package/dist-types/exports/wds-plugin.d.ts +2 -0
- package/dist-types/exports/wds-plugin.d.ts.map +1 -0
- package/dist-types/src/PageData.d.ts +82 -0
- package/dist-types/src/PageData.d.ts.map +1 -0
- package/dist-types/src/RocketCodeBlock.d.ts +64 -0
- package/dist-types/src/RocketCodeBlock.d.ts.map +1 -0
- package/dist-types/src/RocketIcon.d.ts +35 -0
- package/dist-types/src/RocketIcon.d.ts.map +1 -0
- package/dist-types/src/RocketJsDemo.d.ts +59 -0
- package/dist-types/src/RocketJsDemo.d.ts.map +1 -0
- package/dist-types/src/RocketJsDemo.test-browser.d.ts +3 -0
- package/dist-types/src/RocketJsDemo.test-browser.d.ts.map +1 -0
- package/dist-types/src/RocketRequestDemo.d.ts +57 -0
- package/dist-types/src/RocketRequestDemo.d.ts.map +1 -0
- package/dist-types/src/RocketRequestDemo.test-browser.d.ts +3 -0
- package/dist-types/src/RocketRequestDemo.test-browser.d.ts.map +1 -0
- package/dist-types/src/SocialPreviewPlayground.d.ts +102 -0
- package/dist-types/src/SocialPreviewPlayground.d.ts.map +1 -0
- package/dist-types/src/adapters/netlify.d.ts +54 -0
- package/dist-types/src/adapters/netlify.d.ts.map +1 -0
- package/dist-types/src/asyncMessage.d.ts +14 -0
- package/dist-types/src/asyncMessage.d.ts.map +1 -0
- package/dist-types/src/cli/RocketBuild.d.ts +78 -0
- package/dist-types/src/cli/RocketBuild.d.ts.map +1 -0
- package/dist-types/src/cli/RocketCli.d.ts +17 -0
- package/dist-types/src/cli/RocketCli.d.ts.map +1 -0
- package/dist-types/src/cli/RocketInit.d.ts +22 -0
- package/dist-types/src/cli/RocketInit.d.ts.map +1 -0
- package/dist-types/src/cli/RocketStart.d.ts +13 -0
- package/dist-types/src/cli/RocketStart.d.ts.map +1 -0
- package/dist-types/src/cli/cli.d.ts +3 -0
- package/dist-types/src/cli/cli.d.ts.map +1 -0
- package/dist-types/src/component-hydration.d.ts +26 -0
- package/dist-types/src/component-hydration.d.ts.map +1 -0
- package/dist-types/src/components/FeatureList.d.ts +15 -0
- package/dist-types/src/components/FeatureList.d.ts.map +1 -0
- package/dist-types/src/components/Footer.d.ts +17 -0
- package/dist-types/src/components/Footer.d.ts.map +1 -0
- package/dist-types/src/components/Header.d.ts +6 -0
- package/dist-types/src/components/Header.d.ts.map +1 -0
- package/dist-types/src/components/RocketDrawer.d.ts +20 -0
- package/dist-types/src/components/RocketDrawer.d.ts.map +1 -0
- package/dist-types/src/components/RocketSocialLink.d.ts +30 -0
- package/dist-types/src/components/RocketSocialLink.d.ts.map +1 -0
- package/dist-types/src/components.d.ts +5 -0
- package/dist-types/src/components.d.ts.map +1 -0
- package/dist-types/src/config.d.ts +6 -0
- package/dist-types/src/config.d.ts.map +1 -0
- package/dist-types/src/debounce.d.ts +8 -0
- package/dist-types/src/debounce.d.ts.map +1 -0
- package/dist-types/src/defaultSocialPreviewTemplate.d.ts +31 -0
- package/dist-types/src/defaultSocialPreviewTemplate.d.ts.map +1 -0
- package/dist-types/src/development-page-module-loader.d.ts +15 -0
- package/dist-types/src/development-page-module-loader.d.ts.map +1 -0
- package/dist-types/src/extractCode.d.ts +5 -0
- package/dist-types/src/extractCode.d.ts.map +1 -0
- package/dist-types/src/hydration/evaluate.d.ts +20 -0
- package/dist-types/src/hydration/evaluate.d.ts.map +1 -0
- package/dist-types/src/hydration/extractStrategies.d.ts +5 -0
- package/dist-types/src/hydration/extractStrategies.d.ts.map +1 -0
- package/dist-types/src/hydration/hydrationLoader.d.ts +64 -0
- package/dist-types/src/hydration/hydrationLoader.d.ts.map +1 -0
- package/dist-types/src/icons.d.ts +170 -0
- package/dist-types/src/icons.d.ts.map +1 -0
- package/dist-types/src/layouts/atlas/atlasDocLayout.d.ts +45 -0
- package/dist-types/src/layouts/atlas/atlasDocLayout.d.ts.map +1 -0
- package/dist-types/src/layouts/atlas/atlasHeroLayout.d.ts +7 -0
- package/dist-types/src/layouts/atlas/atlasHeroLayout.d.ts.map +1 -0
- package/dist-types/src/layouts/atlas/atlasNotFoundLayout.d.ts +5 -0
- package/dist-types/src/layouts/atlas/atlasNotFoundLayout.d.ts.map +1 -0
- package/dist-types/src/layouts/layout-helper.d.ts +16 -0
- package/dist-types/src/layouts/layout-helper.d.ts.map +1 -0
- package/dist-types/src/layouts/layout.d.ts +9 -0
- package/dist-types/src/layouts/layout.d.ts.map +1 -0
- package/dist-types/src/loaded-page-module.d.ts +51 -0
- package/dist-types/src/loaded-page-module.d.ts.map +1 -0
- package/dist-types/src/main.d.ts +2 -0
- package/dist-types/src/main.d.ts.map +1 -0
- package/dist-types/src/markdownCompiler.d.ts +22 -0
- package/dist-types/src/markdownCompiler.d.ts.map +1 -0
- package/dist-types/src/markdownHook.d.ts +6 -0
- package/dist-types/src/markdownHook.d.ts.map +1 -0
- package/dist-types/src/menu.d.ts +22 -0
- package/dist-types/src/menu.d.ts.map +1 -0
- package/dist-types/src/menus/MainMenu.d.ts +23 -0
- package/dist-types/src/menus/MainMenu.d.ts.map +1 -0
- package/dist-types/src/menus/RocketMenu.d.ts +23 -0
- package/dist-types/src/menus/RocketMenu.d.ts.map +1 -0
- package/dist-types/src/menus/RocketNextPage.d.ts +18 -0
- package/dist-types/src/menus/RocketNextPage.d.ts.map +1 -0
- package/dist-types/src/menus/RocketPreviousPage.d.ts +18 -0
- package/dist-types/src/menus/RocketPreviousPage.d.ts.map +1 -0
- package/dist-types/src/menus/RocketToc.d.ts +54 -0
- package/dist-types/src/menus/RocketToc.d.ts.map +1 -0
- package/dist-types/src/menus/pageNavigation.d.ts +41 -0
- package/dist-types/src/menus/pageNavigation.d.ts.map +1 -0
- package/dist-types/src/page-pagination.d.ts +69 -0
- package/dist-types/src/page-pagination.d.ts.map +1 -0
- package/dist-types/src/page-runtime.d.ts +110 -0
- package/dist-types/src/page-runtime.d.ts.map +1 -0
- package/dist-types/src/pages.d.ts +10 -0
- package/dist-types/src/pages.d.ts.map +1 -0
- package/dist-types/src/publicAssets.d.ts +70 -0
- package/dist-types/src/publicAssets.d.ts.map +1 -0
- package/dist-types/src/requestDemoMetadata.d.ts +19 -0
- package/dist-types/src/requestDemoMetadata.d.ts.map +1 -0
- package/dist-types/src/resolve.d.ts +7 -0
- package/dist-types/src/resolve.d.ts.map +1 -0
- package/dist-types/src/siteDiscoverability.d.ts +33 -0
- package/dist-types/src/siteDiscoverability.d.ts.map +1 -0
- package/dist-types/src/siteHeadMetadata.d.ts +20 -0
- package/dist-types/src/siteHeadMetadata.d.ts.map +1 -0
- package/dist-types/src/socialPreviewImages.d.ts +186 -0
- package/dist-types/src/socialPreviewImages.d.ts.map +1 -0
- package/dist-types/src/socialPreviewTemplatePreview.d.ts +22 -0
- package/dist-types/src/socialPreviewTemplatePreview.d.ts.map +1 -0
- package/dist-types/src/ssr.d.ts +6 -0
- package/dist-types/src/ssr.d.ts.map +1 -0
- package/dist-types/src/standalone-demo-url.d.ts +60 -0
- package/dist-types/src/standalone-demo-url.d.ts.map +1 -0
- package/dist-types/src/static-page-module-loader.d.ts +15 -0
- package/dist-types/src/static-page-module-loader.d.ts.map +1 -0
- package/dist-types/src/transform.d.ts +10 -0
- package/dist-types/src/transform.d.ts.map +1 -0
- package/dist-types/src/urlLifecycle.d.ts +23 -0
- package/dist-types/src/urlLifecycle.d.ts.map +1 -0
- package/dist-types/src/wds-plugin.d.ts +14 -0
- package/dist-types/src/wds-plugin.d.ts.map +1 -0
- package/docs/assets/home-background.svg +1 -0
- package/docs/assets/prism-one-light.css +368 -0
- package/docs/assets/rocket-logo-dark-with-text-below.svg +8 -0
- package/docs/assets/rocket-logo-dark-with-text.svg +7 -0
- package/docs/assets/rocket-logo-dark.svg +7 -0
- package/docs/assets/rocket-logo-light-with-text-below.svg +14 -0
- package/docs/assets/rocket-logo-light-with-text.svg +13 -0
- package/docs/assets/rocket-logo-light.svg +12 -0
- package/docs/assets/rocket-text-no-logo.svg +3 -0
- package/exports/MainMenu.js +1 -0
- package/exports/PageData.js +1 -0
- package/exports/RocketCodeBlock.js +1 -0
- package/exports/RocketIcon.js +1 -0
- package/exports/RocketJsDemo.js +1 -0
- package/exports/RocketRequestDemo.js +1 -0
- package/exports/SocialPreviewPlayground.js +1 -0
- package/exports/adapters/netlify.js +1 -0
- package/exports/asyncMessage.js +1 -0
- package/exports/component-hydration.js +1 -0
- package/exports/components/web-awesome.js +63 -0
- package/exports/components.js +1 -0
- package/exports/config.js +1 -0
- package/exports/debounce.js +1 -0
- package/exports/define/RocketCodeBlock.js +2 -0
- package/exports/define/RocketIcon.js +3 -0
- package/exports/define/RocketJsDemo.js +5 -0
- package/exports/define/RocketRequestDemo.js +5 -0
- package/exports/define/menus.js +14 -0
- package/exports/extractCode.js +1 -0
- package/exports/globalData.js +1 -0
- package/exports/hydration/hydrationLoader.js +1 -0
- package/exports/icons.js +8 -0
- package/exports/layout-helper.js +1 -0
- package/exports/layout.js +1 -0
- package/exports/layouts/_atlas.css +3 -0
- package/exports/layouts/atlasDoc.js +5 -0
- package/exports/layouts/atlasHero.js +1 -0
- package/exports/layouts/atlasNotFound.js +4 -0
- package/exports/loaded-page-module.js +5 -0
- package/exports/markdownHook.js +4 -0
- package/exports/menu.js +4 -0
- package/exports/menus.js +5 -0
- package/exports/page-runtime.js +5 -0
- package/exports/pages.js +1 -0
- package/exports/resolve.js +1 -0
- package/exports/ssr.js +1 -0
- package/exports/standalone-demo-url.js +10 -0
- package/exports/transform.js +1 -0
- package/exports/types/hydration.ts +26 -0
- package/exports/types/rocket.ts +598 -0
- package/exports/types.ts +71 -0
- package/exports/wds-plugin.js +1 -0
- package/package.json +192 -9
- package/src/PageData.js +244 -0
- package/src/RocketCodeBlock.js +516 -0
- package/src/RocketIcon.js +291 -0
- package/src/RocketJsDemo.js +397 -0
- package/src/RocketJsDemo.test-browser.js +228 -0
- package/src/RocketRequestDemo.js +439 -0
- package/src/RocketRequestDemo.test-browser.js +301 -0
- package/src/SocialPreviewPlayground.js +573 -0
- package/src/adapters/netlify.js +814 -0
- package/src/asyncMessage.js +21 -0
- package/src/cli/RocketBuild.js +545 -0
- package/src/cli/RocketCli.js +47 -0
- package/src/cli/RocketInit.js +323 -0
- package/src/cli/RocketStart.js +79 -0
- package/src/cli/cli.js +7 -0
- package/src/component-hydration.js +86 -0
- package/src/components/FeatureList.js +114 -0
- package/src/components/Footer.js +116 -0
- package/src/components/Header.js +122 -0
- package/src/components/RocketDrawer.js +193 -0
- package/src/components/RocketSocialLink.js +128 -0
- package/src/components/assets/discord.svg +7 -0
- package/src/components/assets/github.svg +4 -0
- package/src/components/assets/gitlab.svg +1 -0
- package/src/components/assets/info.txt +1 -0
- package/src/components/assets/license.svg +3 -0
- package/src/components/assets/npm.svg +5 -0
- package/src/components/assets/slack.svg +5 -0
- package/src/components/assets/telegram.svg +4 -0
- package/src/components/assets/twitter.svg +1 -0
- package/src/components.js +15 -0
- package/src/config.js +319 -0
- package/src/debounce.js +21 -0
- package/src/defaultSocialPreviewTemplate.js +118 -0
- package/src/development-page-module-loader.js +29 -0
- package/src/extractCode.js +41 -0
- package/src/hydration/evaluate.js +54 -0
- package/src/hydration/extractStrategies.js +91 -0
- package/src/hydration/hydrationLoader.js +330 -0
- package/src/icons.js +883 -0
- package/src/layouts/atlas/atlasDoc.css +877 -0
- package/src/layouts/atlas/atlasDocLayout.js +288 -0
- package/src/layouts/atlas/atlasHero.css +774 -0
- package/src/layouts/atlas/atlasHeroLayout.js +346 -0
- package/src/layouts/atlas/atlasNotFound.css +365 -0
- package/src/layouts/atlas/atlasNotFoundLayout.js +69 -0
- package/src/layouts/layout-helper.js +92 -0
- package/src/layouts/layout.js +62 -0
- package/src/loaded-page-module.js +97 -0
- package/src/main.js +55 -0
- package/src/markdownCompiler.js +303 -0
- package/src/markdownHook.js +148 -0
- package/src/menu.js +210 -0
- package/src/menus/MainMenu.js +58 -0
- package/src/menus/RocketMenu.js +191 -0
- package/src/menus/RocketNextPage.js +25 -0
- package/src/menus/RocketPreviousPage.js +29 -0
- package/src/menus/RocketToc.js +309 -0
- package/src/menus/pageNavigation.js +285 -0
- package/src/page-pagination.js +241 -0
- package/src/page-runtime.js +481 -0
- package/src/pages.js +537 -0
- package/src/publicAssets.js +336 -0
- package/src/requestDemoMetadata.js +97 -0
- package/src/resolve.js +15 -0
- package/src/siteDiscoverability.js +184 -0
- package/src/siteHeadMetadata.js +69 -0
- package/src/socialPreviewImages.js +482 -0
- package/src/socialPreviewTemplatePreview.js +352 -0
- package/src/ssr.js +14 -0
- package/src/standalone-demo-url.js +134 -0
- package/src/static-page-module-loader.js +29 -0
- package/src/transform.js +633 -0
- package/src/urlLifecycle.js +57 -0
- package/src/wds-plugin.js +302 -0
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_SOCIAL_PREVIEW_IMAGE_HEIGHT,
|
|
3
|
+
DEFAULT_SOCIAL_PREVIEW_IMAGE_WIDTH,
|
|
4
|
+
defaultSocialPreviewTemplate,
|
|
5
|
+
} from './defaultSocialPreviewTemplate.js';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_TITLE = 'Runtime Guide';
|
|
8
|
+
const DEFAULT_DESCRIPTION = 'Learn how Acme UI components load, render, and ship with Rocket.';
|
|
9
|
+
const DEFAULT_SITE_NAME = 'Acme Docs';
|
|
10
|
+
const DEFAULT_SITE_LANGUAGE = 'en';
|
|
11
|
+
const DEFAULT_CANONICAL_URL = 'https://docs.example.com/guides/runtime';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {object} SocialPreviewPage
|
|
15
|
+
* @property {string} path
|
|
16
|
+
* @property {string=} title
|
|
17
|
+
* @property {string=} description
|
|
18
|
+
* @property {string=} downloadFilename
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {object} SocialPreviewPlaygroundConfig
|
|
23
|
+
* @property {string} siteName
|
|
24
|
+
* @property {string} siteLanguage
|
|
25
|
+
* @property {string} canonicalUrl
|
|
26
|
+
* @property {string} defaultTitle
|
|
27
|
+
* @property {string} defaultDescription
|
|
28
|
+
* @property {string} selectedPath
|
|
29
|
+
* @property {'left' | 'top'} controlsPosition
|
|
30
|
+
* @property {string} templateUrl
|
|
31
|
+
* @property {string} imageUrl
|
|
32
|
+
* @property {string} workflowUrl
|
|
33
|
+
* @property {boolean} showPages
|
|
34
|
+
* @property {boolean} showDownload
|
|
35
|
+
* @property {boolean} syncHistory
|
|
36
|
+
* @property {SocialPreviewPage[]} pages
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {object} SocialPreviewPlaygroundState
|
|
41
|
+
* @property {string} selectedPath
|
|
42
|
+
* @property {string} title
|
|
43
|
+
* @property {string} description
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
export class SocialPreviewPlayground extends HTMLElement {
|
|
47
|
+
constructor() {
|
|
48
|
+
super();
|
|
49
|
+
/** @type {SocialPreviewPlaygroundConfig} */
|
|
50
|
+
this.config = {
|
|
51
|
+
siteName: DEFAULT_SITE_NAME,
|
|
52
|
+
siteLanguage: DEFAULT_SITE_LANGUAGE,
|
|
53
|
+
canonicalUrl: DEFAULT_CANONICAL_URL,
|
|
54
|
+
defaultTitle: DEFAULT_TITLE,
|
|
55
|
+
defaultDescription: DEFAULT_DESCRIPTION,
|
|
56
|
+
selectedPath: '',
|
|
57
|
+
controlsPosition: 'top',
|
|
58
|
+
templateUrl: '',
|
|
59
|
+
imageUrl: '',
|
|
60
|
+
workflowUrl: '',
|
|
61
|
+
showPages: false,
|
|
62
|
+
showDownload: false,
|
|
63
|
+
syncHistory: false,
|
|
64
|
+
pages: [],
|
|
65
|
+
};
|
|
66
|
+
/** @type {SocialPreviewPlaygroundState} */
|
|
67
|
+
this.state = {
|
|
68
|
+
selectedPath: '',
|
|
69
|
+
title: DEFAULT_TITLE,
|
|
70
|
+
description: DEFAULT_DESCRIPTION,
|
|
71
|
+
};
|
|
72
|
+
/** @type {ResizeObserver | undefined} */
|
|
73
|
+
this.resizeObserver = undefined;
|
|
74
|
+
/** @type {HTMLSelectElement | null} */
|
|
75
|
+
this.pageSelect = null;
|
|
76
|
+
/** @type {HTMLInputElement | null} */
|
|
77
|
+
this.titleInput = null;
|
|
78
|
+
/** @type {HTMLTextAreaElement | null} */
|
|
79
|
+
this.descriptionInput = null;
|
|
80
|
+
/** @type {HTMLIFrameElement | null} */
|
|
81
|
+
this.templateFrame = null;
|
|
82
|
+
/** @type {HTMLAnchorElement | null} */
|
|
83
|
+
this.pngLink = null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
connectedCallback() {
|
|
87
|
+
if (this.shadowRoot) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.config = this.readConfig();
|
|
91
|
+
this.state = this.initialState(this.config);
|
|
92
|
+
const shadowRoot = this.attachShadow({ mode: 'open' });
|
|
93
|
+
this.render();
|
|
94
|
+
this.connectControls();
|
|
95
|
+
this.updatePreviewResources();
|
|
96
|
+
this.resizePreviewFrame();
|
|
97
|
+
const frame = shadowRoot.querySelector('[data-social-preview-frame-shell]');
|
|
98
|
+
if (frame && 'ResizeObserver' in window) {
|
|
99
|
+
this.resizeObserver = new ResizeObserver(() => this.resizePreviewFrame());
|
|
100
|
+
this.resizeObserver.observe(frame);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
disconnectedCallback() {
|
|
105
|
+
this.resizeObserver?.disconnect();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** @returns {SocialPreviewPlaygroundConfig} */
|
|
109
|
+
readConfig() {
|
|
110
|
+
const pages = this.readPages();
|
|
111
|
+
const showPages = this.hasAttribute('show-pages') && pages.length > 0;
|
|
112
|
+
const imageUrl = this.getAttribute('image-url') ?? '';
|
|
113
|
+
return {
|
|
114
|
+
siteName: this.getAttribute('site-name') || DEFAULT_SITE_NAME,
|
|
115
|
+
siteLanguage: this.getAttribute('site-language') || DEFAULT_SITE_LANGUAGE,
|
|
116
|
+
canonicalUrl: this.getAttribute('canonical-url') || DEFAULT_CANONICAL_URL,
|
|
117
|
+
defaultTitle: this.getAttribute('preview-title') || DEFAULT_TITLE,
|
|
118
|
+
defaultDescription: this.getAttribute('preview-description') || DEFAULT_DESCRIPTION,
|
|
119
|
+
selectedPath: this.getAttribute('selected-path') || pages[0]?.path || '',
|
|
120
|
+
controlsPosition: this.getAttribute('controls-position') === 'left' ? 'left' : 'top',
|
|
121
|
+
templateUrl: this.getAttribute('template-url') ?? '',
|
|
122
|
+
imageUrl,
|
|
123
|
+
workflowUrl: this.getAttribute('workflow-url') ?? '',
|
|
124
|
+
showPages,
|
|
125
|
+
showDownload: this.hasAttribute('show-download') && Boolean(imageUrl),
|
|
126
|
+
syncHistory: this.hasAttribute('sync-history'),
|
|
127
|
+
pages,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** @returns {SocialPreviewPage[]} */
|
|
132
|
+
readPages() {
|
|
133
|
+
const pagesScript = this.querySelector('script[data-social-preview-pages]');
|
|
134
|
+
if (!pagesScript?.textContent) {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const pages = JSON.parse(pagesScript.textContent);
|
|
139
|
+
return Array.isArray(pages)
|
|
140
|
+
? pages
|
|
141
|
+
.filter(page => page && typeof page.path === 'string')
|
|
142
|
+
.map(page => ({
|
|
143
|
+
path: page.path,
|
|
144
|
+
title: typeof page.title === 'string' ? page.title : undefined,
|
|
145
|
+
description: typeof page.description === 'string' ? page.description : undefined,
|
|
146
|
+
downloadFilename:
|
|
147
|
+
typeof page.downloadFilename === 'string' ? page.downloadFilename : undefined,
|
|
148
|
+
}))
|
|
149
|
+
: [];
|
|
150
|
+
} catch {
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @param {SocialPreviewPlaygroundConfig} config
|
|
157
|
+
* @returns {SocialPreviewPlaygroundState}
|
|
158
|
+
*/
|
|
159
|
+
initialState(config) {
|
|
160
|
+
const page = config.pages.find(candidate => candidate.path === config.selectedPath);
|
|
161
|
+
return {
|
|
162
|
+
selectedPath: page?.path ?? config.selectedPath,
|
|
163
|
+
title: config.defaultTitle || page?.title || DEFAULT_TITLE,
|
|
164
|
+
description: config.defaultDescription || page?.description || DEFAULT_DESCRIPTION,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** @returns {SocialPreviewPage | undefined} */
|
|
169
|
+
selectedPage() {
|
|
170
|
+
return this.config.pages.find(page => page.path === this.state.selectedPath);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
render() {
|
|
174
|
+
const shadowRoot = this.shadowRoot;
|
|
175
|
+
if (!shadowRoot) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
shadowRoot.innerHTML = `
|
|
179
|
+
<style>
|
|
180
|
+
:host {
|
|
181
|
+
display: block;
|
|
182
|
+
margin-block: var(--wa-content-spacing, 1rem);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
* {
|
|
186
|
+
box-sizing: border-box;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.playground {
|
|
190
|
+
display: grid;
|
|
191
|
+
gap: 0.875rem;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.playground[data-controls-position='left'] {
|
|
195
|
+
gap: 1.5rem;
|
|
196
|
+
align-items: start;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.controls {
|
|
200
|
+
display: grid;
|
|
201
|
+
gap: 0.75rem;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.playground[data-controls-position='left'] .controls {
|
|
205
|
+
position: sticky;
|
|
206
|
+
top: 1.5rem;
|
|
207
|
+
gap: 1rem;
|
|
208
|
+
padding: 1rem;
|
|
209
|
+
border: 1px solid #d7dde7;
|
|
210
|
+
border-radius: 8px;
|
|
211
|
+
background: #ffffff;
|
|
212
|
+
box-shadow: 0 12px 30px rgb(15 23 42 / 8%);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.fields {
|
|
216
|
+
display: grid;
|
|
217
|
+
gap: 0.75rem;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.page-controls {
|
|
221
|
+
display: grid;
|
|
222
|
+
grid-template-columns: 2.75rem minmax(0, 1fr) 2.75rem;
|
|
223
|
+
gap: 0.5rem;
|
|
224
|
+
align-items: end;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.page-controls[hidden],
|
|
228
|
+
.download-link[hidden] {
|
|
229
|
+
display: none;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
label {
|
|
233
|
+
display: grid;
|
|
234
|
+
gap: 0.35rem;
|
|
235
|
+
min-width: 0;
|
|
236
|
+
color: #213142;
|
|
237
|
+
font-size: 0.92rem;
|
|
238
|
+
font-weight: 700;
|
|
239
|
+
line-height: 1.3;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
input,
|
|
243
|
+
textarea,
|
|
244
|
+
select,
|
|
245
|
+
button {
|
|
246
|
+
font: inherit;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
input,
|
|
250
|
+
textarea,
|
|
251
|
+
select {
|
|
252
|
+
width: 100%;
|
|
253
|
+
min-width: 0;
|
|
254
|
+
border: 1px solid #cbd5e1;
|
|
255
|
+
border-radius: 6px;
|
|
256
|
+
background: #ffffff;
|
|
257
|
+
color: #182230;
|
|
258
|
+
line-height: 1.4;
|
|
259
|
+
padding: 0.6rem 0.7rem;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
textarea {
|
|
263
|
+
min-height: 5.25rem;
|
|
264
|
+
resize: vertical;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
.playground[data-controls-position='left'] textarea {
|
|
268
|
+
min-height: 7.5rem;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
.actions {
|
|
272
|
+
display: flex;
|
|
273
|
+
flex-wrap: wrap;
|
|
274
|
+
gap: 0.75rem;
|
|
275
|
+
justify-content: flex-end;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
button,
|
|
279
|
+
.download-link {
|
|
280
|
+
min-height: 2.25rem;
|
|
281
|
+
border: 1px solid #cbd5e1;
|
|
282
|
+
border-radius: 6px;
|
|
283
|
+
background: #ffffff;
|
|
284
|
+
color: #213142;
|
|
285
|
+
cursor: pointer;
|
|
286
|
+
font-weight: 700;
|
|
287
|
+
padding: 0 0.75rem;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.download-link {
|
|
291
|
+
display: inline-flex;
|
|
292
|
+
align-items: center;
|
|
293
|
+
justify-content: center;
|
|
294
|
+
text-decoration: none;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
button:hover,
|
|
298
|
+
.download-link:hover {
|
|
299
|
+
border-color: #94a3b8;
|
|
300
|
+
background: #f8fafc;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.page-button {
|
|
304
|
+
width: 2.75rem;
|
|
305
|
+
padding: 0;
|
|
306
|
+
font-size: 1.35rem;
|
|
307
|
+
line-height: 1;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.preview-panel {
|
|
311
|
+
min-width: 0;
|
|
312
|
+
display: grid;
|
|
313
|
+
justify-items: center;
|
|
314
|
+
overflow: hidden;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.preview-frame {
|
|
318
|
+
width: min(100%, ${DEFAULT_SOCIAL_PREVIEW_IMAGE_WIDTH}px);
|
|
319
|
+
aspect-ratio: ${DEFAULT_SOCIAL_PREVIEW_IMAGE_WIDTH} / ${DEFAULT_SOCIAL_PREVIEW_IMAGE_HEIGHT};
|
|
320
|
+
overflow: hidden;
|
|
321
|
+
border: 1px solid #cbd5e1;
|
|
322
|
+
background: #020617;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
iframe {
|
|
326
|
+
display: block;
|
|
327
|
+
width: ${DEFAULT_SOCIAL_PREVIEW_IMAGE_WIDTH}px;
|
|
328
|
+
height: ${DEFAULT_SOCIAL_PREVIEW_IMAGE_HEIGHT}px;
|
|
329
|
+
border: 0;
|
|
330
|
+
transform: scale(var(--social-preview-scale, 1));
|
|
331
|
+
transform-origin: 0 0;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
@media (min-width: 720px) {
|
|
335
|
+
.playground:not([data-controls-position='left']) .fields {
|
|
336
|
+
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
@media (min-width: 960px) {
|
|
341
|
+
.playground[data-controls-position='left'] {
|
|
342
|
+
grid-template-columns: minmax(20rem, 26rem) minmax(0, 1fr);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
@media (max-width: 959px) {
|
|
347
|
+
.playground[data-controls-position='left'] .controls {
|
|
348
|
+
position: static;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
</style>
|
|
352
|
+
<section
|
|
353
|
+
class="playground"
|
|
354
|
+
aria-label="Default Social Preview Image playground"
|
|
355
|
+
data-controls-position="${this.config.controlsPosition}"
|
|
356
|
+
>
|
|
357
|
+
<div class="controls" data-social-preview-controls>
|
|
358
|
+
<div class="page-controls" ${this.config.showPages ? '' : 'hidden'}>
|
|
359
|
+
<button class="page-button" type="button" title="Previous Page" aria-label="Previous Page" data-social-preview-previous-page>←</button>
|
|
360
|
+
<label>
|
|
361
|
+
Page
|
|
362
|
+
<select name="page" data-social-preview-page-select></select>
|
|
363
|
+
</label>
|
|
364
|
+
<button class="page-button" type="button" title="Next Page" aria-label="Next Page" data-social-preview-next-page>→</button>
|
|
365
|
+
</div>
|
|
366
|
+
<div class="fields">
|
|
367
|
+
<label>
|
|
368
|
+
Title
|
|
369
|
+
<input data-social-preview-title-input />
|
|
370
|
+
</label>
|
|
371
|
+
<label>
|
|
372
|
+
Description
|
|
373
|
+
<textarea data-social-preview-description-input></textarea>
|
|
374
|
+
</label>
|
|
375
|
+
</div>
|
|
376
|
+
<div class="actions">
|
|
377
|
+
<button type="button" data-social-preview-reset>Reset</button>
|
|
378
|
+
<a class="download-link" data-social-preview-png-link ${this.config.showDownload ? '' : 'hidden'}>Download PNG</a>
|
|
379
|
+
</div>
|
|
380
|
+
</div>
|
|
381
|
+
<section class="preview-panel">
|
|
382
|
+
<div class="preview-frame" data-social-preview-frame-shell>
|
|
383
|
+
<iframe
|
|
384
|
+
title="Social Preview Template"
|
|
385
|
+
width="${DEFAULT_SOCIAL_PREVIEW_IMAGE_WIDTH}"
|
|
386
|
+
height="${DEFAULT_SOCIAL_PREVIEW_IMAGE_HEIGHT}"
|
|
387
|
+
scrolling="no"
|
|
388
|
+
data-social-preview-template-frame
|
|
389
|
+
></iframe>
|
|
390
|
+
</div>
|
|
391
|
+
</section>
|
|
392
|
+
</section>
|
|
393
|
+
`;
|
|
394
|
+
this.pageSelect = /** @type {HTMLSelectElement | null} */ (
|
|
395
|
+
shadowRoot.querySelector('[data-social-preview-page-select]')
|
|
396
|
+
);
|
|
397
|
+
this.titleInput = /** @type {HTMLInputElement | null} */ (
|
|
398
|
+
shadowRoot.querySelector('[data-social-preview-title-input]')
|
|
399
|
+
);
|
|
400
|
+
this.descriptionInput = /** @type {HTMLTextAreaElement | null} */ (
|
|
401
|
+
shadowRoot.querySelector('[data-social-preview-description-input]')
|
|
402
|
+
);
|
|
403
|
+
this.templateFrame = /** @type {HTMLIFrameElement | null} */ (
|
|
404
|
+
shadowRoot.querySelector('[data-social-preview-template-frame]')
|
|
405
|
+
);
|
|
406
|
+
this.pngLink = /** @type {HTMLAnchorElement | null} */ (
|
|
407
|
+
shadowRoot.querySelector('[data-social-preview-png-link]')
|
|
408
|
+
);
|
|
409
|
+
this.renderPageOptions();
|
|
410
|
+
this.syncControlsFromState();
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
connectControls() {
|
|
414
|
+
const shadowRoot = this.shadowRoot;
|
|
415
|
+
if (!shadowRoot) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const { pageSelect, titleInput, descriptionInput } = this;
|
|
419
|
+
pageSelect?.addEventListener('change', () => {
|
|
420
|
+
this.state.selectedPath = pageSelect.value;
|
|
421
|
+
this.syncTextFromSelectedPage();
|
|
422
|
+
this.updatePreviewResources();
|
|
423
|
+
});
|
|
424
|
+
titleInput?.addEventListener('input', () => {
|
|
425
|
+
this.state.title = titleInput.value;
|
|
426
|
+
this.updatePreviewResources();
|
|
427
|
+
});
|
|
428
|
+
descriptionInput?.addEventListener('input', () => {
|
|
429
|
+
this.state.description = descriptionInput.value;
|
|
430
|
+
this.updatePreviewResources();
|
|
431
|
+
});
|
|
432
|
+
shadowRoot
|
|
433
|
+
.querySelector('button[data-social-preview-previous-page]')
|
|
434
|
+
?.addEventListener('click', () => this.movePage(-1));
|
|
435
|
+
shadowRoot
|
|
436
|
+
.querySelector('button[data-social-preview-next-page]')
|
|
437
|
+
?.addEventListener('click', () => this.movePage(1));
|
|
438
|
+
shadowRoot
|
|
439
|
+
.querySelector('button[data-social-preview-reset]')
|
|
440
|
+
?.addEventListener('click', () => this.reset());
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
renderPageOptions() {
|
|
444
|
+
if (!(this.pageSelect instanceof HTMLSelectElement)) {
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
this.pageSelect.replaceChildren(
|
|
448
|
+
...this.config.pages.map(page => {
|
|
449
|
+
const option = document.createElement('option');
|
|
450
|
+
option.value = page.path;
|
|
451
|
+
option.textContent = `${page.path} - ${page.title || page.path}`;
|
|
452
|
+
option.dataset.title = page.title ?? '';
|
|
453
|
+
option.dataset.description = page.description ?? '';
|
|
454
|
+
option.dataset.downloadFilename = page.downloadFilename ?? 'social-preview.png';
|
|
455
|
+
option.selected = page.path === this.state.selectedPath;
|
|
456
|
+
return option;
|
|
457
|
+
}),
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
syncControlsFromState() {
|
|
462
|
+
if (this.titleInput instanceof HTMLInputElement) {
|
|
463
|
+
this.titleInput.value = this.state.title;
|
|
464
|
+
}
|
|
465
|
+
if (this.descriptionInput instanceof HTMLTextAreaElement) {
|
|
466
|
+
this.descriptionInput.value = this.state.description;
|
|
467
|
+
}
|
|
468
|
+
if (this.pageSelect instanceof HTMLSelectElement) {
|
|
469
|
+
this.pageSelect.value = this.state.selectedPath;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
syncTextFromSelectedPage() {
|
|
474
|
+
const page = this.selectedPage();
|
|
475
|
+
this.state.title = page?.title || this.config.defaultTitle;
|
|
476
|
+
this.state.description = page?.description || this.config.defaultDescription;
|
|
477
|
+
this.syncControlsFromState();
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** @param {number} direction */
|
|
481
|
+
movePage(direction) {
|
|
482
|
+
if (!(this.pageSelect instanceof HTMLSelectElement) || this.pageSelect.options.length === 0) {
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
this.pageSelect.selectedIndex =
|
|
486
|
+
(this.pageSelect.selectedIndex + direction + this.pageSelect.options.length) %
|
|
487
|
+
this.pageSelect.options.length;
|
|
488
|
+
this.state.selectedPath = this.pageSelect.value;
|
|
489
|
+
this.syncTextFromSelectedPage();
|
|
490
|
+
this.updatePreviewResources();
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
reset() {
|
|
494
|
+
if (this.config.showPages) {
|
|
495
|
+
this.syncTextFromSelectedPage();
|
|
496
|
+
} else {
|
|
497
|
+
this.state.title = this.config.defaultTitle;
|
|
498
|
+
this.state.description = this.config.defaultDescription;
|
|
499
|
+
this.syncControlsFromState();
|
|
500
|
+
}
|
|
501
|
+
this.updatePreviewResources();
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
updatePreviewResources() {
|
|
505
|
+
if (!(this.templateFrame instanceof HTMLIFrameElement)) {
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
if (this.config.templateUrl) {
|
|
509
|
+
this.templateFrame.src = this.socialPreviewResourcePath(this.config.templateUrl);
|
|
510
|
+
} else {
|
|
511
|
+
this.templateFrame.srcdoc = this.previewHtml();
|
|
512
|
+
}
|
|
513
|
+
if (this.pngLink instanceof HTMLAnchorElement && this.config.imageUrl) {
|
|
514
|
+
this.pngLink.href = this.socialPreviewResourcePath(this.config.imageUrl);
|
|
515
|
+
this.pngLink.download = this.selectedPage()?.downloadFilename ?? 'social-preview.png';
|
|
516
|
+
}
|
|
517
|
+
if (this.config.syncHistory && this.config.workflowUrl) {
|
|
518
|
+
window.history.replaceState(
|
|
519
|
+
null,
|
|
520
|
+
'',
|
|
521
|
+
this.socialPreviewResourcePath(this.config.workflowUrl),
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** @param {string} pathname */
|
|
527
|
+
socialPreviewResourcePath(pathname) {
|
|
528
|
+
const params = new URLSearchParams();
|
|
529
|
+
if (this.state.selectedPath) {
|
|
530
|
+
params.set('page', this.state.selectedPath);
|
|
531
|
+
}
|
|
532
|
+
const selectedPage = this.selectedPage();
|
|
533
|
+
if (
|
|
534
|
+
this.state.title &&
|
|
535
|
+
this.state.title !== (selectedPage?.title ?? this.config.defaultTitle)
|
|
536
|
+
) {
|
|
537
|
+
params.set('title', this.state.title);
|
|
538
|
+
}
|
|
539
|
+
if (
|
|
540
|
+
this.state.description &&
|
|
541
|
+
this.state.description !== (selectedPage?.description ?? this.config.defaultDescription)
|
|
542
|
+
) {
|
|
543
|
+
params.set('description', this.state.description);
|
|
544
|
+
}
|
|
545
|
+
const query = params.toString();
|
|
546
|
+
return query ? `${pathname}?${query}` : pathname;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
previewHtml() {
|
|
550
|
+
return defaultSocialPreviewTemplate({
|
|
551
|
+
site: {
|
|
552
|
+
language: this.config.siteLanguage,
|
|
553
|
+
name: this.config.siteName,
|
|
554
|
+
},
|
|
555
|
+
page: {
|
|
556
|
+
title: this.state.title || ' ',
|
|
557
|
+
description: this.state.description || ' ',
|
|
558
|
+
canonicalUrl: this.config.canonicalUrl,
|
|
559
|
+
},
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
resizePreviewFrame() {
|
|
564
|
+
const frame = this.shadowRoot?.querySelector('[data-social-preview-frame-shell]');
|
|
565
|
+
if (!(frame instanceof HTMLElement)) {
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
frame.style.setProperty(
|
|
569
|
+
'--social-preview-scale',
|
|
570
|
+
String(frame.clientWidth / DEFAULT_SOCIAL_PREVIEW_IMAGE_WIDTH),
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
}
|