mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-14 09:20:51 +08:00
32 lines
717 B
TypeScript
32 lines
717 B
TypeScript
|
/* eslint-disable */
|
||
|
import { utoa } from '../utils'
|
||
|
|
||
|
const scriptRe = /<script[^>]*>([\s\S]*)<\/script>/
|
||
|
|
||
|
export const usePlayGround = (source: string) => {
|
||
|
const decodeCode = decodeURIComponent(source)
|
||
|
const result = decodeCode.match(scriptRe)
|
||
|
let finalCode = ''
|
||
|
if (result) {
|
||
|
finalCode = decodeCode.replace(
|
||
|
scriptRe,
|
||
|
`<script lang="ts" setup>
|
||
|
import { setupElementPlus } from './element-plus.js'
|
||
|
setupElementPlus()
|
||
|
$1
|
||
|
<\/script>`
|
||
|
)
|
||
|
} else {
|
||
|
finalCode = `${decodeCode}
|
||
|
<script lang="ts" setup>
|
||
|
import { setupElementPlus } from './element-plus.js'
|
||
|
setupElementPlus()
|
||
|
<\/script>
|
||
|
`
|
||
|
}
|
||
|
const originCode = {
|
||
|
'App.vue': finalCode,
|
||
|
}
|
||
|
return utoa(JSON.stringify(originCode))
|
||
|
}
|