@fluid-topics/ft-content-watermark 1.4.5
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/README.md +28 -0
- package/build/ft-content-watermark.d.ts +15 -0
- package/build/ft-content-watermark.js +73 -0
- package/build/ft-content-watermark.light.js +179 -0
- package/build/ft-content-watermark.min.js +429 -0
- package/build/ft-content-watermark.properties.d.ts +2 -0
- package/build/ft-content-watermark.properties.js +1 -0
- package/build/ft-content-watermark.styles.d.ts +4 -0
- package/build/ft-content-watermark.styles.js +26 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +6 -0
- package/package.json +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Generic component that overlays a watermark on top of FT content
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npm install @fluid-topics/ft-content-watermark
|
|
7
|
+
yarn add @fluid-topics/ft-content-watermark
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { html } from "lit"
|
|
14
|
+
import { FtWatermark } from "@fluid-topics/public-api"
|
|
15
|
+
import "@fluid-topics/ft-content-watermark"
|
|
16
|
+
|
|
17
|
+
function render() {
|
|
18
|
+
const watermark: FtWatermark = {
|
|
19
|
+
color: "red",
|
|
20
|
+
opacity: 0.3,
|
|
21
|
+
text: ["Internal use only"],
|
|
22
|
+
}
|
|
23
|
+
return html`
|
|
24
|
+
<ft-content-watermark .watermark=${ watermark }
|
|
25
|
+
.heightReference=${ this.offsetParent }></ft-content-watermark>
|
|
26
|
+
`
|
|
27
|
+
}
|
|
28
|
+
```
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FtContentWatermarkProperties } from "./ft-content-watermark.properties";
|
|
2
|
+
import { PropertyValues } from "lit";
|
|
3
|
+
import { FtWatermark } from "@fluid-topics/public-api";
|
|
4
|
+
import { FtLitElement } from "@fluid-topics/ft-wc-utils";
|
|
5
|
+
export declare class FtContentWatermark extends FtLitElement implements FtContentWatermarkProperties {
|
|
6
|
+
svg: SVGSVGElement;
|
|
7
|
+
watermark?: FtWatermark;
|
|
8
|
+
heightReference?: HTMLElement;
|
|
9
|
+
height: number;
|
|
10
|
+
static styles: import("lit").CSSResult[];
|
|
11
|
+
protected render(): unknown;
|
|
12
|
+
protected updated(props: PropertyValues<FtContentWatermark>): void;
|
|
13
|
+
private readonly resizeObserver;
|
|
14
|
+
disconnectedCallback(): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html, nothing, svg, } from "lit";
|
|
8
|
+
import { property, query, state, } from "lit/decorators.js";
|
|
9
|
+
import { styles } from "./ft-content-watermark.styles";
|
|
10
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
11
|
+
import { FtLitElement } from "@fluid-topics/ft-wc-utils";
|
|
12
|
+
import { FtTypographyBody1 } from "@fluid-topics/ft-typography";
|
|
13
|
+
class FtContentWatermark extends FtLitElement {
|
|
14
|
+
constructor() {
|
|
15
|
+
super(...arguments);
|
|
16
|
+
this.height = 0;
|
|
17
|
+
this.resizeObserver = new ResizeObserver(([reference]) => {
|
|
18
|
+
this.height = Math.min(reference.contentRect.height, reference.contentRect.width);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
render() {
|
|
22
|
+
var _a, _b, _c;
|
|
23
|
+
return this.watermark ? html `
|
|
24
|
+
<style>
|
|
25
|
+
.ft-watermark {
|
|
26
|
+
height: ${this.height}px;
|
|
27
|
+
}
|
|
28
|
+
</style>
|
|
29
|
+
<div class="ft-watermark-container ft-typography--body1">
|
|
30
|
+
<svg xmlns="http://www.w3.org/2000/svg"
|
|
31
|
+
class="ft-watermark"
|
|
32
|
+
part="svg">
|
|
33
|
+
<text x="0" y="0"
|
|
34
|
+
text-anchor="middle"
|
|
35
|
+
transform="rotate(-45)"
|
|
36
|
+
fill="${(_a = this.watermark) === null || _a === void 0 ? void 0 : _a.color}"
|
|
37
|
+
fill-opacity="${(_b = this.watermark) === null || _b === void 0 ? void 0 : _b.opacity}%">
|
|
38
|
+
${repeat(((_c = this.watermark) === null || _c === void 0 ? void 0 : _c.text) || [], (item) => svg `<tspan x="0" dy="1.2em">${item}</tspan>`)}
|
|
39
|
+
</text>
|
|
40
|
+
</svg>
|
|
41
|
+
</div>
|
|
42
|
+
` : nothing;
|
|
43
|
+
}
|
|
44
|
+
updated(props) {
|
|
45
|
+
super.updated(props);
|
|
46
|
+
if (props.has("watermark") && this.watermark) {
|
|
47
|
+
const bbox = this.svg.getBBox({ stroke: true });
|
|
48
|
+
this.svg.setAttribute("viewBox", bbox.x + " " + bbox.y + " " + bbox.width + " " + bbox.height);
|
|
49
|
+
}
|
|
50
|
+
if (props.has("heightReference") && this.heightReference) {
|
|
51
|
+
this.resizeObserver.disconnect();
|
|
52
|
+
this.resizeObserver.observe(this.heightReference);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
disconnectedCallback() {
|
|
56
|
+
super.disconnectedCallback();
|
|
57
|
+
this.resizeObserver.disconnect();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
FtContentWatermark.styles = [styles, FtTypographyBody1];
|
|
61
|
+
__decorate([
|
|
62
|
+
query(".ft-watermark")
|
|
63
|
+
], FtContentWatermark.prototype, "svg", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
property({ attribute: false })
|
|
66
|
+
], FtContentWatermark.prototype, "watermark", void 0);
|
|
67
|
+
__decorate([
|
|
68
|
+
property({ attribute: false })
|
|
69
|
+
], FtContentWatermark.prototype, "heightReference", void 0);
|
|
70
|
+
__decorate([
|
|
71
|
+
state()
|
|
72
|
+
], FtContentWatermark.prototype, "height", void 0);
|
|
73
|
+
export { FtContentWatermark };
|