fite/lib/constants.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-09-09 10:52:27 +08:00
/**
* {一些常量}
* @author yutent<yutent.io@gmail.com>
* @date 2022/09/06 11:54:56
*/
2023-05-15 15:17:55 +08:00
export const JS_EXP = /(?<=\n|^)<script[^>]*?>([\w\W]*?)<\/script>/
export const STYLE_EXP = /(?<=\n|^)<style([^>]*?)>([\w\W]*?)<\/style>/g
export const HTML_EXP = /(?<=\n|^)<template[^>]*?>([\w\W]*?)\n<\/template>/
2023-04-27 17:13:58 +08:00
export const V_DEEP = /:deep\(([^)]*?)\)(.*)/
2022-09-09 10:52:27 +08:00
export const CSS_SHEET_EXP = /([%@\w\.,#\-:>\+\~\|\(\)\[\]"'\=\s]+)\{/g
export const PERCENT_EXP = /^\d+%$/
2022-10-18 16:02:29 +08:00
2022-09-09 10:52:27 +08:00
export const COMMON_HEADERS = {
'Cache-Control': 'no-store'
}
2023-02-01 10:51:33 +08:00
export const SHEETS_DEF =
'const __sheets__ = [...document.adoptedStyleSheets];\n'
export const LEGACY_POLYFILL = `!(function(){
function join(p1, p2) {
let tmp1 = p1.split('/')
let tmp2 = p2.split('/')
if (tmp1.at(-1) === '') {
tmp1.pop()
}
while (tmp2.length) {
let tmp = tmp2.shift()
if (tmp === '.' || tmp === '') {
continue
} else if (tmp === '..') {
tmp1.pop()
} else {
tmp1.push(tmp)
}
}
return tmp1.join('/')
}
window.__fite_import = function(url,relPath){
let absPath = relPath.split('/').slice(0, -1).join('/')
let req
if(url.startsWith('./') || url.startsWith('../')) {
url = join(absPath, url)
}
return window.fetch(url).then(r => r.text())
}
})()`