-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpg.js
76 lines (64 loc) · 2.2 KB
/
pg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import './u/u.js'
// import './ut.js'
import './u/web.js'
import './u/ui.js'
// import './vue.js'
import './u/net.js'
import { vm } from './u/vm.js'
import { qht } from './dev/qht.js'
u.qht = qht
import { qcs } from './dev/qcs.js'
u.qcs = qcs
async function init() {
const path = u.path.hash.t('?')[0].t(2) || u.qs(u.path.search.t(1)).hash || u.fs.hash || 'index'
if (!path) {return}
u.path.hash = '/' + path
u.fs.hash = u.path.hash.replace('#', '')
if (u.id('pg')) {
u.id('pg').h('')
} else {
const html = `<div id="pg" class="pg"></div>`
document.body.insertAdjacentHTML(`beforeend`, html);
}
try {pgdata(path)} catch (e) {log(e)}
}
async function pgdata(path) {
var rs = {cfg: {}, db: {}, fn: {}}
const j = u.path.search.endsWith('j')
const c = u.path.search.endsWith('c')
if(j || c) {
var data = {}
// if (j) {
// data = await u.net.get('data.json')
// const { trans } = await import('./to.js')
// }
// if (c) {
const dt = await u.net.get('pg/' + 'data.css', 0, {text: 1})
const { trans, jn } = await import('./dev/figma.js')
data = jn(dt)
// }
data.rules = rs
data.config = rs.config
data.name = path.slice(path.lastIndexOf('/') + 1)
const html = trans(data)
const htm = html.replace(/rpx/g, 'px')
u.id('pg').insertAdjacentHTML(`beforeend`, htm);
return
}
const tpl = await u.net.get('./pg/' + path + '.vue', null, {text: true})
const ht = tpl.match(/\<template\>([\s\S]+?)\<\/template\>/)[1]
const css = tpl.match(/\<style.*?\>([\s\S]+?)\<\/style\>/)[1]
const html = ['<tpl>', qht(ht.t()), '</tpl>', '<style scoped>', qcs(css).replace(/rpx/g, 'px'), '</style>'].join('\n')
const code = tpl.match(/\<script.*?\>([\s\S]+?)\<\/script\>/)
if(code?.[1]){
const ce = code[1].replace(/export[\s\S]*/, 'rs').e(/^\s*\/\//gm, '\n#')
const c = ls.compile(ce, {bare: 1, header: 0, const: 1})
rs = eval(c)
}
// o(html)
u.id('pg').insertAdjacentHTML(`beforeend`, html);
vm(rs).bind(rs)()
u.id('pg').addEventListener('click', u.click.bind(rs))
}
window.addEventListener("load", init)
window.addEventListener('hashchange', init)