@teipublisher/pb-components 1.42.7 → 1.43.1

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.
@@ -1,75 +1,76 @@
1
- import { LitElement, html, css } from 'lit-element';
2
- import { pbMixin } from './pb-mixin.js';
3
- import { translate } from "./pb-i18n.js";
4
- import '@polymer/paper-icon-button';
5
- import '@polymer/iron-icons';
6
-
7
- /**
8
- * A component with a button which copies the contained content to the clipboard.
9
- * Use for the typical 'quote this content as' hints on a webpage.
10
- *
11
- * @slot content - contains the actual content to copy to the clipboard
12
- */
13
- export class PbClipboard extends pbMixin(LitElement) {
14
- static get properties() {
15
- return {
16
- /**
17
- * Label to display above the text to be copied
18
- */
19
- label: {
20
- type: String
21
- },
22
- ...super.properties
23
- };
24
- }
25
-
26
- constructor() {
27
- super();
28
- this.label = 'clipboard.label';
29
- }
30
-
31
- render() {
32
- return html`
33
- <h3>${translate(this.label)}</h3>
34
- <div>
35
- <slot></slot>
36
- <paper-icon-button icon="icons:content-copy" @click="${this._copy}"
37
- title="${translate('clipboard.copy')}"></paper-icon-button>
38
- </div>
39
- `;
40
- }
41
-
42
- /**
43
- * Copy text content from the <slot> to the clipboard
44
- */
45
- _copy() {
46
- const slot = this.shadowRoot.querySelector('slot');
47
- // first import nodes from the slot into a temporary div
48
- const content = document.createElement('div');
49
- slot.assignedNodes().forEach((node) => {
50
- content.appendChild(document.importNode(node, true));
51
- });
52
- // copy the innerText of the temp div into the clipboard
53
- navigator.clipboard.writeText(content.innerText);
54
- }
55
-
56
- static get styles() {
57
- return css`
58
- :host {
59
- display: block;
60
- }
61
- h3 {
62
- margin: 0;
63
- font-size: .85em;
64
- font-weight: normal;
65
- color: #3a3a3a;
66
- }
67
- div {
68
- display: flex;
69
- align-items: center;
70
- padding: 0 16px;
71
- }
72
- `;
73
- }
74
- }
1
+ import { LitElement, html, css } from 'lit-element';
2
+ import { pbMixin } from './pb-mixin.js';
3
+ import { translate } from "./pb-i18n.js";
4
+ import { themableMixin } from "./theming.js";
5
+ import '@polymer/paper-icon-button';
6
+ import '@polymer/iron-icons';
7
+
8
+ /**
9
+ * A component with a button which copies the contained content to the clipboard.
10
+ * Use for the typical 'quote this content as' hints on a webpage.
11
+ *
12
+ * @slot content - contains the actual content to copy to the clipboard
13
+ */
14
+ export class PbClipboard extends themableMixin(pbMixin(LitElement)) {
15
+ static get properties() {
16
+ return {
17
+ /**
18
+ * Label to display above the text to be copied
19
+ */
20
+ label: {
21
+ type: String
22
+ },
23
+ ...super.properties
24
+ };
25
+ }
26
+
27
+ constructor() {
28
+ super();
29
+ this.label = 'clipboard.label';
30
+ }
31
+
32
+ render() {
33
+ return html`
34
+ <h3>${translate(this.label)}</h3>
35
+ <div>
36
+ <slot></slot>
37
+ <paper-icon-button icon="icons:content-copy" @click="${this._copy}"
38
+ title="${translate('clipboard.copy')}"></paper-icon-button>
39
+ </div>
40
+ `;
41
+ }
42
+
43
+ /**
44
+ * Copy text content from the <slot> to the clipboard
45
+ */
46
+ _copy() {
47
+ const slot = this.shadowRoot.querySelector('slot');
48
+ // first import nodes from the slot into a temporary div
49
+ const content = document.createElement('div');
50
+ slot.assignedNodes().forEach((node) => {
51
+ content.appendChild(document.importNode(node, true));
52
+ });
53
+ // copy the innerText of the temp div into the clipboard
54
+ navigator.clipboard.writeText(content.innerText);
55
+ }
56
+
57
+ static get styles() {
58
+ return css`
59
+ :host {
60
+ display: block;
61
+ }
62
+ h3 {
63
+ margin: 0;
64
+ font-size: .85em;
65
+ font-weight: normal;
66
+ color: #3a3a3a;
67
+ }
68
+ div {
69
+ display: flex;
70
+ align-items: center;
71
+ padding: 0 16px;
72
+ }
73
+ `;
74
+ }
75
+ }
75
76
  customElements.define('pb-clipboard', PbClipboard);
