Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions packages/critters/src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@
}
},

id: reflectedProperty('id'),

className: reflectedProperty('class'),



insertBefore(child, referenceNode) {
if (!referenceNode) return this.appendChild(child);
Expand Down Expand Up @@ -160,10 +160,7 @@
return this.attribs != null && this.attribs[name] != null;
},

getAttributeNode(name) {
const value = this.getAttribute(name);
if (value != null) return { specified: true, value };
},


exists(sel) {
return cachedQuerySelector(sel, this);
Expand Down Expand Up @@ -192,11 +189,7 @@
}
},

contentType: {
get() {
return 'text/html';
}
},


nodeName: {
get() {
Expand Down Expand Up @@ -229,10 +222,7 @@
return new Element(name);
},

createTextNode(text) {
// there is no dedicated createTextNode equivalent exposed in htmlparser2's DOM
return new Text(text);
},


exists(sel) {
return cachedQuerySelector(sel, this);
Expand Down Expand Up @@ -269,7 +259,7 @@
* Create a property descriptor defining a getter/setter pair alias for a named attribute.
* @private
*/
function reflectedProperty(attributeName) {

Check warning on line 262 in packages/critters/src/dom.js

View workflow job for this annotation

GitHub Actions / Lint

'reflectedProperty' is defined but never used. Allowed unused vars must match /^_/u
return {
get() {
return this.getAttribute(attributeName);
Expand Down
19 changes: 18 additions & 1 deletion packages/critters/src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,25 @@ export default class Critters {
const preload = document.createElement('link');
preload.setAttribute('rel', 'preload');
preload.setAttribute('as', 'font');
// Determine font type: use explicit format if provided, otherwise infer from file extension
let type;
if (format) {
preload.setAttribute('type', `font/${format}`);
type = `font/${format}`;
} else {
// Infer MIME type from file extension
const ext = fontUrl.split('.').pop().toLowerCase();
const mimeMap = {
'woff2': 'font/woff2',
'woff': 'font/woff',
'ttf': 'font/ttf',
'otf': 'font/otf',
'eot': 'application/vnd.ms-fontobject',
'svg': 'image/svg+xml'
};
type = mimeMap[ext];
}
if (type) {
preload.setAttribute('type', type);
}
preload.setAttribute('crossorigin', 'anonymous');
preload.setAttribute('href', fontUrl);
Expand Down
Loading