@getflip/swirl-components 0.114.0 → 0.116.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/components.json +87 -19
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/swirl-components.cjs.js +1 -1
- package/dist/cjs/swirl-file-viewer_7.cjs.entry.js +5 -2
- package/dist/cjs/swirl-pdf-reader.cjs.entry.js +6 -1
- package/dist/cjs/swirl-theme-provider.cjs.entry.js +42 -285
- package/dist/collection/assets/pdfjs/pdf.worker.min.js +1 -1
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/swirl-file-viewer/swirl-file-viewer.js +19 -1
- package/dist/collection/components/swirl-file-viewer/viewers/swirl-file-viewer-pdf/swirl-file-viewer-pdf.js +21 -1
- package/dist/collection/components/swirl-pdf-reader/swirl-pdf-reader.js +54 -1
- package/dist/collection/components/swirl-theme-provider/swirl-theme-provider.js +72 -99
- package/dist/collection/components/swirl-theme-provider/swirl-theme-provider.spec.js +67 -18
- package/dist/collection/components/swirl-theme-provider/swirl-theme-provider.stories.js +371 -17
- package/dist/collection/components/swirl-theme-provider/swirl-theme-provider.types.js +1 -0
- package/dist/components/assets/pdfjs/pdf.worker.min.js +1 -1
- package/dist/components/swirl-file-viewer-pdf2.js +4 -1
- package/dist/components/swirl-file-viewer2.js +3 -1
- package/dist/components/swirl-pdf-reader.js +8 -2
- package/dist/components/swirl-theme-provider.js +46 -289
- package/dist/esm/loader.js +1 -1
- package/dist/esm/swirl-components.js +1 -1
- package/dist/esm/swirl-file-viewer_7.entry.js +5 -2
- package/dist/esm/swirl-pdf-reader.entry.js +7 -2
- package/dist/esm/swirl-theme-provider.entry.js +42 -285
- package/dist/swirl-components/p-353eab4c.entry.js +1 -0
- package/dist/swirl-components/{p-05d56f14.entry.js → p-4368ba9d.entry.js} +2 -2
- package/dist/swirl-components/p-bceafa56.entry.js +1 -0
- package/dist/swirl-components/swirl-components.esm.js +1 -1
- package/dist/types/components/swirl-file-viewer/swirl-file-viewer.d.ts +1 -0
- package/dist/types/components/swirl-file-viewer/viewers/swirl-file-viewer-pdf/swirl-file-viewer-pdf.d.ts +6 -0
- package/dist/types/components/swirl-pdf-reader/swirl-pdf-reader.d.ts +4 -0
- package/dist/types/components/swirl-theme-provider/swirl-theme-provider.d.ts +15 -34
- package/dist/types/components/swirl-theme-provider/swirl-theme-provider.types.d.ts +45 -0
- package/dist/types/components.d.ts +23 -11
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/vscode-data.json +12 -0
- package/dist/swirl-components/p-1a4c6557.entry.js +0 -1
- package/dist/swirl-components/p-af636e9c.entry.js +0 -1
|
@@ -29508,7 +29508,7 @@ const pdf$1 = /*@__PURE__*/getDefaultExportFromCjs(pdf);
|
|
|
29508
29508
|
|
|
29509
29509
|
const swirlFileViewerPdfCss = ":host{position:relative;display:inline-flex;width:100%;height:100%}:host(.file-viewer-pdf--view-mode-side-by-side) .file-viewer-pdf__pages{display:grid;grid-template-columns:repeat(2, 1fr);grid-row-gap:var(--s-space-8);grid-column-gap:var(--s-space-8);grid-auto-rows:auto}:host(.file-viewer-pdf--view-mode-side-by-side) .file-viewer-pdf__page{margin:0}:host(.file-viewer-pdf--view-mode-side-by-side) .file-viewer-pdf__page:nth-child(odd){justify-self:end}:host(.file-viewer-pdf--view-mode-side-by-side) .file-viewer-pdf__page:nth-child(even){justify-self:start}:host *{box-sizing:border-box}.file-viewer-pdf__pages{overflow:auto;width:100%;height:100%}@media (min-width: 768px){.file-viewer-pdf__pages{padding:var(--s-space-16)}}.file-viewer-pdf__page{position:relative;margin-right:auto;margin-left:auto;border-bottom:var(--s-border-width-default) solid var(--s-border-default);background-color:#fff}@media (min-width: 768px){.file-viewer-pdf__page{border:var(--s-border-width-default) solid var(--s-border-default)}.file-viewer-pdf__page:not(:last-of-type){margin-bottom:var(--s-space-8)}}.file-viewer-pdf__page-spinner{position:absolute;top:50%;left:50%;transform:translate3d(-50%, -50%, 0)}.file-viewer-pdf__canvas{display:flex;width:100%;height:100%;margin-right:auto;margin-left:auto}.file-viewer-pdf__text-container{position:absolute;overflow:hidden;line-height:1;text-align:initial;-webkit-user-select:none;-moz-user-select:none;user-select:none;inset:0;-webkit-text-size-adjust:none;-moz-text-size-adjust:none;text-size-adjust:none;forced-color-adjust:none}.file-viewer-pdf__text-container>*{position:absolute;color:transparent;white-space:pre;cursor:text;transform-origin:0% 0%}.file-viewer-pdf__text-container>*.markedContent{top:0;height:0}.file-viewer-pdf__text-container>*.highlight{margin:-1px;padding:1px;border-radius:4px;background-color:rgba(180, 0, 170, 1)}.file-viewer-pdf__text-container>*.highlight.appended{position:initial}.file-viewer-pdf__text-container>*.highlight.begin{border-radius:4px 0 0 4px}.file-viewer-pdf__text-container>*.highlight.end{border-radius:0 4px 4px 0}.file-viewer-pdf__text-container>*.highlight.middle{border-radius:0}.file-viewer-pdf__text-container>*.highlight.selected{background-color:rgba(0, 100, 0, 1)}.file-viewer-pdf__text-container>*.endOfContent{position:absolute;z-index:-1;top:100%;right:0;bottom:0;left:0;display:block;cursor:default;-webkit-user-select:none;-moz-user-select:none;user-select:none}.file-viewer-pdf__text-container>*.endOfContent.active{top:0}.file-viewer-pdf__text-container>br::-moz-selection{background:transparent}.file-viewer-pdf__text-container>br::selection{background:transparent}@media (min-width: 768px){.file-viewer-pdf__text-container{-webkit-user-select:auto;-moz-user-select:auto;user-select:auto}}.file-viewer-pdf__spinner{position:absolute;display:flex;justify-content:center;align-items:center;background-color:rgba(0, 0, 0, 0.2);inset:0}.file-viewer-pdf__error{position:absolute;top:50%;left:50%;transform:translate3d(-50%, -50%, 0)}.file-viewer-pdf__pagination{position:absolute;bottom:var(--s-space-16);left:50%;padding:var(--s-space-4) var(--s-space-12);border-radius:var(--s-border-radius-base);color:var(--s-text-on-image);background-color:rgba(0, 0, 0, 0.6);font-weight:var(--s-font-weight-medium);line-height:var(--s-line-height-base);transform:translateX(-50%);pointer-events:none}@media (min-width: 992px) and (max-width: 1439px) and (hover: hover),(min-width: 1440px){.file-viewer-pdf__pagination{font-size:var(--s-font-size-sm);line-height:var(--s-line-height-sm)}}";
|
|
29510
29510
|
|
|
29511
|
-
pdf
|
|
29511
|
+
window.pdf = pdf$1;
|
|
29512
29512
|
const SwirlFileViewerPdf = /*@__PURE__*/ proxyCustomElement(class SwirlFileViewerPdf extends HTMLElement$1 {
|
|
29513
29513
|
constructor() {
|
|
29514
29514
|
super();
|
|
@@ -29544,6 +29544,7 @@ const SwirlFileViewerPdf = /*@__PURE__*/ proxyCustomElement(class SwirlFileViewe
|
|
|
29544
29544
|
this.file = undefined;
|
|
29545
29545
|
this.singlePageMode = undefined;
|
|
29546
29546
|
this.viewMode = "single";
|
|
29547
|
+
this.workerSrc = "/pdfjs/pdf.worker.min.js";
|
|
29547
29548
|
this.zoom = 1;
|
|
29548
29549
|
this.doc = undefined;
|
|
29549
29550
|
this.error = undefined;
|
|
@@ -29554,6 +29555,7 @@ const SwirlFileViewerPdf = /*@__PURE__*/ proxyCustomElement(class SwirlFileViewe
|
|
|
29554
29555
|
this.visiblePages = [];
|
|
29555
29556
|
}
|
|
29556
29557
|
async componentWillLoad() {
|
|
29558
|
+
window.pdf.GlobalWorkerOptions.workerSrc = this.workerSrc;
|
|
29557
29559
|
await this.getPages();
|
|
29558
29560
|
}
|
|
29559
29561
|
async componentDidLoad() {
|
|
@@ -29842,6 +29844,7 @@ const SwirlFileViewerPdf = /*@__PURE__*/ proxyCustomElement(class SwirlFileViewe
|
|
|
29842
29844
|
"file": [1],
|
|
29843
29845
|
"singlePageMode": [4, "single-page-mode"],
|
|
29844
29846
|
"viewMode": [1, "view-mode"],
|
|
29847
|
+
"workerSrc": [1, "worker-src"],
|
|
29845
29848
|
"zoom": [8],
|
|
29846
29849
|
"doc": [32],
|
|
29847
29850
|
"error": [32],
|
|
@@ -37,6 +37,7 @@ const SwirlFileViewer = /*@__PURE__*/ proxyCustomElement(class SwirlFileViewer e
|
|
|
37
37
|
this.description = undefined;
|
|
38
38
|
this.errorMessage = "File could not be loaded.";
|
|
39
39
|
this.file = undefined;
|
|
40
|
+
this.pdfWorkerSrc = undefined;
|
|
40
41
|
this.thumbnailUrl = undefined;
|
|
41
42
|
this.type = undefined;
|
|
42
43
|
this.typeUnsupportedMessage = "File type is not supported.";
|
|
@@ -67,7 +68,7 @@ const SwirlFileViewer = /*@__PURE__*/ proxyCustomElement(class SwirlFileViewer e
|
|
|
67
68
|
this.type !== "text/plain" &&
|
|
68
69
|
this.type !== "text/csv" &&
|
|
69
70
|
this.type !== "application/pdf");
|
|
70
|
-
return (h(Host, null, h("div", { class: "file-viewer" }, this.type && this.active && (h("div", { class: "file-viewer__file" }, this.type.startsWith("image/") && (h("swirl-file-viewer-image", { description: this.description, errorMessage: this.errorMessage, file: this.file, ref: (el) => (this.viewer = el) })), this.type === "text/plain" && (h("swirl-file-viewer-text", { errorMessage: this.errorMessage, file: this.file, ref: (el) => (this.viewer = el) })), this.type === "text/csv" && (h("swirl-file-viewer-csv", { errorMessage: this.errorMessage, file: this.file, ref: (el) => (this.viewer = el) })), this.type === "application/pdf" && (h("swirl-file-viewer-pdf", { errorMessage: this.errorMessage, file: this.file, onActivate: this.onActivate, onVisiblePagesChange: this.onVisiblePagesChange, ref: (el) => (this.viewer = el), viewMode: this.viewMode, zoom: this.zoom })), this.type.startsWith("video/") && (h("swirl-file-viewer-video", { autoplay: this.autoplay, file: this.file, ref: (el) => (this.viewer = el), type: this.type })), this.type.startsWith("audio/") && (h("swirl-file-viewer-audio", { autoplay: this.autoplay, file: this.file, ref: (el) => (this.viewer = el), type: this.type })), unsupportedType && (h("swirl-inline-error", { message: this.typeUnsupportedMessage })))))));
|
|
71
|
+
return (h(Host, null, h("div", { class: "file-viewer" }, this.type && this.active && (h("div", { class: "file-viewer__file" }, this.type.startsWith("image/") && (h("swirl-file-viewer-image", { description: this.description, errorMessage: this.errorMessage, file: this.file, ref: (el) => (this.viewer = el) })), this.type === "text/plain" && (h("swirl-file-viewer-text", { errorMessage: this.errorMessage, file: this.file, ref: (el) => (this.viewer = el) })), this.type === "text/csv" && (h("swirl-file-viewer-csv", { errorMessage: this.errorMessage, file: this.file, ref: (el) => (this.viewer = el) })), this.type === "application/pdf" && (h("swirl-file-viewer-pdf", { errorMessage: this.errorMessage, file: this.file, onActivate: this.onActivate, onVisiblePagesChange: this.onVisiblePagesChange, ref: (el) => (this.viewer = el), viewMode: this.viewMode, workerSrc: this.pdfWorkerSrc, zoom: this.zoom })), this.type.startsWith("video/") && (h("swirl-file-viewer-video", { autoplay: this.autoplay, file: this.file, ref: (el) => (this.viewer = el), type: this.type })), this.type.startsWith("audio/") && (h("swirl-file-viewer-audio", { autoplay: this.autoplay, file: this.file, ref: (el) => (this.viewer = el), type: this.type })), unsupportedType && (h("swirl-inline-error", { message: this.typeUnsupportedMessage })))))));
|
|
71
72
|
}
|
|
72
73
|
static get style() { return swirlFileViewerCss; }
|
|
73
74
|
}, [1, "swirl-file-viewer", {
|
|
@@ -76,6 +77,7 @@ const SwirlFileViewer = /*@__PURE__*/ proxyCustomElement(class SwirlFileViewer e
|
|
|
76
77
|
"description": [1],
|
|
77
78
|
"errorMessage": [1, "error-message"],
|
|
78
79
|
"file": [1],
|
|
80
|
+
"pdfWorkerSrc": [1, "pdf-worker-src"],
|
|
79
81
|
"thumbnailUrl": [1, "thumbnail-url"],
|
|
80
82
|
"type": [1],
|
|
81
83
|
"typeUnsupportedMessage": [1, "type-unsupported-message"],
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { proxyCustomElement, HTMLElement, h, Host } from '@stencil/core/internal/client';
|
|
1
|
+
import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
|
|
2
2
|
import { A as A11yDialog } from './a11y-dialog.esm.js';
|
|
3
3
|
import { d as disableBodyScroll, e as enableBodyScroll } from './bodyScrollLock.esm.js';
|
|
4
4
|
import { c as classnames } from './index2.js';
|
|
@@ -37,6 +37,8 @@ const SwirlPdfReader$1 = /*@__PURE__*/ proxyCustomElement(class SwirlPdfReader e
|
|
|
37
37
|
super();
|
|
38
38
|
this.__registerHost();
|
|
39
39
|
this.__attachShadow();
|
|
40
|
+
this.modalClose = createEvent(this, "modalClose", 7);
|
|
41
|
+
this.modalOpen = createEvent(this, "modalOpen", 7);
|
|
40
42
|
this.desktopZoomSteps = [0.5, 0.75, 1, 1.25, 1.5, 2, 3, 4];
|
|
41
43
|
this.mobileZoomSteps = [0.5, 0.75, 1, 1.25, 1.5];
|
|
42
44
|
this.toggleViewMode = () => {
|
|
@@ -109,6 +111,7 @@ const SwirlPdfReader$1 = /*@__PURE__*/ proxyCustomElement(class SwirlPdfReader e
|
|
|
109
111
|
this.label = undefined;
|
|
110
112
|
this.menuLabel = "File menu";
|
|
111
113
|
this.menuTriggerLabel = "Open file menu";
|
|
114
|
+
this.pdfWorkerSrc = undefined;
|
|
112
115
|
this.printButtonLabel = "Print PDF";
|
|
113
116
|
this.sideBySideButtonLabel = "Toggle side by side view";
|
|
114
117
|
this.thumbnailButtonLabel = "Scroll to page";
|
|
@@ -151,6 +154,7 @@ const SwirlPdfReader$1 = /*@__PURE__*/ proxyCustomElement(class SwirlPdfReader e
|
|
|
151
154
|
async open() {
|
|
152
155
|
this.modal.show();
|
|
153
156
|
this.active = true;
|
|
157
|
+
this.modalOpen.emit();
|
|
154
158
|
}
|
|
155
159
|
/**
|
|
156
160
|
* Close the reader.
|
|
@@ -165,6 +169,7 @@ const SwirlPdfReader$1 = /*@__PURE__*/ proxyCustomElement(class SwirlPdfReader e
|
|
|
165
169
|
this.modal.hide();
|
|
166
170
|
this.closing = false;
|
|
167
171
|
this.active = false;
|
|
172
|
+
this.modalClose.emit();
|
|
168
173
|
}, 150);
|
|
169
174
|
}
|
|
170
175
|
lockBodyScroll() {
|
|
@@ -197,7 +202,7 @@ const SwirlPdfReader$1 = /*@__PURE__*/ proxyCustomElement(class SwirlPdfReader e
|
|
|
197
202
|
"pdf-reader__thumbnail--active": this.visiblePages[0] === index + 1,
|
|
198
203
|
});
|
|
199
204
|
return (h("button", { "aria-label": `${this.thumbnailButtonLabel} ${index + 1}`, class: thumbnailClassName, onClick: this.onThumbnailClick(index), type: "button" }, h("img", { src: thumbnail.toDataURL("image/png"), alt: "" })));
|
|
200
|
-
})), h("swirl-file-viewer", { active: this.active, class: "pdf-reader__viewer", file: this.file, onActivate: this.onActivate, onVisiblePagesChange: this.onVisiblePagesChange, ref: (el) => (this.viewer = el), type: "application/pdf", viewMode: this.viewMode, zoom: this.zoom }), h("div", { class: "pdf-reader__mobile-zoom-controls" }, h("button", { "aria-label": this.autoZoomLabel, class: "pdf-reader__mobile-zoom-button", onClick: this.onZoomAutoButtonClick, type: "button" }, this.zoom === "auto" ? (h("swirl-icon-fullscreen-exit", null)) : (h("swirl-icon-fullscreen", null))), h("button", { "aria-label": this.zoomInButtonLabel, class: "pdf-reader__mobile-zoom-button", disabled: this.zoom === this.zoomSteps[this.zoomSteps.length - 1], onClick: this.onZoomInButtonClick, type: "button" }, h("swirl-icon-add", null)), h("button", { "aria-label": this.zoomOutButtonLabel, class: "pdf-reader__mobile-zoom-button", disabled: this.zoom === this.zoomSteps[0], onClick: this.onZoomOutButtonClick, type: "button" }, h("swirl-icon-remove", null))))), h("swirl-popover", { animation: "scale-in-y", disableScrollLock: true, id: "menu", label: this.menuLabel, placement: "bottom-end", ref: (el) => (this.menu = el) }, h("swirl-stack", null, h("div", { class: "pdf-reader__meta" }, h("div", { class: "pdf-reader__file-icon" }, h("svg", { fill: "none", height: "36", viewBox: "0 0 24 36", width: "24" }, h("path", { d: "M7.01755 21.6V15.192H8.39455C8.64655 15.192 8.86855 15.225 9.06055 15.291C9.25255 15.357 9.42655 15.474 9.58255 15.642C9.73855 15.81 9.84655 16.008 9.90655 16.236C9.96655 16.458 9.99655 16.761 9.99655 17.145C9.99655 17.433 9.97855 17.676 9.94255 17.874C9.91255 18.072 9.84355 18.258 9.73555 18.432C9.60955 18.642 9.44155 18.807 9.23155 18.927C9.02155 19.041 8.74555 19.098 8.40355 19.098H7.93555V21.6H7.01755ZM7.93555 16.056V18.234H8.37655C8.56255 18.234 8.70655 18.207 8.80855 18.153C8.91055 18.099 8.98555 18.024 9.03355 17.928C9.08155 17.838 9.10855 17.727 9.11455 17.595C9.12655 17.463 9.13255 17.316 9.13255 17.154C9.13255 17.004 9.12955 16.863 9.12355 16.731C9.11755 16.593 9.09055 16.473 9.04255 16.371C8.99455 16.269 8.92255 16.191 8.82655 16.137C8.73055 16.083 8.59255 16.056 8.41255 16.056H7.93555Z", fill: "white" }), h("path", { d: "M10.6826 21.6V15.192H12.0416C12.5696 15.192 12.9686 15.336 13.2386 15.624C13.5146 15.912 13.6526 16.32 13.6526 16.848V19.845C13.6526 20.445 13.5056 20.889 13.2116 21.177C12.9236 21.459 12.5066 21.6 11.9606 21.6H10.6826ZM11.6006 16.056V20.736H12.0236C12.2816 20.736 12.4646 20.673 12.5726 20.547C12.6806 20.415 12.7346 20.211 12.7346 19.935V16.848C12.7346 16.596 12.6836 16.401 12.5816 16.263C12.4796 16.125 12.2936 16.056 12.0236 16.056H11.6006Z", fill: "white" }), h("path", { d: "M14.5146 21.6V15.192H17.2506V16.056H15.4326V18H17.0166V18.864H15.4326V21.6H14.5146Z", fill: "white" }), h("path", { d: "M3.59961 9.00001C3.59961 8.0059 4.4055 7.20001 5.39961 7.20001H14.854C15.3314 7.20001 15.7893 7.38965 16.1268 7.72722L19.8724 11.4728C20.21 11.8104 20.3996 12.2682 20.3996 12.7456V27C20.3996 27.9941 19.5937 28.8 18.5996 28.8H5.39961C4.4055 28.8 3.59961 27.9941 3.59961 27V9.00001Z", fill: "#FF574D" }), h("path", { d: "M15.5996 7.36166V10.2C15.5996 11.1941 16.4055 12 17.3996 12H20.2379C20.3237 12.1884 20.3768 12.3913 20.3937 12.6H17.3996C16.0785 12.6 15.0067 11.5325 14.9996 10.213L14.9996 7.20587C15.2083 7.2228 15.4112 7.27593 15.5996 7.36166Z", fill: "white" }), h("path", { d: "M7.01755 21.6V15.192H8.39455C8.64655 15.192 8.86855 15.225 9.06055 15.291C9.25255 15.357 9.42655 15.474 9.58255 15.642C9.73855 15.81 9.84655 16.008 9.90655 16.236C9.96655 16.458 9.99655 16.761 9.99655 17.145C9.99655 17.433 9.97855 17.676 9.94255 17.874C9.91255 18.072 9.84355 18.258 9.73555 18.432C9.60955 18.642 9.44155 18.807 9.23155 18.927C9.02155 19.041 8.74555 19.098 8.40355 19.098H7.93555V21.6H7.01755ZM7.93555 16.056V18.234H8.37655C8.56255 18.234 8.70655 18.207 8.80855 18.153C8.91055 18.099 8.98555 18.024 9.03355 17.928C9.08155 17.838 9.10855 17.727 9.11455 17.595C9.12655 17.463 9.13255 17.316 9.13255 17.154C9.13255 17.004 9.12955 16.863 9.12355 16.731C9.11755 16.593 9.09055 16.473 9.04255 16.371C8.99455 16.269 8.92255 16.191 8.82655 16.137C8.73055 16.083 8.59255 16.056 8.41255 16.056H7.93555Z", fill: "white" }), h("path", { d: "M10.6826 21.6V15.192H12.0416C12.5696 15.192 12.9686 15.336 13.2386 15.624C13.5146 15.912 13.6526 16.32 13.6526 16.848V19.845C13.6526 20.445 13.5056 20.889 13.2116 21.177C12.9236 21.459 12.5066 21.6 11.9606 21.6H10.6826ZM11.6006 16.056V20.736H12.0236C12.2816 20.736 12.4646 20.673 12.5726 20.547C12.6806 20.415 12.7346 20.211 12.7346 19.935V16.848C12.7346 16.596 12.6836 16.401 12.5816 16.263C12.4796 16.125 12.2936 16.056 12.0236 16.056H11.6006Z", fill: "white" }), h("path", { d: "M14.5146 21.6V15.192H17.2506V16.056H15.4326V18H17.0166V18.864H15.4326V21.6H14.5146Z", fill: "white" }))), h("div", { class: "pdf-reader__file-info" }, h("swirl-text", { truncate: true, weight: "semibold" }, this.label), h("swirl-text", { color: "subdued", size: "sm", truncate: true }, this.fileTypeLabel))), h("swirl-separator", null), h("swirl-action-list", null, h("swirl-action-list-item", { class: "pdf-reader__print-button", icon: "<swirl-icon-print></swirl-icon-print>", label: this.printButtonLabel, onClick: this.onPrintButtonClick }), h("swirl-action-list-item", { class: "pdf-reader__download-button", disabled: this.downloading, icon: !this.downloading
|
|
205
|
+
})), h("swirl-file-viewer", { active: this.active, class: "pdf-reader__viewer", file: this.file, onActivate: this.onActivate, onVisiblePagesChange: this.onVisiblePagesChange, pdfWorkerSrc: this.pdfWorkerSrc, ref: (el) => (this.viewer = el), type: "application/pdf", viewMode: this.viewMode, zoom: this.zoom }), h("div", { class: "pdf-reader__mobile-zoom-controls" }, h("button", { "aria-label": this.autoZoomLabel, class: "pdf-reader__mobile-zoom-button", onClick: this.onZoomAutoButtonClick, type: "button" }, this.zoom === "auto" ? (h("swirl-icon-fullscreen-exit", null)) : (h("swirl-icon-fullscreen", null))), h("button", { "aria-label": this.zoomInButtonLabel, class: "pdf-reader__mobile-zoom-button", disabled: this.zoom === this.zoomSteps[this.zoomSteps.length - 1], onClick: this.onZoomInButtonClick, type: "button" }, h("swirl-icon-add", null)), h("button", { "aria-label": this.zoomOutButtonLabel, class: "pdf-reader__mobile-zoom-button", disabled: this.zoom === this.zoomSteps[0], onClick: this.onZoomOutButtonClick, type: "button" }, h("swirl-icon-remove", null))))), h("swirl-popover", { animation: "scale-in-y", disableScrollLock: true, id: "menu", label: this.menuLabel, placement: "bottom-end", ref: (el) => (this.menu = el) }, h("swirl-stack", null, h("div", { class: "pdf-reader__meta" }, h("div", { class: "pdf-reader__file-icon" }, h("svg", { fill: "none", height: "36", viewBox: "0 0 24 36", width: "24" }, h("path", { d: "M7.01755 21.6V15.192H8.39455C8.64655 15.192 8.86855 15.225 9.06055 15.291C9.25255 15.357 9.42655 15.474 9.58255 15.642C9.73855 15.81 9.84655 16.008 9.90655 16.236C9.96655 16.458 9.99655 16.761 9.99655 17.145C9.99655 17.433 9.97855 17.676 9.94255 17.874C9.91255 18.072 9.84355 18.258 9.73555 18.432C9.60955 18.642 9.44155 18.807 9.23155 18.927C9.02155 19.041 8.74555 19.098 8.40355 19.098H7.93555V21.6H7.01755ZM7.93555 16.056V18.234H8.37655C8.56255 18.234 8.70655 18.207 8.80855 18.153C8.91055 18.099 8.98555 18.024 9.03355 17.928C9.08155 17.838 9.10855 17.727 9.11455 17.595C9.12655 17.463 9.13255 17.316 9.13255 17.154C9.13255 17.004 9.12955 16.863 9.12355 16.731C9.11755 16.593 9.09055 16.473 9.04255 16.371C8.99455 16.269 8.92255 16.191 8.82655 16.137C8.73055 16.083 8.59255 16.056 8.41255 16.056H7.93555Z", fill: "white" }), h("path", { d: "M10.6826 21.6V15.192H12.0416C12.5696 15.192 12.9686 15.336 13.2386 15.624C13.5146 15.912 13.6526 16.32 13.6526 16.848V19.845C13.6526 20.445 13.5056 20.889 13.2116 21.177C12.9236 21.459 12.5066 21.6 11.9606 21.6H10.6826ZM11.6006 16.056V20.736H12.0236C12.2816 20.736 12.4646 20.673 12.5726 20.547C12.6806 20.415 12.7346 20.211 12.7346 19.935V16.848C12.7346 16.596 12.6836 16.401 12.5816 16.263C12.4796 16.125 12.2936 16.056 12.0236 16.056H11.6006Z", fill: "white" }), h("path", { d: "M14.5146 21.6V15.192H17.2506V16.056H15.4326V18H17.0166V18.864H15.4326V21.6H14.5146Z", fill: "white" }), h("path", { d: "M3.59961 9.00001C3.59961 8.0059 4.4055 7.20001 5.39961 7.20001H14.854C15.3314 7.20001 15.7893 7.38965 16.1268 7.72722L19.8724 11.4728C20.21 11.8104 20.3996 12.2682 20.3996 12.7456V27C20.3996 27.9941 19.5937 28.8 18.5996 28.8H5.39961C4.4055 28.8 3.59961 27.9941 3.59961 27V9.00001Z", fill: "#FF574D" }), h("path", { d: "M15.5996 7.36166V10.2C15.5996 11.1941 16.4055 12 17.3996 12H20.2379C20.3237 12.1884 20.3768 12.3913 20.3937 12.6H17.3996C16.0785 12.6 15.0067 11.5325 14.9996 10.213L14.9996 7.20587C15.2083 7.2228 15.4112 7.27593 15.5996 7.36166Z", fill: "white" }), h("path", { d: "M7.01755 21.6V15.192H8.39455C8.64655 15.192 8.86855 15.225 9.06055 15.291C9.25255 15.357 9.42655 15.474 9.58255 15.642C9.73855 15.81 9.84655 16.008 9.90655 16.236C9.96655 16.458 9.99655 16.761 9.99655 17.145C9.99655 17.433 9.97855 17.676 9.94255 17.874C9.91255 18.072 9.84355 18.258 9.73555 18.432C9.60955 18.642 9.44155 18.807 9.23155 18.927C9.02155 19.041 8.74555 19.098 8.40355 19.098H7.93555V21.6H7.01755ZM7.93555 16.056V18.234H8.37655C8.56255 18.234 8.70655 18.207 8.80855 18.153C8.91055 18.099 8.98555 18.024 9.03355 17.928C9.08155 17.838 9.10855 17.727 9.11455 17.595C9.12655 17.463 9.13255 17.316 9.13255 17.154C9.13255 17.004 9.12955 16.863 9.12355 16.731C9.11755 16.593 9.09055 16.473 9.04255 16.371C8.99455 16.269 8.92255 16.191 8.82655 16.137C8.73055 16.083 8.59255 16.056 8.41255 16.056H7.93555Z", fill: "white" }), h("path", { d: "M10.6826 21.6V15.192H12.0416C12.5696 15.192 12.9686 15.336 13.2386 15.624C13.5146 15.912 13.6526 16.32 13.6526 16.848V19.845C13.6526 20.445 13.5056 20.889 13.2116 21.177C12.9236 21.459 12.5066 21.6 11.9606 21.6H10.6826ZM11.6006 16.056V20.736H12.0236C12.2816 20.736 12.4646 20.673 12.5726 20.547C12.6806 20.415 12.7346 20.211 12.7346 19.935V16.848C12.7346 16.596 12.6836 16.401 12.5816 16.263C12.4796 16.125 12.2936 16.056 12.0236 16.056H11.6006Z", fill: "white" }), h("path", { d: "M14.5146 21.6V15.192H17.2506V16.056H15.4326V18H17.0166V18.864H15.4326V21.6H14.5146Z", fill: "white" }))), h("div", { class: "pdf-reader__file-info" }, h("swirl-text", { truncate: true, weight: "semibold" }, this.label), h("swirl-text", { color: "subdued", size: "sm", truncate: true }, this.fileTypeLabel))), h("swirl-separator", null), h("swirl-action-list", null, h("swirl-action-list-item", { class: "pdf-reader__print-button", icon: "<swirl-icon-print></swirl-icon-print>", label: this.printButtonLabel, onClick: this.onPrintButtonClick }), h("swirl-action-list-item", { class: "pdf-reader__download-button", disabled: this.downloading, icon: !this.downloading
|
|
201
206
|
? "<swirl-icon-download></swirl-icon-download>"
|
|
202
207
|
: '<swirl-spinner size="xs"></swirl-spinner>', label: this.downloadButtonLabel, onClick: this.onDownloadButtonClick }), h("slot", { name: "menu-items" })))))));
|
|
203
208
|
}
|
|
@@ -212,6 +217,7 @@ const SwirlPdfReader$1 = /*@__PURE__*/ proxyCustomElement(class SwirlPdfReader e
|
|
|
212
217
|
"label": [1],
|
|
213
218
|
"menuLabel": [1, "menu-label"],
|
|
214
219
|
"menuTriggerLabel": [1, "menu-trigger-label"],
|
|
220
|
+
"pdfWorkerSrc": [1, "pdf-worker-src"],
|
|
215
221
|
"printButtonLabel": [1, "print-button-label"],
|
|
216
222
|
"sideBySideButtonLabel": [1, "side-by-side-button-label"],
|
|
217
223
|
"thumbnailButtonLabel": [1, "thumbnail-button-label"],
|
|
@@ -1,247 +1,14 @@
|
|
|
1
1
|
import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* A simple guard function:
|
|
5
|
-
*
|
|
6
|
-
* ```js
|
|
7
|
-
* Math.min(Math.max(low, value), high)
|
|
8
|
-
* ```
|
|
9
|
-
*/
|
|
10
|
-
function guard(low, high, value) {
|
|
11
|
-
return Math.min(Math.max(low, value), high);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
class ColorError extends Error {
|
|
15
|
-
constructor(color) {
|
|
16
|
-
super(`Failed to parse color: "${color}"`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
var ColorError$1 = ColorError;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Parses a color into red, gree, blue, alpha parts
|
|
25
|
-
*
|
|
26
|
-
* @param color the input color. Can be a RGB, RBGA, HSL, HSLA, or named color
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
function parseToRgba(color) {
|
|
30
|
-
if (typeof color !== 'string') throw new ColorError$1(color);
|
|
31
|
-
if (color.trim().toLowerCase() === 'transparent') return [0, 0, 0, 0];
|
|
32
|
-
let normalizedColor = color.trim();
|
|
33
|
-
normalizedColor = namedColorRegex.test(color) ? nameToHex(color) : color;
|
|
34
|
-
const reducedHexMatch = reducedHexRegex.exec(normalizedColor);
|
|
35
|
-
|
|
36
|
-
if (reducedHexMatch) {
|
|
37
|
-
const arr = Array.from(reducedHexMatch).slice(1);
|
|
38
|
-
return [...arr.slice(0, 3).map(x => parseInt(r(x, 2), 16)), parseInt(r(arr[3] || 'f', 2), 16) / 255];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const hexMatch = hexRegex.exec(normalizedColor);
|
|
42
|
-
|
|
43
|
-
if (hexMatch) {
|
|
44
|
-
const arr = Array.from(hexMatch).slice(1);
|
|
45
|
-
return [...arr.slice(0, 3).map(x => parseInt(x, 16)), parseInt(arr[3] || 'ff', 16) / 255];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const rgbaMatch = rgbaRegex.exec(normalizedColor);
|
|
49
|
-
|
|
50
|
-
if (rgbaMatch) {
|
|
51
|
-
const arr = Array.from(rgbaMatch).slice(1);
|
|
52
|
-
return [...arr.slice(0, 3).map(x => parseInt(x, 10)), parseFloat(arr[3] || '1')];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const hslaMatch = hslaRegex.exec(normalizedColor);
|
|
56
|
-
|
|
57
|
-
if (hslaMatch) {
|
|
58
|
-
const [h, s, l, a] = Array.from(hslaMatch).slice(1).map(parseFloat);
|
|
59
|
-
if (guard(0, 100, s) !== s) throw new ColorError$1(color);
|
|
60
|
-
if (guard(0, 100, l) !== l) throw new ColorError$1(color);
|
|
61
|
-
return [...hslToRgb(h, s, l), a || 1];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
throw new ColorError$1(color);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function hash(str) {
|
|
68
|
-
let hash = 5381;
|
|
69
|
-
let i = str.length;
|
|
70
|
-
|
|
71
|
-
while (i) {
|
|
72
|
-
hash = hash * 33 ^ str.charCodeAt(--i);
|
|
73
|
-
}
|
|
74
|
-
/* JavaScript does bitwise operations (like XOR, above) on 32-bit signed
|
|
75
|
-
* integers. Since we want the results to be always positive, convert the
|
|
76
|
-
* signed int to an unsigned by doing an unsigned bitshift. */
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return (hash >>> 0) % 2341;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const colorToInt = x => parseInt(x.replace(/_/g, ''), 36);
|
|
83
|
-
|
|
84
|
-
const compressedColorMap = '1q29ehhb 1n09sgk7 1kl1ekf_ _yl4zsno 16z9eiv3 1p29lhp8 _bd9zg04 17u0____ _iw9zhe5 _to73___ _r45e31e _7l6g016 _jh8ouiv _zn3qba8 1jy4zshs 11u87k0u 1ro9yvyo 1aj3xael 1gz9zjz0 _3w8l4xo 1bf1ekf_ _ke3v___ _4rrkb__ 13j776yz _646mbhl _nrjr4__ _le6mbhl 1n37ehkb _m75f91n _qj3bzfz 1939yygw 11i5z6x8 _1k5f8xs 1509441m 15t5lwgf _ae2th1n _tg1ugcv 1lp1ugcv 16e14up_ _h55rw7n _ny9yavn _7a11xb_ 1ih442g9 _pv442g9 1mv16xof 14e6y7tu 1oo9zkds 17d1cisi _4v9y70f _y98m8kc 1019pq0v 12o9zda8 _348j4f4 1et50i2o _8epa8__ _ts6senj 1o350i2o 1mi9eiuo 1259yrp0 1ln80gnw _632xcoy 1cn9zldc _f29edu4 1n490c8q _9f9ziet 1b94vk74 _m49zkct 1kz6s73a 1eu9dtog _q58s1rz 1dy9sjiq __u89jo3 _aj5nkwg _ld89jo3 13h9z6wx _qa9z2ii _l119xgq _bs5arju 1hj4nwk9 1qt4nwk9 1ge6wau6 14j9zlcw 11p1edc_ _ms1zcxe _439shk6 _jt9y70f _754zsow 1la40eju _oq5p___ _x279qkz 1fa5r3rv _yd2d9ip _424tcku _8y1di2_ _zi2uabw _yy7rn9h 12yz980_ __39ljp6 1b59zg0x _n39zfzp 1fy9zest _b33k___ _hp9wq92 1il50hz4 _io472ub _lj9z3eo 19z9ykg0 _8t8iu3a 12b9bl4a 1ak5yw0o _896v4ku _tb8k8lv _s59zi6t _c09ze0p 1lg80oqn 1id9z8wb _238nba5 1kq6wgdi _154zssg _tn3zk49 _da9y6tc 1sg7cv4f _r12jvtt 1gq5fmkz 1cs9rvci _lp9jn1c _xw1tdnb 13f9zje6 16f6973h _vo7ir40 _bt5arjf _rc45e4t _hr4e100 10v4e100 _hc9zke2 _w91egv_ _sj2r1kk 13c87yx8 _vqpds__ _ni8ggk8 _tj9yqfb 1ia2j4r4 _7x9b10u 1fc9ld4j 1eq9zldr _5j9lhpx _ez9zl6o _md61fzm'.split(' ').reduce((acc, next) => {
|
|
85
|
-
const key = colorToInt(next.substring(0, 3));
|
|
86
|
-
const hex = colorToInt(next.substring(3)).toString(16); // NOTE: padStart could be used here but it breaks Node 6 compat
|
|
87
|
-
// https://github.com/ricokahler/color2k/issues/351
|
|
88
|
-
|
|
89
|
-
let prefix = '';
|
|
90
|
-
|
|
91
|
-
for (let i = 0; i < 6 - hex.length; i++) {
|
|
92
|
-
prefix += '0';
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
acc[key] = `${prefix}${hex}`;
|
|
96
|
-
return acc;
|
|
97
|
-
}, {});
|
|
98
|
-
/**
|
|
99
|
-
* Checks if a string is a CSS named color and returns its equivalent hex value, otherwise returns the original color.
|
|
100
|
-
*/
|
|
101
|
-
|
|
102
|
-
function nameToHex(color) {
|
|
103
|
-
const normalizedColorName = color.toLowerCase().trim();
|
|
104
|
-
const result = compressedColorMap[hash(normalizedColorName)];
|
|
105
|
-
if (!result) throw new ColorError$1(color);
|
|
106
|
-
return `#${result}`;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const r = (str, amount) => Array.from(Array(amount)).map(() => str).join('');
|
|
110
|
-
|
|
111
|
-
const reducedHexRegex = new RegExp(`^#${r('([a-f0-9])', 3)}([a-f0-9])?$`, 'i');
|
|
112
|
-
const hexRegex = new RegExp(`^#${r('([a-f0-9]{2})', 3)}([a-f0-9]{2})?$`, 'i');
|
|
113
|
-
const rgbaRegex = new RegExp(`^rgba?\\(\\s*(\\d+)\\s*${r(',\\s*(\\d+)\\s*', 2)}(?:,\\s*([\\d.]+))?\\s*\\)$`, 'i');
|
|
114
|
-
const hslaRegex = /^hsla?\(\s*([\d.]+)\s*,\s*([\d.]+)%\s*,\s*([\d.]+)%(?:\s*,\s*([\d.]+))?\s*\)$/i;
|
|
115
|
-
const namedColorRegex = /^[a-z]+$/i;
|
|
116
|
-
|
|
117
|
-
const roundColor = color => {
|
|
118
|
-
return Math.round(color * 255);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const hslToRgb = (hue, saturation, lightness) => {
|
|
122
|
-
let l = lightness / 100;
|
|
123
|
-
|
|
124
|
-
if (saturation === 0) {
|
|
125
|
-
// achromatic
|
|
126
|
-
return [l, l, l].map(roundColor);
|
|
127
|
-
} // formulae from https://en.wikipedia.org/wiki/HSL_and_HSV
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const huePrime = (hue % 360 + 360) % 360 / 60;
|
|
131
|
-
const chroma = (1 - Math.abs(2 * l - 1)) * (saturation / 100);
|
|
132
|
-
const secondComponent = chroma * (1 - Math.abs(huePrime % 2 - 1));
|
|
133
|
-
let red = 0;
|
|
134
|
-
let green = 0;
|
|
135
|
-
let blue = 0;
|
|
136
|
-
|
|
137
|
-
if (huePrime >= 0 && huePrime < 1) {
|
|
138
|
-
red = chroma;
|
|
139
|
-
green = secondComponent;
|
|
140
|
-
} else if (huePrime >= 1 && huePrime < 2) {
|
|
141
|
-
red = secondComponent;
|
|
142
|
-
green = chroma;
|
|
143
|
-
} else if (huePrime >= 2 && huePrime < 3) {
|
|
144
|
-
green = chroma;
|
|
145
|
-
blue = secondComponent;
|
|
146
|
-
} else if (huePrime >= 3 && huePrime < 4) {
|
|
147
|
-
green = secondComponent;
|
|
148
|
-
blue = chroma;
|
|
149
|
-
} else if (huePrime >= 4 && huePrime < 5) {
|
|
150
|
-
red = secondComponent;
|
|
151
|
-
blue = chroma;
|
|
152
|
-
} else if (huePrime >= 5 && huePrime < 6) {
|
|
153
|
-
red = chroma;
|
|
154
|
-
blue = secondComponent;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const lightnessModification = l - chroma / 2;
|
|
158
|
-
const finalRed = red + lightnessModification;
|
|
159
|
-
const finalGreen = green + lightnessModification;
|
|
160
|
-
const finalBlue = blue + lightnessModification;
|
|
161
|
-
return [finalRed, finalGreen, finalBlue].map(roundColor);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
// taken from:
|
|
165
|
-
/**
|
|
166
|
-
* Parses a color in hue, saturation, lightness, and the alpha channel.
|
|
167
|
-
*
|
|
168
|
-
* Hue is a number between 0 and 360, saturation, lightness, and alpha are
|
|
169
|
-
* decimal percentages between 0 and 1
|
|
170
|
-
*/
|
|
171
|
-
|
|
172
|
-
function parseToHsla(color) {
|
|
173
|
-
const [red, green, blue, alpha] = parseToRgba(color).map((value, index) => // 3rd index is alpha channel which is already normalized
|
|
174
|
-
index === 3 ? value : value / 255);
|
|
175
|
-
const max = Math.max(red, green, blue);
|
|
176
|
-
const min = Math.min(red, green, blue);
|
|
177
|
-
const lightness = (max + min) / 2; // achromatic
|
|
178
|
-
|
|
179
|
-
if (max === min) return [0, 0, lightness, alpha];
|
|
180
|
-
const delta = max - min;
|
|
181
|
-
const saturation = lightness > 0.5 ? delta / (2 - max - min) : delta / (max + min);
|
|
182
|
-
const hue = 60 * (red === max ? (green - blue) / delta + (green < blue ? 6 : 0) : green === max ? (blue - red) / delta + 2 : (red - green) / delta + 4);
|
|
183
|
-
return [hue, saturation, lightness, alpha];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Takes in hsla parts and constructs an hsla string
|
|
188
|
-
*
|
|
189
|
-
* @param hue The color circle (from 0 to 360) - 0 (or 360) is red, 120 is green, 240 is blue
|
|
190
|
-
* @param saturation Percentage of saturation, given as a decimal between 0 and 1
|
|
191
|
-
* @param lightness Percentage of lightness, given as a decimal between 0 and 1
|
|
192
|
-
* @param alpha Percentage of opacity, given as a decimal between 0 and 1
|
|
193
|
-
*/
|
|
194
|
-
|
|
195
|
-
function hsla(hue, saturation, lightness, alpha) {
|
|
196
|
-
return `hsla(${(hue % 360).toFixed()}, ${guard(0, 100, saturation * 100).toFixed()}%, ${guard(0, 100, lightness * 100).toFixed()}%, ${parseFloat(guard(0, 1, alpha).toFixed(3))})`;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Takes in rgba parts and returns an rgba string
|
|
201
|
-
*
|
|
202
|
-
* @param red The amount of red in the red channel, given in a number between 0 and 255 inclusive
|
|
203
|
-
* @param green The amount of green in the red channel, given in a number between 0 and 255 inclusive
|
|
204
|
-
* @param blue The amount of blue in the red channel, given in a number between 0 and 255 inclusive
|
|
205
|
-
* @param alpha Percentage of opacity, given as a decimal between 0 and 1
|
|
206
|
-
*/
|
|
207
|
-
|
|
208
|
-
function rgba(red, green, blue, alpha) {
|
|
209
|
-
return `rgba(${guard(0, 255, red).toFixed()}, ${guard(0, 255, green).toFixed()}, ${guard(0, 255, blue).toFixed()}, ${parseFloat(guard(0, 1, alpha).toFixed(3))})`;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Takes in any color and returns it as an rgba string.
|
|
214
|
-
*/
|
|
215
|
-
|
|
216
|
-
function toRgba(color) {
|
|
217
|
-
return rgba(...parseToRgba(color));
|
|
218
|
-
}
|
|
219
|
-
|
|
220
3
|
const swirlThemeProviderCss = ".sc-swirl-theme-provider-h{display:block}";
|
|
221
4
|
|
|
222
5
|
const preferredThemeStorageKey = "swirl-preferred-theme";
|
|
223
|
-
const tenantColorMapping = {
|
|
224
|
-
"--s-action-primary-default": "primary",
|
|
225
|
-
"--s-action-primary-hovered": "primaryHovered",
|
|
226
|
-
"--s-action-primary-pressed": "primaryPressed",
|
|
227
|
-
"--s-text-on-action-primary": "primaryContrast",
|
|
228
|
-
"--s-icon-on-action-primary": "primaryContrast",
|
|
229
|
-
"--s-surface-highlight-default": "secondary",
|
|
230
|
-
"--s-surface-highlight-hovered": "secondaryHovered",
|
|
231
|
-
"--s-surface-highlight-pressed": "secondaryPressed",
|
|
232
|
-
"--s-on-surface-highlight-default": "secondaryHovered",
|
|
233
|
-
"--s-text-on-surface-highlight": "secondaryContrast",
|
|
234
|
-
"--s-icon-on-surface-highlight": "secondaryContrast",
|
|
235
|
-
"--s-text-highlight": "text",
|
|
236
|
-
"--s-interactive-primary-default": "text",
|
|
237
|
-
"--s-interactive-primary-hovered": "textHovered",
|
|
238
|
-
"--s-interactive-primary-pressed": "textPressed",
|
|
239
|
-
};
|
|
240
6
|
const SwirlThemeProvider$1 = /*@__PURE__*/ proxyCustomElement(class SwirlThemeProvider extends HTMLElement {
|
|
241
7
|
constructor() {
|
|
242
8
|
super();
|
|
243
9
|
this.__registerHost();
|
|
244
10
|
this.themeChange = createEvent(this, "themeChange", 7);
|
|
11
|
+
this.setDesignTokens = [];
|
|
245
12
|
this.config = undefined;
|
|
246
13
|
}
|
|
247
14
|
componentWillLoad() {
|
|
@@ -255,27 +22,27 @@ const SwirlThemeProvider$1 = /*@__PURE__*/ proxyCustomElement(class SwirlThemePr
|
|
|
255
22
|
this.updateAppTheme();
|
|
256
23
|
}
|
|
257
24
|
/**
|
|
258
|
-
* Returns the active
|
|
25
|
+
* Returns the active OS theme.
|
|
259
26
|
* @returns SwirlTheme
|
|
260
27
|
*/
|
|
261
|
-
async
|
|
262
|
-
return this.
|
|
28
|
+
async getActiveOSTheme() {
|
|
29
|
+
return this.appOSTheme;
|
|
263
30
|
}
|
|
264
31
|
/**
|
|
265
|
-
* Returns the user's preferred theme stored in local storage.
|
|
32
|
+
* Returns the user's preferred OS theme stored in local storage.
|
|
266
33
|
* @returns SwirlTheme
|
|
267
34
|
*/
|
|
268
|
-
async
|
|
35
|
+
async getPreferredOSTheme() {
|
|
269
36
|
if (!Boolean(this.resolvedConfig.storage)) {
|
|
270
37
|
return;
|
|
271
38
|
}
|
|
272
39
|
return this.resolvedConfig.storage.getItem(preferredThemeStorageKey);
|
|
273
40
|
}
|
|
274
41
|
/**
|
|
275
|
-
* Sets the user's preferred theme and stores it in local storage. Overrides
|
|
276
|
-
* the
|
|
42
|
+
* Sets the user's preferred OS theme and stores it in local storage. Overrides
|
|
43
|
+
* the system theme.
|
|
277
44
|
*/
|
|
278
|
-
async
|
|
45
|
+
async setPreferredOSTheme(theme) {
|
|
279
46
|
if (!Boolean(this.resolvedConfig.storage)) {
|
|
280
47
|
return;
|
|
281
48
|
}
|
|
@@ -283,9 +50,9 @@ const SwirlThemeProvider$1 = /*@__PURE__*/ proxyCustomElement(class SwirlThemePr
|
|
|
283
50
|
this.updateAppTheme();
|
|
284
51
|
}
|
|
285
52
|
/**
|
|
286
|
-
* Resets the user's preferred theme, using the
|
|
53
|
+
* Resets the user's preferred OS theme, using the system theme instead.
|
|
287
54
|
*/
|
|
288
|
-
async
|
|
55
|
+
async resetPreferredOSTheme() {
|
|
289
56
|
if (!Boolean(this.resolvedConfig.storage)) {
|
|
290
57
|
return;
|
|
291
58
|
}
|
|
@@ -312,8 +79,8 @@ const SwirlThemeProvider$1 = /*@__PURE__*/ proxyCustomElement(class SwirlThemePr
|
|
|
312
79
|
});
|
|
313
80
|
}
|
|
314
81
|
async updateAppTheme() {
|
|
315
|
-
this.
|
|
316
|
-
if (this.
|
|
82
|
+
this.appOSTheme = (await this.getPreferredOSTheme()) || this.osTheme;
|
|
83
|
+
if (this.appOSTheme === "dark") {
|
|
317
84
|
document.documentElement.classList.remove("theme-light");
|
|
318
85
|
document.documentElement.classList.add("theme-dark");
|
|
319
86
|
}
|
|
@@ -322,59 +89,49 @@ const SwirlThemeProvider$1 = /*@__PURE__*/ proxyCustomElement(class SwirlThemePr
|
|
|
322
89
|
document.documentElement.classList.add("theme-light");
|
|
323
90
|
}
|
|
324
91
|
this.updateTenantVariables();
|
|
92
|
+
this.updateTenantAssets();
|
|
325
93
|
const themeChangeEventData = {
|
|
326
|
-
activeTheme: await this.
|
|
327
|
-
preferredTheme: await this.
|
|
94
|
+
activeTheme: await this.getActiveOSTheme(),
|
|
95
|
+
preferredTheme: await this.getPreferredOSTheme(),
|
|
328
96
|
};
|
|
329
|
-
if (!Boolean(this.
|
|
97
|
+
if (!Boolean(this.recentOSThemeChangeEventData) ||
|
|
330
98
|
themeChangeEventData.activeTheme !==
|
|
331
|
-
this.
|
|
99
|
+
this.recentOSThemeChangeEventData.activeTheme ||
|
|
332
100
|
themeChangeEventData.preferredTheme !==
|
|
333
|
-
this.
|
|
334
|
-
this.
|
|
335
|
-
this.themeChange.emit(this.
|
|
101
|
+
this.recentOSThemeChangeEventData.preferredTheme) {
|
|
102
|
+
this.recentOSThemeChangeEventData = themeChangeEventData;
|
|
103
|
+
this.themeChange.emit(this.recentOSThemeChangeEventData);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
updateTenantAssets() {
|
|
107
|
+
const theme = this.resolvedConfig?.themes?.[this.appOSTheme];
|
|
108
|
+
if (!Boolean(theme)) {
|
|
109
|
+
return;
|
|
336
110
|
}
|
|
111
|
+
document.head
|
|
112
|
+
.querySelector('link[rel="icon"]')
|
|
113
|
+
?.setAttribute("href", theme.favicon.link);
|
|
337
114
|
}
|
|
338
115
|
updateTenantVariables() {
|
|
339
|
-
const
|
|
340
|
-
if (!Boolean(
|
|
116
|
+
const theme = this.resolvedConfig?.themes?.[this.appOSTheme];
|
|
117
|
+
if (!Boolean(theme)) {
|
|
341
118
|
this.resetTenantVariables();
|
|
342
119
|
return;
|
|
343
120
|
}
|
|
344
121
|
const rootElement = this.resolvedConfig.rootElement;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const secondaryHovered = toRgba(hsla(secondaryHsla[0], secondaryHsla[1], secondaryHsla[2] + 0.07, 1));
|
|
352
|
-
const secondaryPressed = toRgba(hsla(secondaryHsla[0], secondaryHsla[1], secondaryHsla[2] + 0.15, 1));
|
|
353
|
-
const textHovered = toRgba(hsla(textHsla[0], textHsla[1] - 0.34, textHsla[2] + 0.1, 1));
|
|
354
|
-
const textPressed = toRgba(hsla(textHsla[0], textHsla[1] - 0.48, textHsla[2] + 0.2, 1));
|
|
355
|
-
const tenantThemeWithGeneratedStateColors = {
|
|
356
|
-
...tenantTheme,
|
|
357
|
-
primaryHovered: primaryHovered,
|
|
358
|
-
primaryPressed: primaryPressed,
|
|
359
|
-
secondaryHovered: secondaryHovered,
|
|
360
|
-
secondaryPressed: secondaryPressed,
|
|
361
|
-
textHovered: textHovered,
|
|
362
|
-
textPressed: textPressed,
|
|
363
|
-
};
|
|
364
|
-
// set custom properties for tenant theme colors
|
|
365
|
-
Object.entries(tenantColorMapping).forEach(([key, value]) => rootElement.style.setProperty(key, tenantThemeWithGeneratedStateColors[value]));
|
|
122
|
+
this.setDesignTokens = [];
|
|
123
|
+
theme.design_tokens.forEach((token) => {
|
|
124
|
+
const propertyName = `--s-${token.id}`;
|
|
125
|
+
rootElement.style.setProperty(propertyName, `rgba(${token.color.r}, ${token.color.g}, ${token.color.b}, ${token.color.a})`);
|
|
126
|
+
this.setDesignTokens.push(propertyName);
|
|
127
|
+
});
|
|
366
128
|
}
|
|
367
129
|
resetTenantVariables() {
|
|
368
130
|
const rootElement = this.resolvedConfig.rootElement;
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
"secondaryHovered",
|
|
374
|
-
"secondaryPressed",
|
|
375
|
-
"textHovered",
|
|
376
|
-
"textPressed",
|
|
377
|
-
].forEach((key) => rootElement.style.removeProperty(key));
|
|
131
|
+
this.setDesignTokens.forEach((property) => {
|
|
132
|
+
rootElement.style.removeProperty(property);
|
|
133
|
+
});
|
|
134
|
+
this.setDesignTokens = [];
|
|
378
135
|
}
|
|
379
136
|
render() {
|
|
380
137
|
return (h(Host, null, h("slot", null)));
|
|
@@ -385,10 +142,10 @@ const SwirlThemeProvider$1 = /*@__PURE__*/ proxyCustomElement(class SwirlThemePr
|
|
|
385
142
|
static get style() { return swirlThemeProviderCss; }
|
|
386
143
|
}, [6, "swirl-theme-provider", {
|
|
387
144
|
"config": [16],
|
|
388
|
-
"
|
|
389
|
-
"
|
|
390
|
-
"
|
|
391
|
-
"
|
|
145
|
+
"getActiveOSTheme": [64],
|
|
146
|
+
"getPreferredOSTheme": [64],
|
|
147
|
+
"setPreferredOSTheme": [64],
|
|
148
|
+
"resetPreferredOSTheme": [64]
|
|
392
149
|
}]);
|
|
393
150
|
function defineCustomElement$1() {
|
|
394
151
|
if (typeof customElements === "undefined") {
|