@brightspace-ui/core 2.62.0 → 2.64.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/demo/demo-snippet.js +49 -11
- package/custom-elements.json +2 -2
- package/helpers/mathjax.js +60 -46
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import './code-view.js';
|
|
2
|
-
import '../button/button-
|
|
2
|
+
import '../button/button-subtle.js';
|
|
3
3
|
import '../switch/switch.js';
|
|
4
|
+
import '../dropdown/dropdown.js';
|
|
5
|
+
import '../dropdown/dropdown-content.js';
|
|
4
6
|
import { css, html, LitElement } from 'lit';
|
|
5
7
|
|
|
6
8
|
class DemoSnippet extends LitElement {
|
|
@@ -8,13 +10,14 @@ class DemoSnippet extends LitElement {
|
|
|
8
10
|
static get properties() {
|
|
9
11
|
return {
|
|
10
12
|
codeViewHidden: { type: Boolean, reflect: true, attribute: 'code-view-hidden' },
|
|
11
|
-
fullWidth: { type: Boolean, reflect: true },
|
|
13
|
+
fullWidth: { type: Boolean, reflect: true, attribute: 'full-width' },
|
|
12
14
|
noPadding: { type: Boolean, reflect: true, attribute: 'no-padding' },
|
|
13
15
|
overflowHidden: { type: Boolean, reflect: true, attribute: 'overflow-hidden' },
|
|
14
16
|
_code: { type: String },
|
|
15
17
|
_dir: { type: String, attribute: false },
|
|
16
18
|
_fullscreen: { state: true },
|
|
17
19
|
_hasSkeleton: { type: Boolean, attribute: false },
|
|
20
|
+
_settingsPeek: { state: true },
|
|
18
21
|
_skeletonOn: { type: Boolean, reflect: false }
|
|
19
22
|
};
|
|
20
23
|
}
|
|
@@ -40,14 +43,18 @@ class DemoSnippet extends LitElement {
|
|
|
40
43
|
}
|
|
41
44
|
.d2l-demo-snippet-demo-wrapper.fullscreen {
|
|
42
45
|
background-color: white;
|
|
46
|
+
height: fit-content;
|
|
43
47
|
inset: 0;
|
|
44
|
-
|
|
45
|
-
position: fixed;
|
|
48
|
+
position: absolute;
|
|
46
49
|
z-index: 2;
|
|
47
50
|
}
|
|
48
51
|
.d2l-demo-snippet-demo {
|
|
49
52
|
flex: 1 1 auto;
|
|
50
53
|
position: relative;
|
|
54
|
+
translate: 0; /* create stacking context to prevent demos from leaking outside their containers */
|
|
55
|
+
}
|
|
56
|
+
:host([full-width]) .d2l-demo-snippet-demo-wrapper.fullscreen .d2l-demo-snippet-demo {
|
|
57
|
+
width: 100vw;
|
|
51
58
|
}
|
|
52
59
|
:host([overflow-hidden]) .d2l-demo-snippet-demo {
|
|
53
60
|
overflow: hidden;
|
|
@@ -68,6 +75,27 @@ class DemoSnippet extends LitElement {
|
|
|
68
75
|
position: sticky;
|
|
69
76
|
top: 0;
|
|
70
77
|
}
|
|
78
|
+
d2l-dropdown.settings-dropdown {
|
|
79
|
+
background-color: white;
|
|
80
|
+
border-radius: 6px;
|
|
81
|
+
box-shadow: 0 0 0 1px var(--d2l-color-celestine-minus-1);
|
|
82
|
+
position: fixed;
|
|
83
|
+
right: 1rem;
|
|
84
|
+
top: -0.25rem;
|
|
85
|
+
translate: 0 -1.5rem;
|
|
86
|
+
}
|
|
87
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
88
|
+
d2l-dropdown.settings-dropdown {
|
|
89
|
+
transition: translate 0.15s, box-shadow 0.15s;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
d2l-dropdown.settings-dropdown.peek,
|
|
93
|
+
d2l-dropdown.settings-dropdown:hover,
|
|
94
|
+
d2l-dropdown.settings-dropdown:focus-within,
|
|
95
|
+
d2l-dropdown.settings-dropdown:has(d2l-button-subtle[active]) {
|
|
96
|
+
box-shadow: 0 -1px 0 1px white;
|
|
97
|
+
translate: 0;
|
|
98
|
+
}
|
|
71
99
|
d2l-code-view {
|
|
72
100
|
border: none;
|
|
73
101
|
border-top-left-radius: 0;
|
|
@@ -78,7 +106,7 @@ class DemoSnippet extends LitElement {
|
|
|
78
106
|
:host([code-view-hidden]) d2l-code-view {
|
|
79
107
|
display: none;
|
|
80
108
|
}
|
|
81
|
-
|
|
109
|
+
`;
|
|
82
110
|
}
|
|
83
111
|
|
|
84
112
|
constructor() {
|
|
@@ -97,6 +125,16 @@ class DemoSnippet extends LitElement {
|
|
|
97
125
|
render() {
|
|
98
126
|
const dirAttr = this._dir === 'rtl' ? 'rtl' : 'ltr';
|
|
99
127
|
const skeleton = this._hasSkeleton ? html`<d2l-switch text="Skeleton" ?on="${this._skeletonOn}" @change="${this._handleSkeletonChange}"></d2l-switch>` : null;
|
|
128
|
+
const switches = html`
|
|
129
|
+
<d2l-switch text="RTL" ?on="${dirAttr === 'rtl'}" @change="${this._handleDirChange}"></d2l-switch><br />
|
|
130
|
+
<d2l-switch text="Fullscreen" ?on="${this._fullscreen}" @change="${this._handleFullscreenChange}"></d2l-switch><br />
|
|
131
|
+
${skeleton}`;
|
|
132
|
+
const settings = this.fullWidth && this._fullscreen ? html`
|
|
133
|
+
<d2l-dropdown class="settings-dropdown ${this._settingsPeek ? 'peek' : ''}">
|
|
134
|
+
<d2l-button-subtle primary icon="tier1:gear" text="Settings" class="d2l-dropdown-opener"></d2l-button-subtle>
|
|
135
|
+
<d2l-dropdown-content>${switches}</d2l-dropdown-content>
|
|
136
|
+
</d2l-dropdown>` : html`<div class="d2l-demo-snippet-settings">${switches}</div>`;
|
|
137
|
+
|
|
100
138
|
return html`
|
|
101
139
|
<div class="d2l-demo-snippet-demo-wrapper ${this._fullscreen ? 'fullscreen' : ''}">
|
|
102
140
|
<div class="d2l-demo-snippet-demo" dir="${dirAttr}">
|
|
@@ -105,11 +143,7 @@ class DemoSnippet extends LitElement {
|
|
|
105
143
|
<slot></slot>
|
|
106
144
|
</div>
|
|
107
145
|
</div>
|
|
108
|
-
|
|
109
|
-
<d2l-switch text="RTL" ?on="${dirAttr === 'rtl'}" @change="${this._handleDirChange}"></d2l-switch><br />
|
|
110
|
-
<d2l-switch text="Fullscreen" ?on="${this._fullscreen}" @change="${this._handleFullscreenChange}"></d2l-switch><br />
|
|
111
|
-
${skeleton}
|
|
112
|
-
</div>
|
|
146
|
+
${settings}
|
|
113
147
|
</div>
|
|
114
148
|
<d2l-code-view language="html" hide-language>${this._code}</d2l-code-view>
|
|
115
149
|
`;
|
|
@@ -201,10 +235,14 @@ class DemoSnippet extends LitElement {
|
|
|
201
235
|
this._applyAttr('dir', this._dir, true);
|
|
202
236
|
}
|
|
203
237
|
|
|
204
|
-
_handleFullscreenChange(e) {
|
|
238
|
+
async _handleFullscreenChange(e) {
|
|
205
239
|
this._fullscreen = e.target.on;
|
|
240
|
+
this._settingsPeek = this._fullscreen;
|
|
206
241
|
const event = new CustomEvent('d2l-demo-snippet-fullscreen-toggle', { bubbles: true, composed: true });
|
|
207
242
|
this.dispatchEvent(event);
|
|
243
|
+
await this.updateComplete;
|
|
244
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
245
|
+
this._settingsPeek = false;
|
|
208
246
|
}
|
|
209
247
|
|
|
210
248
|
_handleSkeletonChange(e) {
|
package/custom-elements.json
CHANGED
|
@@ -1436,7 +1436,7 @@
|
|
|
1436
1436
|
"type": "boolean"
|
|
1437
1437
|
},
|
|
1438
1438
|
{
|
|
1439
|
-
"name": "
|
|
1439
|
+
"name": "full-width",
|
|
1440
1440
|
"type": "boolean",
|
|
1441
1441
|
"default": "false"
|
|
1442
1442
|
}
|
|
@@ -1459,7 +1459,7 @@
|
|
|
1459
1459
|
},
|
|
1460
1460
|
{
|
|
1461
1461
|
"name": "fullWidth",
|
|
1462
|
-
"attribute": "
|
|
1462
|
+
"attribute": "full-width",
|
|
1463
1463
|
"type": "boolean",
|
|
1464
1464
|
"default": "false"
|
|
1465
1465
|
}
|
package/helpers/mathjax.js
CHANGED
|
@@ -30,9 +30,6 @@ const mathjaxFontMappings = new Map([
|
|
|
30
30
|
['MJXTEX-VB', 'MathJax_Vector-Bold']
|
|
31
31
|
]);
|
|
32
32
|
|
|
33
|
-
let mathJaxLoaded;
|
|
34
|
-
let renderingPromise = Promise.resolve();
|
|
35
|
-
|
|
36
33
|
class HtmlBlockMathRenderer {
|
|
37
34
|
|
|
38
35
|
get contextAttributes() {
|
|
@@ -45,34 +42,13 @@ class HtmlBlockMathRenderer {
|
|
|
45
42
|
if (contextVal === undefined) return elem;
|
|
46
43
|
|
|
47
44
|
const context = JSON.parse(contextVal) || {};
|
|
48
|
-
const isLatexSupported = context.renderLatex;
|
|
49
|
-
|
|
50
|
-
if (!elem.querySelector('math') && !(isLatexSupported && /\$\$|\\\(|\\\[|\\begin{|\\ref{|\\eqref{/.test(elem.innerHTML))) return elem;
|
|
51
45
|
|
|
52
|
-
|
|
46
|
+
await typesetMath(elem, {
|
|
53
47
|
deferTypeset: true,
|
|
54
|
-
renderLatex:
|
|
55
|
-
outputScale: context.outputScale || 1
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
await loadMathJax(mathJaxConfig);
|
|
59
|
-
|
|
60
|
-
// MathJax 3 does not support newlines, but it does persist styles, so add custom styles to mimic a linebreak
|
|
61
|
-
// This work-around should be removed when linebreaks are natively supported.
|
|
62
|
-
// MathJax issue: https://github.com/mathjax/MathJax/issues/2312
|
|
63
|
-
// A duplicate that explains our exact issue: https://github.com/mathjax/MathJax/issues/2495
|
|
64
|
-
elem.querySelectorAll('mspace[linebreak="newline"]').forEach(elm => {
|
|
65
|
-
elm.style.display = 'block';
|
|
66
|
-
elm.style.height = '0.5rem';
|
|
48
|
+
renderLatex: context.renderLatex,
|
|
49
|
+
outputScale: context.outputScale || 1,
|
|
50
|
+
window: window
|
|
67
51
|
});
|
|
68
|
-
|
|
69
|
-
// If we're using deferred rendering, we need to create a document structure
|
|
70
|
-
// within the element so MathJax can appropriately process math.
|
|
71
|
-
if (!options.noDeferredRendering) elem.innerHTML = `<mjx-doc><mjx-head></mjx-head><mjx-body>${elem.innerHTML}</mjx-body></mjx-doc>`;
|
|
72
|
-
|
|
73
|
-
await window.MathJax.startup.promise;
|
|
74
|
-
renderingPromise = renderingPromise.then(() => window.MathJax.typesetShadow(elem.getRootNode(), elem));
|
|
75
|
-
await renderingPromise;
|
|
76
52
|
}
|
|
77
53
|
|
|
78
54
|
}
|
|
@@ -83,9 +59,12 @@ export function createHtmlBlockRenderer() {
|
|
|
83
59
|
|
|
84
60
|
export function loadMathJax(mathJaxConfig) {
|
|
85
61
|
|
|
86
|
-
|
|
62
|
+
const win = (mathJaxConfig && mathJaxConfig.window) || window;
|
|
87
63
|
|
|
88
|
-
|
|
64
|
+
win.D2L = win.D2L || {};
|
|
65
|
+
if (win.D2L.mathJaxLoaded) return win.D2L.mathJaxLoaded;
|
|
66
|
+
|
|
67
|
+
win.MathJax = {
|
|
89
68
|
chtml: {
|
|
90
69
|
adaptiveCSS: false,
|
|
91
70
|
scale: (mathJaxConfig && mathJaxConfig.outputScale) || 1
|
|
@@ -110,11 +89,11 @@ export function loadMathJax(mathJaxConfig) {
|
|
|
110
89
|
// just an example and so we use an expedient method of
|
|
111
90
|
// accessing these for now.)
|
|
112
91
|
//
|
|
113
|
-
const mathjax =
|
|
114
|
-
const HTMLAdaptor =
|
|
115
|
-
const HTMLHandler =
|
|
116
|
-
const AbstractHandler =
|
|
117
|
-
const startup =
|
|
92
|
+
const mathjax = win.MathJax._.mathjax.mathjax;
|
|
93
|
+
const HTMLAdaptor = win.MathJax._.adaptors.HTMLAdaptor.HTMLAdaptor;
|
|
94
|
+
const HTMLHandler = win.MathJax._.handlers.html.HTMLHandler.HTMLHandler;
|
|
95
|
+
const AbstractHandler = win.MathJax._.core.Handler.AbstractHandler.prototype;
|
|
96
|
+
const startup = win.MathJax.startup;
|
|
118
97
|
|
|
119
98
|
const getFirstChild = doc => {
|
|
120
99
|
const child = doc.firstChild;
|
|
@@ -155,7 +134,7 @@ export function loadMathJax(mathJaxConfig) {
|
|
|
155
134
|
const adaptor = this.adaptor;
|
|
156
135
|
if (typeof(document) === 'string') {
|
|
157
136
|
document = adaptor.parse(document, 'text/html');
|
|
158
|
-
} else if ((document instanceof adaptor.window.HTMLElement || document instanceof adaptor.window.DocumentFragment) && !(document instanceof
|
|
137
|
+
} else if ((document instanceof adaptor.window.HTMLElement || document instanceof adaptor.window.DocumentFragment) && !(document instanceof win.ShadowRoot)) {
|
|
159
138
|
const child = document;
|
|
160
139
|
document = adaptor.parse('', 'text/html');
|
|
161
140
|
adaptor.append(adaptor.body(document), child);
|
|
@@ -173,7 +152,7 @@ export function loadMathJax(mathJaxConfig) {
|
|
|
173
152
|
// Register the new handler and adaptor
|
|
174
153
|
//
|
|
175
154
|
startup.registerConstructor('HTMLHandler', ShadowHandler);
|
|
176
|
-
startup.registerConstructor('browserAdaptor', () => new ShadowAdaptor(
|
|
155
|
+
startup.registerConstructor('browserAdaptor', () => new ShadowAdaptor(win));
|
|
177
156
|
|
|
178
157
|
//
|
|
179
158
|
// A service function that creates a new MathDocument from the
|
|
@@ -181,7 +160,7 @@ export function loadMathJax(mathJaxConfig) {
|
|
|
181
160
|
// renders the document. The MathDocument is returned in case
|
|
182
161
|
// you need to rerender the shadowRoot later.
|
|
183
162
|
//
|
|
184
|
-
|
|
163
|
+
win.MathJax.typesetShadow = async function(root, elem) {
|
|
185
164
|
const InputJax = startup.getInputJax();
|
|
186
165
|
const OutputJax = startup.getOutputJax();
|
|
187
166
|
const html = mathjax.document(root, { InputJax, OutputJax });
|
|
@@ -195,15 +174,15 @@ export function loadMathJax(mathJaxConfig) {
|
|
|
195
174
|
//
|
|
196
175
|
// Now do the usual startup now that the extensions are in place
|
|
197
176
|
//
|
|
198
|
-
|
|
177
|
+
win.MathJax.startup.defaultReady();
|
|
199
178
|
},
|
|
200
179
|
// Defer typesetting if the config is present and deferring is set
|
|
201
180
|
typeset: !(mathJaxConfig && mathJaxConfig.deferTypeset)
|
|
202
181
|
}
|
|
203
182
|
};
|
|
204
183
|
|
|
205
|
-
if (mathJaxConfig && mathJaxConfig.deferTypeset && !document.head.querySelector('#d2l-mathjax-fonts') && !document.head.querySelector('#MJX-CHTML-styles')) {
|
|
206
|
-
const styleElem = document.createElement('style');
|
|
184
|
+
if (mathJaxConfig && mathJaxConfig.deferTypeset && !win.document.head.querySelector('#d2l-mathjax-fonts') && !win.document.head.querySelector('#MJX-CHTML-styles')) {
|
|
185
|
+
const styleElem = win.document.createElement('style');
|
|
207
186
|
styleElem.id = 'd2l-mathjax-fonts';
|
|
208
187
|
|
|
209
188
|
let fontImportStyles = '';
|
|
@@ -216,11 +195,11 @@ export function loadMathJax(mathJaxConfig) {
|
|
|
216
195
|
});
|
|
217
196
|
|
|
218
197
|
styleElem.textContent = fontImportStyles;
|
|
219
|
-
document.head.appendChild(styleElem);
|
|
198
|
+
win.document.head.appendChild(styleElem);
|
|
220
199
|
}
|
|
221
200
|
|
|
222
|
-
mathJaxLoaded = new Promise(resolve => {
|
|
223
|
-
const script = document.createElement('script');
|
|
201
|
+
win.D2L.mathJaxLoaded = new Promise(resolve => {
|
|
202
|
+
const script = win.document.createElement('script');
|
|
224
203
|
script.async = 'async';
|
|
225
204
|
script.onload = resolve;
|
|
226
205
|
|
|
@@ -229,9 +208,44 @@ export function loadMathJax(mathJaxConfig) {
|
|
|
229
208
|
: 'mml-chtml';
|
|
230
209
|
|
|
231
210
|
script.src = `${mathjaxBaseUrl}/${component}.js`;
|
|
232
|
-
document.head.appendChild(script);
|
|
211
|
+
win.document.head.appendChild(script);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return win.D2L.mathJaxLoaded;
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export async function typesetMath(elem, options) {
|
|
219
|
+
if (!elem.querySelector('math') && !(options.renderLatex && /\$\$|\\\(|\\\[|\\begin{|\\ref{|\\eqref{/.test(elem.innerHTML))) return elem;
|
|
220
|
+
|
|
221
|
+
const win = options.window;
|
|
222
|
+
|
|
223
|
+
const mathJaxConfig = {
|
|
224
|
+
deferTypeset: options.deferTypeset,
|
|
225
|
+
renderLatex: options.renderLatex,
|
|
226
|
+
outputScale: options.outputScale || 1,
|
|
227
|
+
window: win
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
await loadMathJax(mathJaxConfig);
|
|
231
|
+
|
|
232
|
+
// MathJax 3 does not support newlines, but it does persist styles, so add custom styles to mimic a linebreak
|
|
233
|
+
// This work-around should be removed when linebreaks are natively supported.
|
|
234
|
+
// MathJax issue: https://github.com/mathjax/MathJax/issues/2312
|
|
235
|
+
// A duplicate that explains our exact issue: https://github.com/mathjax/MathJax/issues/2495
|
|
236
|
+
elem.querySelectorAll('mspace[linebreak="newline"]').forEach(elm => {
|
|
237
|
+
elm.style.display = 'block';
|
|
238
|
+
elm.style.height = '0.5rem';
|
|
233
239
|
});
|
|
234
240
|
|
|
235
|
-
|
|
241
|
+
// If we're using deferred rendering, we need to create a document structure
|
|
242
|
+
// within the element so MathJax can appropriately process math.
|
|
243
|
+
if (!options.noDeferredRendering) elem.innerHTML = `<mjx-doc><mjx-head></mjx-head><mjx-body>${elem.innerHTML}</mjx-body></mjx-doc>`;
|
|
244
|
+
|
|
245
|
+
await win.MathJax.startup.promise;
|
|
246
|
+
win.D2L = win.D2L || {};
|
|
236
247
|
|
|
248
|
+
if (!win.D2L.renderingPromise) win.D2L.renderingPromise = Promise.resolve();
|
|
249
|
+
win.D2L.renderingPromise = win.D2L.renderingPromise.then(() => win.MathJax.typesetShadow(elem.getRootNode(), elem));
|
|
250
|
+
await win.D2L.renderingPromise;
|
|
237
251
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brightspace-ui/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.64.0",
|
|
4
4
|
"description": "A collection of accessible, free, open-source web components for building Brightspace applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/BrightspaceUI/core.git",
|