@@ -1,194 +1,195 @@
1
- import { LitElement, html, css } from 'lit-element';
2
- import "prismjs/prism";
3
- import 'prismjs/components/prism-xquery';
4
- import 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace';
5
- import 'prismjs/plugins/line-numbers/prism-line-numbers';
6
- import { resolveURL, getCSSProperty } from './utils.js';
7
-
8
- const PRISM_THEMES = new Map();
9
-
10
- function loadTheme(theme) {
11
- const themeName = theme === 'default' ? 'prism.css' : `prism-${theme}.css`;
12
- if (PRISM_THEMES.has(themeName)) {
13
- console.log('Using cached theme: %s', themeName);
14
- return PRISM_THEMES.get(themeName);
15
- }
16
-
17
- const promise = new Promise((resolve) => {
18
- const resource = resolveURL('../css/prismjs/') + themeName;
19
- console.log('<pb-code-highlight> loading theme %s from %s', theme, resource);
20
- fetch(resource)
21
- .then(response => response.text())
22
- .catch(() => resolve(''))
23
- .then(text => {
24
- resolve(html`<style>${text}</style>`);
25
- });
26
- });
27
- PRISM_THEMES.set(themeName, promise);
28
- return promise;
29
- }
30
-
31
- /**
32
- * Highlight a code snippet. The snippet may either be passed in a template child
33
- * element, which could contain HTML or text. If no template child is present, the
34
- * component will take any text content contained in it and highlight it. One can also
35
- * pass the code to be highlighted in the `code` property.
36
- *
37
- * @cssprop [--pb-code-highlight-white-space=pre] - configures line wrapping
38
- * @cssprop [--pb-code-highlight-theme=default] - configures the default theme to be used
39
- */
40
- export class PbCodeHighlight extends LitElement {
41
- static get properties() {
42
- return {
43
- /**
44
- * The language to be used for syntax highlighting.
45
- */
46
- language: {
47
- type: String
48
- },
49
- /**
50
- * The code to be highlighted as a string. If not set,
51
- * this will be populated from either a template child element
52
- * or the element's text content.
53
- */
54
- code: {
55
- type: String
56
- },
57
- /**
58
- * Highlighting theme to use: 'coy', 'dark', 'funky', 'okaida', 'solarizedlight',
59
- * 'tomorrow', 'twilight' or 'default'.
60
- */
61
- theme: {
62
- type: String
63
- },
64
- lineNumbers: {
65
- type: Boolean,
66
- attribute: 'line-numbers'
67
- },
68
- _themeStyles: {
69
- type: String
70
- }
71
- };
72
- }
73
-
74
- constructor() {
75
- super();
76
- this.language = 'xml';
77
- this.theme = 'default';
78
- this.lineNumbers = false;
79
- this._themeStyles = null;
80
- }
81
-
82
- connectedCallback() {
83
- super.connectedCallback();
84
- let theme = this.getAttribute('theme');
85
- if (theme === null) {
86
- theme = getCSSProperty(this, '--pb-code-highlight-theme', 'default');
87
- this.setAttribute('theme', theme);
88
- }
89
- }
90
-
91
- firstUpdated() {
92
- super.firstUpdated();
93
-
94
- if (!this.code) {
95
- const template = this.querySelector('template');
96
- if (template) {
97
- this.code = Prism.plugins.NormalizeWhitespace.normalize(template.innerHTML);
98
- } else {
99
- this.code = Prism.plugins.NormalizeWhitespace.normalize(this.textContent);
100
- }
101
- }
102
- }
103
-
104
- attributeChangedCallback(name, oldValue, newValue) {
105
- super.attributeChangedCallback(name, oldValue, newValue);
106
- switch (name) {
107
- case 'theme':
108
- loadTheme(newValue).then(loadedStyles => {
109
- this._themeStyles = loadedStyles;
110
- });
111
- break;
112
- default:
113
- break;
114
- }
115
- }
116
-
117
- updated(changedProperties) {
118
- super.updated(changedProperties);
119
- if (changedProperties.has('code')) {
120
- this.highlight();
121
- }
122
- }
123
-
124
- highlight() {
125
- Prism.highlightAllUnder(this.shadowRoot);
126
- }
127
-
128
- render() {
129
- if (this.code) {
130
- return html`
131
- ${this._themeStyles}
132
- <pre class="${this.lineNumbers ? 'line-numbers' : ''} language-${this.language}"><code>${this.code}</code></pre>
133
- `;
134
- }
135
- return html`<pre class="line-numbers"><code><code></pre>`;
136
- }
137
-
138
- static get styles() {
139
- return css`
140
- :host {
141
- display: block;
142
- }
143
- pre[class*='language-'] {
144
- margin: 0;
145
- }
146
- code[class*='language-'] {
147
- white-space: var(--pb-code-highlight-white-space, pre);
148
- }
149
- pre.line-numbers {
150
- position: relative;
151
- padding-left: 3.8em;
152
- counter-reset: linenumber;
153
- }
154
-
155
- pre.line-numbers > code {
156
- position: relative;
157
- white-space: inherit;
158
- }
159
-
160
- .line-numbers .line-numbers-rows {
161
- position: absolute;
162
- pointer-events: none;
163
- top: 0;
164
- font-size: 100%;
165
- left: -3.8em;
166
- width: 3em; /* works for line-numbers below 1000 lines */
167
- letter-spacing: -1px;
168
- border-right: 1px solid #999;
169
-
170
- -webkit-user-select: none;
171
- -moz-user-select: none;
172
- -ms-user-select: none;
173
- user-select: none;
174
-
175
- }
176
-
177
- .line-numbers-rows > span {
178
- pointer-events: none;
179
- display: block;
180
- counter-increment: linenumber;
181
- height: auto !important;
182
- }
183
-
184
- .line-numbers-rows > span:before {
185
- content: counter(linenumber);
186
- color: #999;
187
- display: block;
188
- padding-right: 0.8em;
189
- text-align: right;
190
- }
191
- `;
192
- }
193
- }
1
+ import { LitElement, html, css } from 'lit-element';
2
+ import "prismjs/prism";
3
+ import 'prismjs/components/prism-xquery';
4
+ import 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace';
5
+ import 'prismjs/plugins/line-numbers/prism-line-numbers';
6
+ import { resolveURL, getCSSProperty } from './utils.js';
7
+ import { themableMixin } from "./theming.js";
8
+
9
+ const PRISM_THEMES = new Map();
10
+
11
+ function loadTheme(theme) {
12
+ const themeName = theme === 'default' ? 'prism.css' : `prism-${theme}.css`;
13
+ if (PRISM_THEMES.has(themeName)) {
14
+ console.log('Using cached theme: %s', themeName);
15
+ return PRISM_THEMES.get(themeName);
16
+ }
17
+
18
+ const promise = new Promise((resolve) => {
19
+ const resource = resolveURL('../css/prismjs/') + themeName;
20
+ console.log('<pb-code-highlight> loading theme %s from %s', theme, resource);
21
+ fetch(resource)
22
+ .then(response => response.text())
23
+ .catch(() => resolve(''))
24
+ .then(text => {
25
+ resolve(html`<style>${text}</style>`);
26
+ });
27
+ });
28
+ PRISM_THEMES.set(themeName, promise);
29
+ return promise;
30
+ }
31
+
32
+ /**
33
+ * Highlight a code snippet. The snippet may either be passed in a template child
34
+ * element, which could contain HTML or text. If no template child is present, the
35
+ * component will take any text content contained in it and highlight it. One can also
36
+ * pass the code to be highlighted in the `code` property.
37
+ *
38
+ * @cssprop [--pb-code-highlight-white-space=pre] - configures line wrapping
39
+ * @cssprop [--pb-code-highlight-theme=default] - configures the default theme to be used
40
+ */
41
+ export class PbCodeHighlight extends themableMixin(LitElement) {
42
+ static get properties() {
43
+ return {
44
+ /**
45
+ * The language to be used for syntax highlighting.
46
+ */
47
+ language: {
48
+ type: String
49
+ },
50
+ /**
51
+ * The code to be highlighted as a string. If not set,
52
+ * this will be populated from either a template child element
53
+ * or the element's text content.
54
+ */
55
+ code: {
56
+ type: String
57
+ },
58
+ /**
59
+ * Highlighting theme to use: 'coy', 'dark', 'funky', 'okaida', 'solarizedlight',
60
+ * 'tomorrow', 'twilight' or 'default'.
61
+ */
62
+ theme: {
63
+ type: String
64
+ },
65
+ lineNumbers: {
66
+ type: Boolean,
67
+ attribute: 'line-numbers'
68
+ },
69
+ _themeStyles: {
70
+ type: String
71
+ }
72
+ };
73
+ }
74
+
75
+ constructor() {
76
+ super();
77
+ this.language = 'xml';
78
+ this.theme = 'default';
79
+ this.lineNumbers = false;
80
+ this._themeStyles = null;
81
+ }
82
+
83
+ connectedCallback() {
84
+ super.connectedCallback();
85
+ let theme = this.getAttribute('theme');
86
+ if (theme === null) {
87
+ theme = getCSSProperty(this, '--pb-code-highlight-theme', 'default');
88
+ this.setAttribute('theme', theme);
89
+ }
90
+ }
91
+
92
+ firstUpdated() {
93
+ super.firstUpdated();
94
+
95
+ if (!this.code) {
96
+ const template = this.querySelector('template');
97
+ if (template) {
98
+ this.code = Prism.plugins.NormalizeWhitespace.normalize(template.innerHTML);
99
+ } else {
100
+ this.code = Prism.plugins.NormalizeWhitespace.normalize(this.textContent);
101
+ }
102
+ }
103
+ }
104
+
105
+ attributeChangedCallback(name, oldValue, newValue) {
106
+ super.attributeChangedCallback(name, oldValue, newValue);
107
+ switch (name) {
108
+ case 'theme':
109
+ loadTheme(newValue).then(loadedStyles => {
110
+ this._themeStyles = loadedStyles;
111
+ });
112
+ break;
113
+ default:
114
+ break;
115
+ }
116
+ }
117
+
118
+ updated(changedProperties) {
119
+ super.updated(changedProperties);
120
+ if (changedProperties.has('code')) {
121
+ this.highlight();
122
+ }
123
+ }
124
+
125
+ highlight() {
126
+ Prism.highlightAllUnder(this.shadowRoot);
127
+ }
128
+
129
+ render() {
130
+ if (this.code) {
131
+ return html`
132
+ ${this._themeStyles}
133
+ <pre class="${this.lineNumbers ? 'line-numbers' : ''} language-${this.language}"><code>${this.code}</code></pre>
134
+ `;
135
+ }
136
+ return html`<pre class="line-numbers"><code><code></pre>`;
137
+ }
138
+
139
+ static get styles() {
140
+ return css`
141
+ :host {
142
+ display: block;
143
+ }
144
+ pre[class*='language-'] {
145
+ margin: 0;
146
+ }
147
+ code[class*='language-'] {
148
+ white-space: var(--pb-code-highlight-white-space, pre);
149
+ }
150
+ pre.line-numbers {
151
+ position: relative;
152
+ padding-left: 3.8em;
153
+ counter-reset: linenumber;
154
+ }
155
+
156
+ pre.line-numbers > code {
157
+ position: relative;
158
+ white-space: inherit;
159
+ }
160
+
161
+ .line-numbers .line-numbers-rows {
162
+ position: absolute;
163
+ pointer-events: none;
164
+ top: 0;
165
+ font-size: 100%;
166
+ left: -3.8em;
167
+ width: 3em; /* works for line-numbers below 1000 lines */
168
+ letter-spacing: -1px;
169
+ border-right: 1px solid #999;
170
+
171
+ -webkit-user-select: none;
172
+ -moz-user-select: none;
173
+ -ms-user-select: none;
174
+ user-select: none;
175
+
176
+ }
177
+
178
+ .line-numbers-rows > span {
179
+ pointer-events: none;
180
+ display: block;
181
+ counter-increment: linenumber;
182
+ height: auto !important;
183
+ }
184
+
185
+ .line-numbers-rows > span:before {
186
+ content: counter(linenumber);
187
+ color: #999;
188
+ display: block;
189
+ padding-right: 0.8em;
190
+ text-align: right;
191
+ }
192
+ `;
193
+ }
194
+ }
194
195
  customElements.define('pb-code-highlight', PbCodeHighlight);