@studiometa/ui 0.2.47 → 0.2.49
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/atoms/Button/Button.twig +15 -5
- package/atoms/FigureVideo/FigureVideo.cjs +132 -0
- package/atoms/FigureVideo/FigureVideo.cjs.map +7 -0
- package/atoms/FigureVideo/FigureVideo.d.ts +51 -0
- package/atoms/FigureVideo/FigureVideo.js +110 -0
- package/atoms/FigureVideo/FigureVideo.js.map +7 -0
- package/atoms/FigureVideo/FigureVideo.twig +152 -0
- package/atoms/FigureVideo/FigureVideoTwicpics.cjs +153 -0
- package/atoms/FigureVideo/FigureVideoTwicpics.cjs.map +7 -0
- package/atoms/FigureVideo/FigureVideoTwicpics.d.ts +57 -0
- package/atoms/FigureVideo/FigureVideoTwicpics.js +135 -0
- package/atoms/FigureVideo/FigureVideoTwicpics.js.map +7 -0
- package/atoms/FigureVideo/FigureVideoTwicpics.twig +98 -0
- package/atoms/FigureVideo/index.cjs +22 -0
- package/atoms/FigureVideo/index.cjs.map +7 -0
- package/atoms/FigureVideo/index.d.ts +2 -0
- package/atoms/FigureVideo/index.js +3 -0
- package/atoms/FigureVideo/index.js.map +7 -0
- package/atoms/Icon/IconInline.twig +11 -4
- package/atoms/Icon/IconInlineImg.twig +44 -41
- package/atoms/index.cjs +1 -0
- package/atoms/index.cjs.map +2 -2
- package/atoms/index.d.ts +1 -0
- package/atoms/index.js +1 -0
- package/atoms/index.js.map +2 -2
- package/molecules/AnchorNav/AnchorNav.cjs +63 -0
- package/molecules/AnchorNav/AnchorNav.cjs.map +7 -0
- package/molecules/AnchorNav/AnchorNav.d.ts +24 -0
- package/molecules/AnchorNav/AnchorNav.js +41 -0
- package/molecules/AnchorNav/AnchorNav.js.map +7 -0
- package/molecules/AnchorNav/AnchorNavLink.cjs +40 -0
- package/molecules/AnchorNav/AnchorNavLink.cjs.map +7 -0
- package/molecules/AnchorNav/AnchorNavLink.d.ts +19 -0
- package/molecules/AnchorNav/AnchorNavLink.js +18 -0
- package/molecules/AnchorNav/AnchorNavLink.js.map +7 -0
- package/molecules/AnchorNav/AnchorNavTarget.cjs +35 -0
- package/molecules/AnchorNav/AnchorNavTarget.cjs.map +7 -0
- package/molecules/AnchorNav/AnchorNavTarget.d.ts +13 -0
- package/molecules/AnchorNav/AnchorNavTarget.js +13 -0
- package/molecules/AnchorNav/AnchorNavTarget.js.map +7 -0
- package/molecules/AnchorNav/index.cjs +23 -0
- package/molecules/AnchorNav/index.cjs.map +7 -0
- package/molecules/AnchorNav/index.d.ts +3 -0
- package/molecules/AnchorNav/index.js +4 -0
- package/molecules/AnchorNav/index.js.map +7 -0
- package/molecules/IconList/IconList.twig +83 -0
- package/molecules/index.cjs +1 -0
- package/molecules/index.cjs.map +2 -2
- package/molecules/index.d.ts +1 -0
- package/molecules/index.js +1 -0
- package/molecules/index.js.map +2 -2
- package/organisms/Frame/Frame.cjs +20 -7
- package/organisms/Frame/Frame.cjs.map +3 -3
- package/organisms/Frame/Frame.d.ts +2 -2
- package/organisms/Frame/Frame.js +20 -7
- package/organisms/Frame/Frame.js.map +3 -3
- package/package.json +1 -1
package/atoms/Button/Button.twig
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @param string $href
|
|
9
9
|
* @param array $attr
|
|
10
10
|
* @param string $icon
|
|
11
|
+
* @param array $icon_attr
|
|
11
12
|
* @param array|string $icon_classes
|
|
12
13
|
* @param 'start'|'end' $icon_position
|
|
13
14
|
* @param boolean $icon_only
|
|
@@ -39,12 +40,21 @@
|
|
|
39
40
|
|
|
40
41
|
{% set rendered_icon %}
|
|
41
42
|
{% block icon %}
|
|
42
|
-
{
|
|
43
|
+
{# @TODO: Breaking change -> Delete icon_classes to use only icon_attr #}
|
|
44
|
+
{% include '@ui/atoms/Icon/IconInline.twig' with {
|
|
43
45
|
name: icon ?? '',
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
attr: merge_html_attributes(
|
|
47
|
+
icon_attr ?? null,
|
|
48
|
+
{
|
|
49
|
+
class: {
|
|
50
|
+
'mr-3': not icon_only and icon_position == 'start',
|
|
51
|
+
'ml-3': not icon_only and icon_position == 'end',
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
class: icon_classes,
|
|
56
|
+
},
|
|
57
|
+
)
|
|
48
58
|
} %}
|
|
49
59
|
{% endblock %}
|
|
50
60
|
{% endset %}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/ui/atoms/FigureVideo/FigureVideo.ts
|
|
20
|
+
var FigureVideo_exports = {};
|
|
21
|
+
__export(FigureVideo_exports, {
|
|
22
|
+
FigureVideo: () => FigureVideo
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(FigureVideo_exports);
|
|
25
|
+
var import_js_toolkit = require("@studiometa/js-toolkit");
|
|
26
|
+
var import_primitives = require("../../primitives/index.cjs");
|
|
27
|
+
var import__ = require("../index.cjs");
|
|
28
|
+
var FigureVideo = class extends (0, import_js_toolkit.withMountWhenInView)(
|
|
29
|
+
import_primitives.Transition,
|
|
30
|
+
{
|
|
31
|
+
threshold: [0, 1]
|
|
32
|
+
}
|
|
33
|
+
) {
|
|
34
|
+
/**
|
|
35
|
+
* Config.
|
|
36
|
+
*/
|
|
37
|
+
static config = {
|
|
38
|
+
...import_primitives.Transition.config,
|
|
39
|
+
name: "FigureVideo",
|
|
40
|
+
emits: ["load"],
|
|
41
|
+
refs: ["video"],
|
|
42
|
+
options: {
|
|
43
|
+
...import_primitives.Transition.config.options,
|
|
44
|
+
lazy: Boolean
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Get the transition target.
|
|
49
|
+
*/
|
|
50
|
+
get target() {
|
|
51
|
+
return this.$refs.video;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the video sources.
|
|
55
|
+
*/
|
|
56
|
+
get sources() {
|
|
57
|
+
return Array.from(this.$refs.video.querySelectorAll("source"));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Load poster
|
|
61
|
+
*/
|
|
62
|
+
loadPoster() {
|
|
63
|
+
const { video } = this.$refs;
|
|
64
|
+
if (!video.dataset.poster) {
|
|
65
|
+
return Promise.resolve();
|
|
66
|
+
}
|
|
67
|
+
return (0, import__.loadImage)(video.dataset.poster).then(() => {
|
|
68
|
+
video.poster = video.dataset.poster;
|
|
69
|
+
this.$log("fresh poster loaded");
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Load sources
|
|
74
|
+
* @returns {Promise}
|
|
75
|
+
*/
|
|
76
|
+
loadSources() {
|
|
77
|
+
const { video } = this.$refs;
|
|
78
|
+
this.sources.forEach((source) => {
|
|
79
|
+
if (!source.dataset.src) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
source.src = source.dataset.src;
|
|
83
|
+
});
|
|
84
|
+
return new Promise((resolve) => {
|
|
85
|
+
const loadHandler = () => {
|
|
86
|
+
video.removeEventListener("loadeddata", loadHandler);
|
|
87
|
+
this.$log("fresh sources loaded");
|
|
88
|
+
resolve();
|
|
89
|
+
};
|
|
90
|
+
video.addEventListener("loadeddata", loadHandler);
|
|
91
|
+
video.load();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Load
|
|
96
|
+
* @returns {Promise}
|
|
97
|
+
*/
|
|
98
|
+
load() {
|
|
99
|
+
return Promise.all([this.loadPoster(), this.loadSources()]);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Load on mount.
|
|
103
|
+
*/
|
|
104
|
+
async mounted() {
|
|
105
|
+
this.$log("mounted");
|
|
106
|
+
const { video } = this.$refs;
|
|
107
|
+
if (!video) {
|
|
108
|
+
throw new Error("[VideoFigure] The `video` ref is required.");
|
|
109
|
+
}
|
|
110
|
+
if (!(video instanceof HTMLVideoElement)) {
|
|
111
|
+
throw new Error("[VideoFigure] The `video` ref must be an `<video>` element.");
|
|
112
|
+
}
|
|
113
|
+
if (!this.$options.lazy) {
|
|
114
|
+
this.$log("Lazy loading disabled");
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this.$log("start loading");
|
|
118
|
+
await this.load();
|
|
119
|
+
this.$log("all is loaded");
|
|
120
|
+
await this.enter();
|
|
121
|
+
this.$log("transition done");
|
|
122
|
+
this.$emit("load");
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Terminate the component on load.
|
|
126
|
+
*/
|
|
127
|
+
onLoad() {
|
|
128
|
+
this.$terminate();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
132
|
+
//# sourceMappingURL=FigureVideo.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/ui/atoms/FigureVideo/FigureVideo.ts"],
|
|
4
|
+
"sourcesContent": ["import { withMountWhenInView } from '@studiometa/js-toolkit';\nimport type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport { Transition } from '../../primitives/index.js';\nimport { loadImage } from '../index.js';\n\nexport interface FigureVideoProps extends BaseProps {\n $refs: {\n video: HTMLVideoElement;\n };\n $options: {\n lazy: boolean;\n };\n}\n\n/**\n * FigureVideo class.\n */\nexport class FigureVideo<T extends BaseProps = BaseProps> extends withMountWhenInView<Transition>(\n Transition,\n {\n threshold: [0, 1],\n },\n)<T & FigureVideoProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...Transition.config,\n name: 'FigureVideo',\n emits: ['load'],\n refs: ['video'],\n options: {\n ...Transition.config.options,\n lazy: Boolean,\n },\n };\n\n /**\n * Get the transition target.\n */\n get target(): HTMLVideoElement {\n return this.$refs.video;\n }\n\n /**\n * Get the video sources.\n */\n get sources(): Array<HTMLSourceElement> {\n return Array.from(this.$refs.video.querySelectorAll('source'));\n }\n\n /**\n * Load poster\n */\n loadPoster(): Promise<void|HTMLImageElement> {\n const { video } = this.$refs;\n\n if (!video.dataset.poster) {\n return Promise.resolve();\n }\n\n return loadImage(video.dataset.poster).then(() => {\n video.poster = video.dataset.poster;\n this.$log('fresh poster loaded');\n })\n }\n\n /**\n * Load sources\n * @returns {Promise}\n */\n loadSources(): Promise<void> {\n const { video } = this.$refs;\n\n this.sources.forEach((source) => {\n if (!source.dataset.src) {\n return;\n }\n source.src = source.dataset.src;\n });\n\n return new Promise<void>((resolve) => {\n const loadHandler = () => {\n video.removeEventListener('loadeddata', loadHandler);\n this.$log('fresh sources loaded');\n resolve();\n };\n video.addEventListener('loadeddata', loadHandler);\n video.load();\n });\n }\n\n /**\n * Load\n * @returns {Promise}\n */\n load(): Promise<any[]> {\n return Promise.all([this.loadPoster(), this.loadSources()]);\n }\n\n /**\n * Load on mount.\n */\n async mounted() {\n this.$log('mounted');\n const { video } = this.$refs;\n\n if (!video) {\n throw new Error('[VideoFigure] The `video` ref is required.');\n }\n\n if (!(video instanceof HTMLVideoElement)) {\n throw new Error('[VideoFigure] The `video` ref must be an `<video>` element.');\n }\n\n if (!this.$options.lazy) {\n this.$log('Lazy loading disabled');\n return;\n }\n\n this.$log('start loading');\n await this.load();\n this.$log('all is loaded');\n await this.enter();\n this.$log('transition done');\n this.$emit('load');\n }\n\n /**\n * Terminate the component on load.\n */\n onLoad() {\n this.$terminate();\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAoC;AAEpC,wBAA2B;AAC3B,eAA0B;AAcnB,IAAM,cAAN,kBAA2D;AAAA,EAChE;AAAA,EACA;AAAA,IACE,WAAW,CAAC,GAAG,CAAC;AAAA,EAClB;AACF,EAAwB;AAAA;AAAA;AAAA;AAAA,EAItB,OAAO,SAAqB;AAAA,IAC1B,GAAG,6BAAW;AAAA,IACd,MAAM;AAAA,IACN,OAAO,CAAC,MAAM;AAAA,IACd,MAAM,CAAC,OAAO;AAAA,IACd,SAAS;AAAA,MACP,GAAG,6BAAW,OAAO;AAAA,MACrB,MAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,SAA2B;AAC7B,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,UAAoC;AACtC,WAAO,MAAM,KAAK,KAAK,MAAM,MAAM,iBAAiB,QAAQ,CAAC;AAAA,EAC/D;AAAA;AAAA;AAAA;AAAA,EAKA,aAA6C;AAC3C,UAAM,EAAE,MAAM,IAAI,KAAK;AAEvB,QAAI,CAAC,MAAM,QAAQ,QAAQ;AACzB,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAEA,eAAO,oBAAU,MAAM,QAAQ,MAAM,EAAE,KAAK,MAAM;AAChD,YAAM,SAAS,MAAM,QAAQ;AAC7B,WAAK,KAAK,qBAAqB;AAAA,IAC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{ BaseConfig, BaseProps } from '@studiometa/js-toolkit';
|
|
2
|
+
import { Transition } from '../../primitives/index.js';
|
|
3
|
+
export interface FigureVideoProps extends BaseProps {
|
|
4
|
+
$refs: {
|
|
5
|
+
video: HTMLVideoElement;
|
|
6
|
+
};
|
|
7
|
+
$options: {
|
|
8
|
+
lazy: boolean;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
declare const FigureVideo_base: import("@studiometa/js-toolkit").BaseDecorator<import("@studiometa/js-toolkit").WithMountWhenInViewInterface, Transition<BaseProps>, import("@studiometa/js-toolkit").WithMountWhenInViewProps>;
|
|
12
|
+
/**
|
|
13
|
+
* FigureVideo class.
|
|
14
|
+
*/
|
|
15
|
+
export declare class FigureVideo<T extends BaseProps = BaseProps> extends FigureVideo_base<T & FigureVideoProps> {
|
|
16
|
+
/**
|
|
17
|
+
* Config.
|
|
18
|
+
*/
|
|
19
|
+
static config: BaseConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Get the transition target.
|
|
22
|
+
*/
|
|
23
|
+
get target(): HTMLVideoElement;
|
|
24
|
+
/**
|
|
25
|
+
* Get the video sources.
|
|
26
|
+
*/
|
|
27
|
+
get sources(): Array<HTMLSourceElement>;
|
|
28
|
+
/**
|
|
29
|
+
* Load poster
|
|
30
|
+
*/
|
|
31
|
+
loadPoster(): Promise<void | HTMLImageElement>;
|
|
32
|
+
/**
|
|
33
|
+
* Load sources
|
|
34
|
+
* @returns {Promise}
|
|
35
|
+
*/
|
|
36
|
+
loadSources(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Load
|
|
39
|
+
* @returns {Promise}
|
|
40
|
+
*/
|
|
41
|
+
load(): Promise<any[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Load on mount.
|
|
44
|
+
*/
|
|
45
|
+
mounted(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Terminate the component on load.
|
|
48
|
+
*/
|
|
49
|
+
onLoad(): void;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { withMountWhenInView } from "@studiometa/js-toolkit";
|
|
2
|
+
import { Transition } from "../../primitives/index.js";
|
|
3
|
+
import { loadImage } from "../index.js";
|
|
4
|
+
class FigureVideo extends withMountWhenInView(
|
|
5
|
+
Transition,
|
|
6
|
+
{
|
|
7
|
+
threshold: [0, 1]
|
|
8
|
+
}
|
|
9
|
+
) {
|
|
10
|
+
/**
|
|
11
|
+
* Config.
|
|
12
|
+
*/
|
|
13
|
+
static config = {
|
|
14
|
+
...Transition.config,
|
|
15
|
+
name: "FigureVideo",
|
|
16
|
+
emits: ["load"],
|
|
17
|
+
refs: ["video"],
|
|
18
|
+
options: {
|
|
19
|
+
...Transition.config.options,
|
|
20
|
+
lazy: Boolean
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Get the transition target.
|
|
25
|
+
*/
|
|
26
|
+
get target() {
|
|
27
|
+
return this.$refs.video;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the video sources.
|
|
31
|
+
*/
|
|
32
|
+
get sources() {
|
|
33
|
+
return Array.from(this.$refs.video.querySelectorAll("source"));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Load poster
|
|
37
|
+
*/
|
|
38
|
+
loadPoster() {
|
|
39
|
+
const { video } = this.$refs;
|
|
40
|
+
if (!video.dataset.poster) {
|
|
41
|
+
return Promise.resolve();
|
|
42
|
+
}
|
|
43
|
+
return loadImage(video.dataset.poster).then(() => {
|
|
44
|
+
video.poster = video.dataset.poster;
|
|
45
|
+
this.$log("fresh poster loaded");
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Load sources
|
|
50
|
+
* @returns {Promise}
|
|
51
|
+
*/
|
|
52
|
+
loadSources() {
|
|
53
|
+
const { video } = this.$refs;
|
|
54
|
+
this.sources.forEach((source) => {
|
|
55
|
+
if (!source.dataset.src) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
source.src = source.dataset.src;
|
|
59
|
+
});
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
const loadHandler = () => {
|
|
62
|
+
video.removeEventListener("loadeddata", loadHandler);
|
|
63
|
+
this.$log("fresh sources loaded");
|
|
64
|
+
resolve();
|
|
65
|
+
};
|
|
66
|
+
video.addEventListener("loadeddata", loadHandler);
|
|
67
|
+
video.load();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Load
|
|
72
|
+
* @returns {Promise}
|
|
73
|
+
*/
|
|
74
|
+
load() {
|
|
75
|
+
return Promise.all([this.loadPoster(), this.loadSources()]);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Load on mount.
|
|
79
|
+
*/
|
|
80
|
+
async mounted() {
|
|
81
|
+
this.$log("mounted");
|
|
82
|
+
const { video } = this.$refs;
|
|
83
|
+
if (!video) {
|
|
84
|
+
throw new Error("[VideoFigure] The `video` ref is required.");
|
|
85
|
+
}
|
|
86
|
+
if (!(video instanceof HTMLVideoElement)) {
|
|
87
|
+
throw new Error("[VideoFigure] The `video` ref must be an `<video>` element.");
|
|
88
|
+
}
|
|
89
|
+
if (!this.$options.lazy) {
|
|
90
|
+
this.$log("Lazy loading disabled");
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.$log("start loading");
|
|
94
|
+
await this.load();
|
|
95
|
+
this.$log("all is loaded");
|
|
96
|
+
await this.enter();
|
|
97
|
+
this.$log("transition done");
|
|
98
|
+
this.$emit("load");
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Terminate the component on load.
|
|
102
|
+
*/
|
|
103
|
+
onLoad() {
|
|
104
|
+
this.$terminate();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
FigureVideo
|
|
109
|
+
};
|
|
110
|
+
//# sourceMappingURL=FigureVideo.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/ui/atoms/FigureVideo/FigureVideo.ts"],
|
|
4
|
+
"sourcesContent": ["import { withMountWhenInView } from '@studiometa/js-toolkit';\nimport type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport { Transition } from '../../primitives/index.js';\nimport { loadImage } from '../index.js';\n\nexport interface FigureVideoProps extends BaseProps {\n $refs: {\n video: HTMLVideoElement;\n };\n $options: {\n lazy: boolean;\n };\n}\n\n/**\n * FigureVideo class.\n */\nexport class FigureVideo<T extends BaseProps = BaseProps> extends withMountWhenInView<Transition>(\n Transition,\n {\n threshold: [0, 1],\n },\n)<T & FigureVideoProps> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...Transition.config,\n name: 'FigureVideo',\n emits: ['load'],\n refs: ['video'],\n options: {\n ...Transition.config.options,\n lazy: Boolean,\n },\n };\n\n /**\n * Get the transition target.\n */\n get target(): HTMLVideoElement {\n return this.$refs.video;\n }\n\n /**\n * Get the video sources.\n */\n get sources(): Array<HTMLSourceElement> {\n return Array.from(this.$refs.video.querySelectorAll('source'));\n }\n\n /**\n * Load poster\n */\n loadPoster(): Promise<void|HTMLImageElement> {\n const { video } = this.$refs;\n\n if (!video.dataset.poster) {\n return Promise.resolve();\n }\n\n return loadImage(video.dataset.poster).then(() => {\n video.poster = video.dataset.poster;\n this.$log('fresh poster loaded');\n })\n }\n\n /**\n * Load sources\n * @returns {Promise}\n */\n loadSources(): Promise<void> {\n const { video } = this.$refs;\n\n this.sources.forEach((source) => {\n if (!source.dataset.src) {\n return;\n }\n source.src = source.dataset.src;\n });\n\n return new Promise<void>((resolve) => {\n const loadHandler = () => {\n video.removeEventListener('loadeddata', loadHandler);\n this.$log('fresh sources loaded');\n resolve();\n };\n video.addEventListener('loadeddata', loadHandler);\n video.load();\n });\n }\n\n /**\n * Load\n * @returns {Promise}\n */\n load(): Promise<any[]> {\n return Promise.all([this.loadPoster(), this.loadSources()]);\n }\n\n /**\n * Load on mount.\n */\n async mounted() {\n this.$log('mounted');\n const { video } = this.$refs;\n\n if (!video) {\n throw new Error('[VideoFigure] The `video` ref is required.');\n }\n\n if (!(video instanceof HTMLVideoElement)) {\n throw new Error('[VideoFigure] The `video` ref must be an `<video>` element.');\n }\n\n if (!this.$options.lazy) {\n this.$log('Lazy loading disabled');\n return;\n }\n\n this.$log('start loading');\n await this.load();\n this.$log('all is loaded');\n await this.enter();\n this.$log('transition done');\n this.$emit('load');\n }\n\n /**\n * Terminate the component on load.\n */\n onLoad() {\n this.$terminate();\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,2BAA2B;AAEpC,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAcnB,MAAM,oBAAqD;AAAA,EAChE;AAAA,EACA;AAAA,IACE,WAAW,CAAC,GAAG,CAAC;AAAA,EAClB;AACF,EAAwB;AAAA;AAAA;AAAA;AAAA,EAItB,OAAO,SAAqB;AAAA,IAC1B,GAAG,WAAW;AAAA,IACd,MAAM;AAAA,IACN,OAAO,CAAC,MAAM;AAAA,IACd,MAAM,CAAC,OAAO;AAAA,IACd,SAAS;AAAA,MACP,GAAG,WAAW,OAAO;AAAA,MACrB,MAAM;AAAA,IACR;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,SAA2B;AAC7B,WAAO,KAAK,MAAM;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,UAAoC;AACtC,WAAO,MAAM,KAAK,KAAK,MAAM,MAAM,iBAAiB,QAAQ,CAAC;AAAA,EAC/D;AAAA;AAAA;AAAA;AAAA,EAKA,aAA6C;AAC3C,UAAM,EAAE,MAAM,IAAI,KAAK;AAEvB,QAAI,CAAC,MAAM,QAAQ,QAAQ;AACzB,aAAO,QAAQ,QAAQ;AAAA,IACzB;AAEA,WAAO,UAAU,MAAM,QAAQ,MAAM,EAAE,KAAK,MAAM;AAChD,YAAM,SAAS,MAA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+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
{#
|
|
2
|
+
/**
|
|
3
|
+
* @file
|
|
4
|
+
* Video Figure component.
|
|
5
|
+
*
|
|
6
|
+
* @param string $src
|
|
7
|
+
* @param array $sources
|
|
8
|
+
* @param string $poster
|
|
9
|
+
* @param string $placeholder
|
|
10
|
+
* @param number $width
|
|
11
|
+
* @param number $height
|
|
12
|
+
* @param string $caption
|
|
13
|
+
* @param boolean $lazy
|
|
14
|
+
* @param 'cover'|'contain'|'fill'|'none' $fit
|
|
15
|
+
* Define how the video will fit.
|
|
16
|
+
* @param boolean $absolute
|
|
17
|
+
* Use absolute position on the video holder instead of relative.
|
|
18
|
+
* @param boolean $inline
|
|
19
|
+
* Wether to enable the display of the figure inline or not. When `inline`, the root element
|
|
20
|
+
* will have a max-width set corresponding to the `width` given. Use with caution.
|
|
21
|
+
* @param string $placeholder
|
|
22
|
+
* Use a custom placeholder.
|
|
23
|
+
* @param string $placeholder_color
|
|
24
|
+
* Set an hexadecimal custom color for the generic placeholder.
|
|
25
|
+
* @param array $attr
|
|
26
|
+
* Custom attributes for the root element.
|
|
27
|
+
* @param array $inner_attr
|
|
28
|
+
* Custom attributes for the inner element.
|
|
29
|
+
* @param array $video_attr
|
|
30
|
+
* Custom attributes for the video element.
|
|
31
|
+
* @param array $caption_attr
|
|
32
|
+
* Custom attributes for the caption element.
|
|
33
|
+
*
|
|
34
|
+
* @block $caption
|
|
35
|
+
* Use this block to customize the video's caption.
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
#}
|
|
39
|
+
|
|
40
|
+
{% set absolute = absolute|default(false) %}
|
|
41
|
+
{% set inline = inline|default(false) %}
|
|
42
|
+
{% set fit = fit ?? null %}
|
|
43
|
+
{% set height = height|default(100) %}
|
|
44
|
+
{% set width = width|default(100) %}
|
|
45
|
+
{% set lazy = lazy ?? true %}
|
|
46
|
+
{% set placeholder = placeholder|default('') %}
|
|
47
|
+
|
|
48
|
+
{% if placeholder is empty %}
|
|
49
|
+
{% set placeholder_color = placeholder_color|default('#eee') %}
|
|
50
|
+
{%- set placeholder_markup -%}
|
|
51
|
+
<svg xmlns="http://www.w3.org/2000/svg"
|
|
52
|
+
viewbox="0 0 {{ width }} {{ height }}"
|
|
53
|
+
width="{{ width }}"
|
|
54
|
+
height="{{ height }}">
|
|
55
|
+
<rect x="0" y="0" width="{{ width }}" height="{{ height }}" fill="{{ placeholder_color }}" />
|
|
56
|
+
</svg>
|
|
57
|
+
{%- endset -%}
|
|
58
|
+
{% set placeholder = 'data:image/svg+xml,%s'|format(placeholder_markup|url_encode) %}
|
|
59
|
+
{% endif %}
|
|
60
|
+
|
|
61
|
+
{% set attributes =
|
|
62
|
+
merge_html_attributes(
|
|
63
|
+
attr ?? null,
|
|
64
|
+
{ data_component: 'FigureVideo', class: ['figure-video', 'w-full'] },
|
|
65
|
+
{
|
|
66
|
+
style: { height: absolute ? '100%' : '', maxWidth: inline ? width ~ 'px' : '' },
|
|
67
|
+
data_option_lazy: lazy
|
|
68
|
+
}
|
|
69
|
+
)
|
|
70
|
+
%}
|
|
71
|
+
|
|
72
|
+
{% set video_attributes =
|
|
73
|
+
merge_html_attributes(
|
|
74
|
+
video_attr ?? null,
|
|
75
|
+
{ class: 'figure-video__video' },
|
|
76
|
+
{
|
|
77
|
+
class: [
|
|
78
|
+
'absolute inset-0 w-full max-w-none h-full',
|
|
79
|
+
{
|
|
80
|
+
'object-cover': fit == 'cover',
|
|
81
|
+
'object-contain': fit == 'contain',
|
|
82
|
+
'object-fill': fit == 'fill',
|
|
83
|
+
'object-none': fit == 'none'
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
poster: lazy and poster ? placeholder : poster,
|
|
87
|
+
data_poster: lazy and poster ? poster : false,
|
|
88
|
+
width: width|default(false),
|
|
89
|
+
height: height|default(false),
|
|
90
|
+
playsinline: true,
|
|
91
|
+
autoplay: true,
|
|
92
|
+
controls: false,
|
|
93
|
+
loop: true,
|
|
94
|
+
muted: true,
|
|
95
|
+
preload: lazy ? false : preload ?? false,
|
|
96
|
+
data_ref: 'video'
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
%}
|
|
100
|
+
|
|
101
|
+
{% set inner_attributes =
|
|
102
|
+
merge_html_attributes(
|
|
103
|
+
inner_attr ?? null,
|
|
104
|
+
{ class: ['figure-video__inner'] },
|
|
105
|
+
{
|
|
106
|
+
class: absolute ? ['absolute', 'inset-0'] : ['relative', 'w-full', 'h-0'],
|
|
107
|
+
style: { paddingTop: absolute ? '' : height * 100 / width ~ '%' }
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
%}
|
|
111
|
+
|
|
112
|
+
{% set caption_attributes =
|
|
113
|
+
merge_html_attributes(caption_attr ?? null, { class: 'figure-video__caption' })
|
|
114
|
+
%}
|
|
115
|
+
|
|
116
|
+
<figure {{ html_attributes(attributes) }}>
|
|
117
|
+
<div {{ html_attributes(inner_attributes) }}>
|
|
118
|
+
<video {{ html_attributes(video_attributes) }}>
|
|
119
|
+
{% block sources %}
|
|
120
|
+
{% if sources is not empty %}
|
|
121
|
+
{% for source in sources %}
|
|
122
|
+
<source {{
|
|
123
|
+
html_attributes(
|
|
124
|
+
merge_html_attributes(
|
|
125
|
+
source,
|
|
126
|
+
{
|
|
127
|
+
src: lazy ? false : source.src|default(false),
|
|
128
|
+
data_src: lazy ? source.src|default(false) : false
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
}} />
|
|
133
|
+
{% endfor %}
|
|
134
|
+
{% else %}
|
|
135
|
+
<source {{
|
|
136
|
+
html_attributes({
|
|
137
|
+
src: lazy ? false : src|default(false),
|
|
138
|
+
data_src: lazy ? src|default(false) : false
|
|
139
|
+
})
|
|
140
|
+
}} />
|
|
141
|
+
{% endif %}
|
|
142
|
+
{% endblock %}
|
|
143
|
+
</video>
|
|
144
|
+
</div>
|
|
145
|
+
{% if caption is defined %}
|
|
146
|
+
{% block caption %}
|
|
147
|
+
<figcaption {{ html_attributes(caption_attributes) }}>
|
|
148
|
+
{{ caption }}
|
|
149
|
+
</figcaption>
|
|
150
|
+
{% endblock %}
|
|
151
|
+
{% endif %}
|
|
152
|
+
</figure>
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// packages/ui/atoms/FigureVideo/FigureVideoTwicpics.ts
|
|
20
|
+
var FigureVideoTwicpics_exports = {};
|
|
21
|
+
__export(FigureVideoTwicpics_exports, {
|
|
22
|
+
FigureVideoTwicpics: () => FigureVideoTwicpics
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(FigureVideoTwicpics_exports);
|
|
25
|
+
var import_utils = require("@studiometa/js-toolkit/utils");
|
|
26
|
+
var import__ = require("../index.cjs");
|
|
27
|
+
var import_FigureVideo = require("./FigureVideo.cjs");
|
|
28
|
+
function normalizeSize(that, prop) {
|
|
29
|
+
const { step } = that.$options;
|
|
30
|
+
return Math.ceil(that.$refs.video[prop] / step) * step;
|
|
31
|
+
}
|
|
32
|
+
var FigureVideoTwicpics = class extends import_FigureVideo.FigureVideo {
|
|
33
|
+
/**
|
|
34
|
+
* Config.
|
|
35
|
+
*/
|
|
36
|
+
static config = {
|
|
37
|
+
...import_FigureVideo.FigureVideo.config,
|
|
38
|
+
name: "FigureVideoTwicpics",
|
|
39
|
+
options: {
|
|
40
|
+
...import_FigureVideo.FigureVideo.config.options,
|
|
41
|
+
transform: String,
|
|
42
|
+
domain: String,
|
|
43
|
+
path: String,
|
|
44
|
+
step: {
|
|
45
|
+
type: Number,
|
|
46
|
+
default: 50
|
|
47
|
+
},
|
|
48
|
+
mode: {
|
|
49
|
+
type: String,
|
|
50
|
+
default: "cover"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Get the Twicpics path.
|
|
56
|
+
*/
|
|
57
|
+
get path() {
|
|
58
|
+
return (0, import_utils.withoutTrailingSlash)((0, import_utils.withoutLeadingSlash)(this.$options.path));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get the Twicpics domain.
|
|
62
|
+
*/
|
|
63
|
+
get domain() {
|
|
64
|
+
if (this.$options.domain) {
|
|
65
|
+
return this.$options.domain;
|
|
66
|
+
}
|
|
67
|
+
const url = new URL(this.sources[0].dataset.src);
|
|
68
|
+
return url.host;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Format the source for Twicpics.
|
|
72
|
+
* @param {string} src
|
|
73
|
+
* @param {Array} options
|
|
74
|
+
* @returns {string}
|
|
75
|
+
*/
|
|
76
|
+
formatSrc(src, options = []) {
|
|
77
|
+
const url = new URL(src, "https://localhost");
|
|
78
|
+
url.host = this.domain;
|
|
79
|
+
url.port = "";
|
|
80
|
+
if (this.path && !url.pathname.startsWith((0, import_utils.withLeadingSlash)(this.path))) {
|
|
81
|
+
url.pathname = `/${this.path}${url.pathname}`;
|
|
82
|
+
}
|
|
83
|
+
const width = normalizeSize(this, "offsetWidth");
|
|
84
|
+
const height = normalizeSize(this, "offsetHeight");
|
|
85
|
+
this.$log(this.$options.mode, width, height);
|
|
86
|
+
url.searchParams.set(
|
|
87
|
+
"twic",
|
|
88
|
+
["v1", this.$options.transform, `${this.$options.mode}=${width}x${height}`, ...options].filter(Boolean).join("/")
|
|
89
|
+
);
|
|
90
|
+
url.search = decodeURIComponent(url.search);
|
|
91
|
+
return url.toString();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Load poster
|
|
95
|
+
*/
|
|
96
|
+
loadPoster() {
|
|
97
|
+
const { video } = this.$refs;
|
|
98
|
+
if (!video.dataset.poster) {
|
|
99
|
+
return Promise.resolve();
|
|
100
|
+
}
|
|
101
|
+
const twicPoster = this.formatSrc(video.dataset.poster);
|
|
102
|
+
return (0, import__.loadImage)(twicPoster).then(() => {
|
|
103
|
+
video.poster = twicPoster;
|
|
104
|
+
this.$log("fresh poster loaded");
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Load sources
|
|
109
|
+
*/
|
|
110
|
+
loadSources() {
|
|
111
|
+
const { video } = this.$refs;
|
|
112
|
+
this.sources.forEach((source) => {
|
|
113
|
+
if (!source.dataset.src) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
source.src = this.formatSrc(
|
|
117
|
+
source.dataset.src,
|
|
118
|
+
source.dataset.output ? [`output=${source.dataset.output}`] : []
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
return new Promise((resolve) => {
|
|
122
|
+
const loadHandler = () => {
|
|
123
|
+
resolve();
|
|
124
|
+
video.removeEventListener("canplaythrough", loadHandler);
|
|
125
|
+
this.$log("fresh sources loaded");
|
|
126
|
+
};
|
|
127
|
+
video.addEventListener("canplaythrough", loadHandler);
|
|
128
|
+
this.$refs.video.width = normalizeSize(this, "offsetWidth");
|
|
129
|
+
this.$refs.video.height = normalizeSize(this, "offsetHeight");
|
|
130
|
+
video.load();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Reassign the source from the original on resize.
|
|
135
|
+
*/
|
|
136
|
+
async resized() {
|
|
137
|
+
const width = normalizeSize(this, "offsetWidth");
|
|
138
|
+
const height = normalizeSize(this, "offsetHeight");
|
|
139
|
+
if (width === this.$refs.video.width && height === this.$refs.video.height) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
this.$refs.video.width = width;
|
|
143
|
+
this.$refs.video.height = height;
|
|
144
|
+
await this.load();
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Do not terminate on image load as we need to set the src on resize.
|
|
148
|
+
*/
|
|
149
|
+
onLoad() {
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
if (module.exports.default) module.exports = module.exports.default;
|
|
153
|
+
//# sourceMappingURL=FigureVideoTwicpics.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../packages/ui/atoms/FigureVideo/FigureVideoTwicpics.ts"],
|
|
4
|
+
"sourcesContent": ["import type { BaseConfig, BaseProps } from '@studiometa/js-toolkit';\nimport {\n withLeadingSlash,\n withoutLeadingSlash,\n withoutTrailingSlash,\n} from '@studiometa/js-toolkit/utils';\nimport { loadImage } from '../index.js';\nimport { FigureVideo } from './FigureVideo.js';\n\nexport interface FigureVideoTwicpicsProps extends BaseProps {\n $refs: {\n video: HTMLVideoElement;\n };\n $options: {\n lazy: boolean;\n transform: string;\n domain: string;\n path: string;\n step: number;\n mode: string;\n };\n}\n\n/**\n * Normalize the given size to the step option.\n */\n// eslint-disable-next-line no-use-before-define\nfunction normalizeSize(that: FigureVideoTwicpics, prop: string): number {\n const { step } = that.$options;\n return Math.ceil(that.$refs.video[prop] / step) * step;\n}\n\n/**\n * FigureVideo class.\n *\n * Manager lazyloading image sources.\n */\nexport class FigureVideoTwicpics<T extends BaseProps = BaseProps> extends FigureVideo<\n T & FigureVideoTwicpicsProps\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n ...FigureVideo.config,\n name: 'FigureVideoTwicpics',\n options: {\n ...FigureVideo.config.options,\n transform: String,\n domain: String,\n path: String,\n step: {\n type: Number,\n default: 50,\n },\n mode: {\n type: String,\n default: 'cover',\n },\n },\n };\n\n /**\n * Get the Twicpics path.\n */\n get path(): string {\n return withoutTrailingSlash(withoutLeadingSlash(this.$options.path));\n }\n\n /**\n * Get the Twicpics domain.\n */\n get domain(): string {\n if (this.$options.domain) {\n return this.$options.domain;\n }\n const url = new URL(this.sources[0].dataset.src);\n return url.host;\n }\n\n /**\n * Format the source for Twicpics.\n * @param {string} src\n * @param {Array} options\n * @returns {string}\n */\n formatSrc(src: string, options: Array<string> = []): string {\n const url = new URL(src, 'https://localhost');\n url.host = this.domain;\n url.port = '';\n\n if (this.path && !url.pathname.startsWith(withLeadingSlash(this.path))) {\n url.pathname = `/${this.path}${url.pathname}`;\n }\n\n const width = normalizeSize(this, 'offsetWidth');\n const height = normalizeSize(this, 'offsetHeight');\n\n this.$log(this.$options.mode, width, height);\n\n url.searchParams.set(\n 'twic',\n ['v1', this.$options.transform, `${this.$options.mode}=${width}x${height}`, ...options]\n .filter(Boolean)\n .join('/'),\n );\n\n url.search = decodeURIComponent(url.search);\n\n return url.toString();\n }\n\n /**\n * Load poster\n */\n loadPoster(): Promise<void|HTMLImageElement> {\n const { video } = this.$refs;\n\n if (!video.dataset.poster) {\n return Promise.resolve();\n }\n\n const twicPoster = this.formatSrc(video.dataset.poster);\n\n return loadImage(twicPoster).then(() => {\n video.poster = twicPoster;\n this.$log('fresh poster loaded');\n });\n }\n\n /**\n * Load sources\n */\n loadSources(): Promise<void> {\n const { video } = this.$refs;\n\n this.sources.forEach((source) => {\n if (!source.dataset.src) {\n return;\n }\n source.src = this.formatSrc(\n source.dataset.src,\n source.dataset.output ? [`output=${source.dataset.output}`] : [],\n );\n });\n\n return new Promise((resolve) => {\n const loadHandler = () => {\n resolve();\n video.removeEventListener('canplaythrough', loadHandler);\n this.$log('fresh sources loaded');\n };\n\n video.addEventListener('canplaythrough', loadHandler);\n\n this.$refs.video.width = normalizeSize(this, 'offsetWidth');\n this.$refs.video.height = normalizeSize(this, 'offsetHeight');\n\n video.load();\n });\n }\n\n /**\n * Reassign the source from the original on resize.\n */\n async resized() {\n const width = normalizeSize(this, 'offsetWidth');\n const height = normalizeSize(this, 'offsetHeight');\n\n if (width === this.$refs.video.width && height === this.$refs.video.height) {\n return;\n }\n\n this.$refs.video.width = width;\n this.$refs.video.height = height;\n\n await this.load();\n }\n\n /**\n * Do not terminate on image load as we need to set the src on resize.\n */\n onLoad() {\n // Do not terminate on image load as we need.\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAIO;AACP,eAA0B;AAC1B,yBAA4B;AAoB5B,SAAS,cAAc,MAA2B,MAAsB;AACtE,QAAM,EAAE,KAAK,IAAI,KAAK;AACtB,SAAO,KAAK,KAAK,KAAK,MAAM,MAAM,IAAI,IAAI,IAAI,IAAI;AACpD;AAOO,IAAM,sBAAN,cAAmE,+BAExE;AAAA;AAAA;AAAA;AAAA,EAIA,OAAO,SAAqB;AAAA,IAC1B,GAAG,+BAAY;AAAA,IACf,MAAM;AAAA,IACN,SAAS;AAAA,MACP,GAAG,+BAAY,OAAO;AAAA,MACtB,WAAW;AAAA,MACX,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,MAAM;AAAA,QACJ,MAAM;AAAA,QACN,SAAS;AAAA,MACX;AAAA,MACA,MAAM;AAAA,QACJ,MAAM;AAAA,QACN,SAAS;AAAA,MACX;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,OAAe;AACjB,eAAO,uCAAqB,kCAAoB,KAAK,SAAS,IAAI,CAAC;AAAA,EACrE;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,SAAiB;AACnB,QAAI,KAAK,S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