🌀: fix linter
This commit is contained in:
		
							parent
							
								
									d28a4a7c82
								
							
						
					
					
						commit
						a0fd9345a2
					
				@ -403,7 +403,7 @@ watch(
 | 
			
		||||
 | 
			
		||||
provide("openState", openState);
 | 
			
		||||
 | 
			
		||||
defineExpose({open, hide, toggle});
 | 
			
		||||
defineExpose({ open, hide, toggle });
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<template>
 | 
			
		||||
@ -416,9 +416,7 @@ defineExpose({open, hide, toggle});
 | 
			
		||||
    @focusout="handleFocusout()"
 | 
			
		||||
    :class="{ 'layui-dropdown-up': openState }"
 | 
			
		||||
  >
 | 
			
		||||
    <div
 | 
			
		||||
      @click="handleClick()" 
 | 
			
		||||
      @contextmenu.prevent="handleContextMenuClick()">
 | 
			
		||||
    <div @click="handleClick()" @contextmenu.prevent="handleContextMenuClick()">
 | 
			
		||||
      <slot></slot>
 | 
			
		||||
    </div>
 | 
			
		||||
    <dl
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,3 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <router-view />
 | 
			
		||||
</template>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
import { createApp } from './main'
 | 
			
		||||
import { createApp } from "./main";
 | 
			
		||||
 | 
			
		||||
const { app, router } = createApp()
 | 
			
		||||
const { app, router } = createApp();
 | 
			
		||||
 | 
			
		||||
router.isReady().then(() => {
 | 
			
		||||
  app.mount('#app')
 | 
			
		||||
})
 | 
			
		||||
  app.mount("#app");
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
@ -1,24 +1,24 @@
 | 
			
		||||
import Layout from './App.vue'
 | 
			
		||||
import { App, createApp as _createApp } from 'vue'
 | 
			
		||||
import { createRouter } from './src/router/index'
 | 
			
		||||
import { Router } from 'vue-router'
 | 
			
		||||
import LayCode from './src/components/LayCode.vue'
 | 
			
		||||
import Children1  from './src/components/Children1.vue'
 | 
			
		||||
import Children2  from './src/components/Children2.vue'
 | 
			
		||||
import './src/assets/css/index.css'
 | 
			
		||||
import Layout from "./App.vue";
 | 
			
		||||
import { App, createApp as _createApp } from "vue";
 | 
			
		||||
import { createRouter } from "./src/router/index";
 | 
			
		||||
import { Router } from "vue-router";
 | 
			
		||||
import LayCode from "./src/components/LayCode.vue";
 | 
			
		||||
import Children1 from "./src/components/Children1.vue";
 | 
			
		||||
import Children2 from "./src/components/Children2.vue";
 | 
			
		||||
import "./src/assets/css/index.css";
 | 
			
		||||
 | 
			
		||||
export function createApp(): {
 | 
			
		||||
  app: App<Element>
 | 
			
		||||
  router: Router
 | 
			
		||||
  app: App<Element>;
 | 
			
		||||
  router: Router;
 | 
			
		||||
} {
 | 
			
		||||
  
 | 
			
		||||
  const app = _createApp(Layout);
 | 
			
		||||
  const router = createRouter();
 | 
			
		||||
 | 
			
		||||
   app.use(router)
 | 
			
		||||
    .component('LayCode', LayCode)
 | 
			
		||||
    .component('Children1',Children1)
 | 
			
		||||
    .component('Children2', Children2)
 | 
			
		||||
  app
 | 
			
		||||
    .use(router)
 | 
			
		||||
    .component("LayCode", LayCode)
 | 
			
		||||
    .component("Children1", Children1)
 | 
			
		||||
    .component("Children2", Children2);
 | 
			
		||||
 | 
			
		||||
  return { app, router }
 | 
			
		||||
}
 | 
			
		||||
  return { app, router };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -4,17 +4,15 @@
 | 
			
		||||
  </form>
 | 
			
		||||
</template>
 | 
			
		||||
<script setup>
 | 
			
		||||
 | 
			
		||||
const emit = defineEmits('called')
 | 
			
		||||
const emit = defineEmits("called");
 | 
			
		||||
 | 
			
		||||
const props = defineProps({
 | 
			
		||||
  data: Object
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
  data: Object,
 | 
			
		||||
});
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style scoped>
 | 
			
		||||
form {
 | 
			
		||||
  padding: 10px;
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
</style>
 | 
			
		||||
 | 
			
		||||
@ -5,21 +5,19 @@
 | 
			
		||||
  </form>
 | 
			
		||||
</template>
 | 
			
		||||
<script setup>
 | 
			
		||||
 | 
			
		||||
const emit = defineEmits('add','sub')
 | 
			
		||||
const emit = defineEmits("add", "sub");
 | 
			
		||||
 | 
			
		||||
const add = () => {
 | 
			
		||||
    emit('add')
 | 
			
		||||
}
 | 
			
		||||
  emit("add");
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const sub = () => {
 | 
			
		||||
    emit('sub')
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
  emit("sub");
 | 
			
		||||
};
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
<style scoped>
 | 
			
		||||
form {
 | 
			
		||||
  padding: 10px;
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
</style>
 | 
			
		||||
 | 
			
		||||
@ -12,95 +12,123 @@
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    <div :class="{ 'is-fixed': isFixContorl }" class="control">
 | 
			
		||||
      <i class="layui-icon layui-icon-file btn" @click="copy"><svg t="1646244236057" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5505" width="18" height="18"><path d="M768 682.666667V170.666667a85.333333 85.333333 0 0 0-85.333333-85.333334H170.666667a85.333333 85.333333 0 0 0-85.333334 85.333334v512a85.333333 85.333333 0 0 0 85.333334 85.333333h512a85.333333 85.333333 0 0 0 85.333333-85.333333zM170.666667 170.666667h512v512H170.666667z m682.666666 85.333333v512a85.333333 85.333333 0 0 1-85.333333 85.333333H256a85.333333 85.333333 0 0 0 85.333333 85.333334h426.666667a170.666667 170.666667 0 0 0 170.666667-170.666667V341.333333a85.333333 85.333333 0 0 0-85.333334-85.333333z" p-id="5506"></path></svg></i>
 | 
			
		||||
      <i class="layui-icon layui-icon-fonts-code btn" @click="toggle"><svg t="1646244296040" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7127" width="18" height="18"><path d="M217.301333 414.933333a21.333333 21.333333 0 0 1-1.066666-30.165333l29.098666-31.232a21.333333 21.333333 0 0 1 30.165334-1.024l236.117333 220.16 236.16-220.16a21.333333 21.333333 0 0 1 30.122667 1.024l29.098666 31.232a21.333333 21.333333 0 0 1-1.024 30.165333L541.738667 661.333333l-13.44 14.421334a21.290667 21.290667 0 0 1-16.725334 6.741333 21.290667 21.290667 0 0 1-16.64-6.741333l-13.44-14.506667z" p-id="7128"></path></svg></i>
 | 
			
		||||
      <i class="layui-icon layui-icon-file btn" @click="copy"
 | 
			
		||||
        ><svg
 | 
			
		||||
          t="1646244236057"
 | 
			
		||||
          class="icon"
 | 
			
		||||
          viewBox="0 0 1024 1024"
 | 
			
		||||
          version="1.1"
 | 
			
		||||
          xmlns="http://www.w3.org/2000/svg"
 | 
			
		||||
          p-id="5505"
 | 
			
		||||
          width="18"
 | 
			
		||||
          height="18"
 | 
			
		||||
        >
 | 
			
		||||
          <path
 | 
			
		||||
            d="M768 682.666667V170.666667a85.333333 85.333333 0 0 0-85.333333-85.333334H170.666667a85.333333 85.333333 0 0 0-85.333334 85.333334v512a85.333333 85.333333 0 0 0 85.333334 85.333333h512a85.333333 85.333333 0 0 0 85.333333-85.333333zM170.666667 170.666667h512v512H170.666667z m682.666666 85.333333v512a85.333333 85.333333 0 0 1-85.333333 85.333333H256a85.333333 85.333333 0 0 0 85.333333 85.333334h426.666667a170.666667 170.666667 0 0 0 170.666667-170.666667V341.333333a85.333333 85.333333 0 0 0-85.333334-85.333333z"
 | 
			
		||||
            p-id="5506"
 | 
			
		||||
          ></path></svg
 | 
			
		||||
      ></i>
 | 
			
		||||
      <i class="layui-icon layui-icon-fonts-code btn" @click="toggle"
 | 
			
		||||
        ><svg
 | 
			
		||||
          t="1646244296040"
 | 
			
		||||
          class="icon"
 | 
			
		||||
          viewBox="0 0 1024 1024"
 | 
			
		||||
          version="1.1"
 | 
			
		||||
          xmlns="http://www.w3.org/2000/svg"
 | 
			
		||||
          p-id="7127"
 | 
			
		||||
          width="18"
 | 
			
		||||
          height="18"
 | 
			
		||||
        >
 | 
			
		||||
          <path
 | 
			
		||||
            d="M217.301333 414.933333a21.333333 21.333333 0 0 1-1.066666-30.165333l29.098666-31.232a21.333333 21.333333 0 0 1 30.165334-1.024l236.117333 220.16 236.16-220.16a21.333333 21.333333 0 0 1 30.122667 1.024l29.098666 31.232a21.333333 21.333333 0 0 1-1.024 30.165333L541.738667 661.333333l-13.44 14.421334a21.290667 21.290667 0 0 1-16.725334 6.741333 21.290667 21.290667 0 0 1-16.64-6.741333l-13.44-14.506667z"
 | 
			
		||||
            p-id="7128"
 | 
			
		||||
          ></path></svg
 | 
			
		||||
      ></i>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import { onMounted, onUnmounted, ref, watch } from 'vue'
 | 
			
		||||
import { onMounted, onUnmounted, ref, watch } from "vue";
 | 
			
		||||
 | 
			
		||||
const meta = ref<HTMLElement>({} as HTMLElement)
 | 
			
		||||
const isFixContorl = ref(false)
 | 
			
		||||
const codeAreaHeight = ref(0)
 | 
			
		||||
const meta = ref<HTMLElement>({} as HTMLElement);
 | 
			
		||||
const isFixContorl = ref(false);
 | 
			
		||||
const codeAreaHeight = ref(0);
 | 
			
		||||
 | 
			
		||||
const show = ref(false)
 | 
			
		||||
const show = ref(false);
 | 
			
		||||
 | 
			
		||||
const toggle = function () {
 | 
			
		||||
  show.value = !show.value
 | 
			
		||||
}
 | 
			
		||||
  show.value = !show.value;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const copy = function () {
 | 
			
		||||
  const foundCodes = meta.value.getElementsByClassName('language-html')
 | 
			
		||||
  const foundCodes = meta.value.getElementsByClassName("language-html");
 | 
			
		||||
  const foundCode = foundCodes[0];
 | 
			
		||||
  let successful = false;
 | 
			
		||||
  if (navigator.clipboard && document.hasFocus()) {
 | 
			
		||||
    const text = foundCode.textContent || "";
 | 
			
		||||
    navigator.clipboard.writeText(text);
 | 
			
		||||
    successful = true;
 | 
			
		||||
  } else if (window.getSelection()){
 | 
			
		||||
  } else if (window.getSelection()) {
 | 
			
		||||
    var range = document.createRange();
 | 
			
		||||
    let copyDiv;
 | 
			
		||||
    if (show.value) {
 | 
			
		||||
      range.selectNode(foundCode); 
 | 
			
		||||
      range.selectNode(foundCode);
 | 
			
		||||
    } else {
 | 
			
		||||
      copyDiv = document.createElement('div');
 | 
			
		||||
      copyDiv = document.createElement("div");
 | 
			
		||||
      copyDiv.innerHTML = foundCode.innerHTML;
 | 
			
		||||
      copyDiv.style.position="fixed";
 | 
			
		||||
      copyDiv.style.left="-9999px";
 | 
			
		||||
      copyDiv.style.position = "fixed";
 | 
			
		||||
      copyDiv.style.left = "-9999px";
 | 
			
		||||
      document.body.appendChild(copyDiv);
 | 
			
		||||
      range.selectNode(copyDiv); 
 | 
			
		||||
      range.selectNode(copyDiv);
 | 
			
		||||
    }
 | 
			
		||||
    window.getSelection()?.addRange(range);  
 | 
			
		||||
    try {  
 | 
			
		||||
      successful = document.execCommand('copy');  
 | 
			
		||||
    } catch(err) {  
 | 
			
		||||
    window.getSelection()?.addRange(range);
 | 
			
		||||
    try {
 | 
			
		||||
      successful = document.execCommand("copy");
 | 
			
		||||
    } catch (err) {
 | 
			
		||||
      successful = false;
 | 
			
		||||
      console.error(err);
 | 
			
		||||
    }
 | 
			
		||||
    window.getSelection()?.removeAllRanges(); 
 | 
			
		||||
    window.getSelection()?.removeAllRanges();
 | 
			
		||||
    copyDiv?.remove();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (successful) {
 | 
			
		||||
 
 | 
			
		||||
  } else {
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
onMounted(() => {
 | 
			
		||||
  const foundDescs = meta.value.getElementsByClassName('description')
 | 
			
		||||
  const foundCodes = meta.value.getElementsByClassName('language-html')
 | 
			
		||||
  const foundDescs = meta.value.getElementsByClassName("description");
 | 
			
		||||
  const foundCodes = meta.value.getElementsByClassName("language-html");
 | 
			
		||||
 | 
			
		||||
  if (foundDescs.length) {
 | 
			
		||||
    codeAreaHeight.value =
 | 
			
		||||
      foundDescs[0].clientHeight + foundCodes[0].clientHeight + 30
 | 
			
		||||
      foundDescs[0].clientHeight + foundCodes[0].clientHeight + 30;
 | 
			
		||||
  } else {
 | 
			
		||||
    codeAreaHeight.value = foundCodes[0].clientHeight + 20
 | 
			
		||||
    codeAreaHeight.value = foundCodes[0].clientHeight + 20;
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
onUnmounted(() => {
 | 
			
		||||
  window.removeEventListener('scroll', handleScroll)
 | 
			
		||||
})
 | 
			
		||||
  window.removeEventListener("scroll", handleScroll);
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
watch(show, (value) => {
 | 
			
		||||
  if (value) {
 | 
			
		||||
    meta.value.style.height = `${codeAreaHeight.value}px`
 | 
			
		||||
    window.addEventListener('scroll', handleScroll)
 | 
			
		||||
    setTimeout(handleScroll, 100)
 | 
			
		||||
    meta.value.style.height = `${codeAreaHeight.value}px`;
 | 
			
		||||
    window.addEventListener("scroll", handleScroll);
 | 
			
		||||
    setTimeout(handleScroll, 100);
 | 
			
		||||
  } else {
 | 
			
		||||
    meta.value.style.height = '0'
 | 
			
		||||
    window.removeEventListener('scroll', handleScroll)
 | 
			
		||||
    meta.value.style.height = "0";
 | 
			
		||||
    window.removeEventListener("scroll", handleScroll);
 | 
			
		||||
  }
 | 
			
		||||
})
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
function handleScroll() {
 | 
			
		||||
  const { top, bottom } = meta.value.getBoundingClientRect()
 | 
			
		||||
  const { top, bottom } = meta.value.getBoundingClientRect();
 | 
			
		||||
  isFixContorl.value =
 | 
			
		||||
    bottom > window.innerHeight && top + 44 <= window.innerHeight
 | 
			
		||||
    bottom > window.innerHeight && top + 44 <= window.innerHeight;
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
@ -117,7 +145,7 @@ function handleScroll() {
 | 
			
		||||
}
 | 
			
		||||
.lay-code .source {
 | 
			
		||||
  padding: 24px;
 | 
			
		||||
  padding-bottom:15px;
 | 
			
		||||
  padding-bottom: 15px;
 | 
			
		||||
}
 | 
			
		||||
.lay-code .meta {
 | 
			
		||||
  padding: 0 10px;
 | 
			
		||||
@ -154,7 +182,7 @@ function handleScroll() {
 | 
			
		||||
  color: var(--c-text-light);
 | 
			
		||||
}
 | 
			
		||||
.lay-code pre {
 | 
			
		||||
    margin: 1rem 0.8rem 1rem 0.8rem;
 | 
			
		||||
  margin: 1rem 0.8rem 1rem 0.8rem;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.lay-code .control {
 | 
			
		||||
@ -189,6 +217,6 @@ function handleScroll() {
 | 
			
		||||
  padding-right: 10px;
 | 
			
		||||
}
 | 
			
		||||
.btn:hover::before {
 | 
			
		||||
  color: #5FB878;
 | 
			
		||||
  color: #5fb878;
 | 
			
		||||
}
 | 
			
		||||
</style>
 | 
			
		||||
</style>
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,21 @@
 | 
			
		||||
<template>
 | 
			
		||||
  <div class="markdown-body light-scheme">
 | 
			
		||||
    <div class="alone-header">
 | 
			
		||||
      <img class="alone-logo" src="../assets/logo.png" /> 
 | 
			
		||||
      <a style="position: absolute; right: 16%; line-height: 60px;color:white;font-size:15px;">1.3.10</a>
 | 
			
		||||
      <a href="https://gitee.com/layui-vue/layer-vue" style="position: absolute; right: 10%; line-height: 75px">
 | 
			
		||||
      <img class="alone-logo" src="../assets/logo.png" />
 | 
			
		||||
      <a
 | 
			
		||||
        style="
 | 
			
		||||
          position: absolute;
 | 
			
		||||
          right: 16%;
 | 
			
		||||
          line-height: 60px;
 | 
			
		||||
          color: white;
 | 
			
		||||
          font-size: 15px;
 | 
			
		||||
        "
 | 
			
		||||
        >1.3.10</a
 | 
			
		||||
      >
 | 
			
		||||
      <a
 | 
			
		||||
        href="https://gitee.com/layui-vue/layer-vue"
 | 
			
		||||
        style="position: absolute; right: 10%; line-height: 75px"
 | 
			
		||||
      >
 | 
			
		||||
        <svg width="1.7em" height="1.7em" viewBox="0 0 24 24">
 | 
			
		||||
          <path
 | 
			
		||||
            fill="#fff"
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,7 @@ const plugins = [
 | 
			
		||||
      highlight,
 | 
			
		||||
    },
 | 
			
		||||
    markdownItSetup(md) {
 | 
			
		||||
      md.use(snippet).use(preWrapper).use(container, "demo", demo)
 | 
			
		||||
      md.use(snippet).use(preWrapper).use(container, "demo", demo);
 | 
			
		||||
    },
 | 
			
		||||
  }),
 | 
			
		||||
] as any;
 | 
			
		||||
 | 
			
		||||
@ -1,21 +1,21 @@
 | 
			
		||||
import markdown from 'markdown-it'
 | 
			
		||||
import highlight from './highlight'
 | 
			
		||||
import type Token from 'markdown-it/lib/token'
 | 
			
		||||
import markdown from "markdown-it";
 | 
			
		||||
import highlight from "./highlight";
 | 
			
		||||
import type Token from "markdown-it/lib/token";
 | 
			
		||||
 | 
			
		||||
function assignScript(script: string) {
 | 
			
		||||
  const dependencies = {} as Record<string, string[]>
 | 
			
		||||
  const attrs = {} as Record<string, string>
 | 
			
		||||
  const dependencies = {} as Record<string, string[]>;
 | 
			
		||||
  const attrs = {} as Record<string, string>;
 | 
			
		||||
  const content = script
 | 
			
		||||
    .replace(/import\s?\{.*\}.*/g, (item) => {
 | 
			
		||||
      const key = getInnerString(item.replace(/'/g, '"'), '"', '"')
 | 
			
		||||
      const value = getInnerString(item.replace(/\s+/g, ''), '{', '}')
 | 
			
		||||
      const list = value ? value.split(',') : []
 | 
			
		||||
      const key = getInnerString(item.replace(/'/g, '"'), '"', '"');
 | 
			
		||||
      const value = getInnerString(item.replace(/\s+/g, ""), "{", "}");
 | 
			
		||||
      const list = value ? value.split(",") : [];
 | 
			
		||||
      if (key && dependencies[key]) {
 | 
			
		||||
        dependencies[key] = dependencies[key].concat(list)
 | 
			
		||||
        dependencies[key] = dependencies[key].concat(list);
 | 
			
		||||
      } else if (key) {
 | 
			
		||||
        dependencies[key] = list
 | 
			
		||||
        dependencies[key] = list;
 | 
			
		||||
      }
 | 
			
		||||
      return ''
 | 
			
		||||
      return "";
 | 
			
		||||
    })
 | 
			
		||||
    /**
 | 
			
		||||
     * const -> let
 | 
			
		||||
@ -24,23 +24,23 @@ function assignScript(script: string) {
 | 
			
		||||
     * const a = -> a =
 | 
			
		||||
     */
 | 
			
		||||
    .replace(/(const|let|var)\s\w*\s?=/g, (item) => {
 | 
			
		||||
      const attr = getInnerString(item, '\\s', '\\s?=')
 | 
			
		||||
      const attr = getInnerString(item, "\\s", "\\s?=");
 | 
			
		||||
      if (attr && !(attr in attrs)) {
 | 
			
		||||
        attrs[attr] = attr
 | 
			
		||||
        return `let ${attr} =`
 | 
			
		||||
        attrs[attr] = attr;
 | 
			
		||||
        return `let ${attr} =`;
 | 
			
		||||
      } else {
 | 
			
		||||
        return attr + ' ='
 | 
			
		||||
        return attr + " =";
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    // Remove extra line breaks
 | 
			
		||||
    .replace(/\n+/gm, '\n')
 | 
			
		||||
    .replace(/\n+/gm, "\n");
 | 
			
		||||
  // Combine the import
 | 
			
		||||
  const reImport = Object.keys(dependencies).reduce((all, item) => {
 | 
			
		||||
    const filterAttrs = [...new Set(dependencies[item])]
 | 
			
		||||
    return all + `import {${filterAttrs + ','}} from '${item}';\n`
 | 
			
		||||
  }, '')
 | 
			
		||||
    const filterAttrs = [...new Set(dependencies[item])];
 | 
			
		||||
    return all + `import {${filterAttrs + ","}} from '${item}';\n`;
 | 
			
		||||
  }, "");
 | 
			
		||||
 | 
			
		||||
  return reImport + content
 | 
			
		||||
  return reImport + content;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
@ -53,89 +53,89 @@ function assignScript(script: string) {
 | 
			
		||||
function getInnerString(
 | 
			
		||||
  string: string,
 | 
			
		||||
  prefix: string,
 | 
			
		||||
  postfix = '',
 | 
			
		||||
  type: 'i' | 'g' | 'm' = 'i'
 | 
			
		||||
  postfix = "",
 | 
			
		||||
  type: "i" | "g" | "m" = "i"
 | 
			
		||||
): string | undefined {
 | 
			
		||||
  const result = new RegExp(`${prefix}(.*)${postfix}`, type)
 | 
			
		||||
  const match = string.match(result)
 | 
			
		||||
  return match ? match[1].trim() : undefined
 | 
			
		||||
  const result = new RegExp(`${prefix}(.*)${postfix}`, type);
 | 
			
		||||
  const match = string.match(result);
 | 
			
		||||
  return match ? match[1].trim() : undefined;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
let script = '' // Record the <script> label of the current page
 | 
			
		||||
let script = ""; // Record the <script> label of the current page
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  render: (tokens: Token[], idx: number): string => {
 | 
			
		||||
    // the `demo` block of the current page
 | 
			
		||||
    const htmlBlock = tokens.filter((item) => item.type === 'html_block')
 | 
			
		||||
    const { nesting, info = '', map } = tokens[idx]
 | 
			
		||||
    const htmlBlock = tokens.filter((item) => item.type === "html_block");
 | 
			
		||||
    const { nesting, info = "", map } = tokens[idx];
 | 
			
		||||
 | 
			
		||||
    if (nesting === -1) {
 | 
			
		||||
      return '</lay-code>'
 | 
			
		||||
      return "</lay-code>";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const matchedInfo = info.trim().match(/^demo\s+(.*)$/)
 | 
			
		||||
    const description = matchedInfo && matchedInfo[1]
 | 
			
		||||
    const descTemplate = markdown().render(description || '')
 | 
			
		||||
    let str = '' // copy the current `demo` block code
 | 
			
		||||
    let lastLine = NaN
 | 
			
		||||
    const matchedInfo = info.trim().match(/^demo\s+(.*)$/);
 | 
			
		||||
    const description = matchedInfo && matchedInfo[1];
 | 
			
		||||
    const descTemplate = markdown().render(description || "");
 | 
			
		||||
    let str = ""; // copy the current `demo` block code
 | 
			
		||||
    let lastLine = NaN;
 | 
			
		||||
 | 
			
		||||
    for (let i = 0; i < htmlBlock.length; i++) {
 | 
			
		||||
      const item = htmlBlock[i]
 | 
			
		||||
      const item = htmlBlock[i];
 | 
			
		||||
 | 
			
		||||
      if (item.map && map && item.map[0] >= map[0] && item.map[1] <= map[1]) {
 | 
			
		||||
        const { map, content } = item
 | 
			
		||||
        const delta = map[0] - (lastLine || map[1])
 | 
			
		||||
        const { map, content } = item;
 | 
			
		||||
        const delta = map[0] - (lastLine || map[1]);
 | 
			
		||||
 | 
			
		||||
        if (delta > 0) {
 | 
			
		||||
          str += '\n'.repeat(delta)
 | 
			
		||||
          str += "\n".repeat(delta);
 | 
			
		||||
        }
 | 
			
		||||
        str += content
 | 
			
		||||
        lastLine = map[1]
 | 
			
		||||
        str += content;
 | 
			
		||||
        lastLine = map[1];
 | 
			
		||||
        if (i === 0) {
 | 
			
		||||
          script = ''
 | 
			
		||||
          script = "";
 | 
			
		||||
        }
 | 
			
		||||
        // Remove top <template>
 | 
			
		||||
        if (/^<template>/.test(content)) {
 | 
			
		||||
          const reContent = content.match(/^<template>((\s|\S)*)<\/template>/m)
 | 
			
		||||
          const reContent = content.match(/^<template>((\s|\S)*)<\/template>/m);
 | 
			
		||||
 | 
			
		||||
          htmlBlock[i].content = (reContent && reContent[1]) || ''
 | 
			
		||||
          htmlBlock[i].content = (reContent && reContent[1]) || "";
 | 
			
		||||
        }
 | 
			
		||||
        // Extract the <script> label content
 | 
			
		||||
        if (content.includes('<script')) {
 | 
			
		||||
        if (content.includes("<script")) {
 | 
			
		||||
          if (/export\sdefault\s?\{/m.test(content)) {
 | 
			
		||||
            const setup = content.match(
 | 
			
		||||
              /setup\s?\(\)\s?\{((\s|\S)*)return\s?\{/m
 | 
			
		||||
            )
 | 
			
		||||
            );
 | 
			
		||||
            const reContent = content.replace(
 | 
			
		||||
              /export\sdefault\s?\{((\s|\S)*)\}/m,
 | 
			
		||||
              (setup && setup[1]) || ''
 | 
			
		||||
            )
 | 
			
		||||
              (setup && setup[1]) || ""
 | 
			
		||||
            );
 | 
			
		||||
            const reScript = reContent.match(
 | 
			
		||||
              /^<script\s?.*?>((\s|\S)*)<\/script>/m
 | 
			
		||||
            )
 | 
			
		||||
            script += (reScript && reScript[1]) || ''
 | 
			
		||||
            );
 | 
			
		||||
            script += (reScript && reScript[1]) || "";
 | 
			
		||||
          } else {
 | 
			
		||||
            const reScript = content.match(
 | 
			
		||||
              /^<script\s?.*?>((\s|\S)*)<\/script>/m
 | 
			
		||||
            )
 | 
			
		||||
            script += (reScript && reScript[1]) || ''
 | 
			
		||||
            );
 | 
			
		||||
            script += (reScript && reScript[1]) || "";
 | 
			
		||||
          }
 | 
			
		||||
          htmlBlock[i].content = ''
 | 
			
		||||
          htmlBlock[i].content = "";
 | 
			
		||||
        }
 | 
			
		||||
        // Change the last content to <script> of the current page
 | 
			
		||||
        if (i + 1 === htmlBlock.length) {
 | 
			
		||||
          htmlBlock[i].content = `
 | 
			
		||||
          <script setup>
 | 
			
		||||
            ${assignScript(script)}
 | 
			
		||||
          </script>`
 | 
			
		||||
          </script>`;
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return `
 | 
			
		||||
    <lay-code>
 | 
			
		||||
      ${description ? `<template #description>${descTemplate}</template>` : ''}
 | 
			
		||||
      <template #code>${highlight(str, 'vue')}</template>
 | 
			
		||||
    `
 | 
			
		||||
      ${description ? `<template #description>${descTemplate}</template>` : ""}
 | 
			
		||||
      <template #code>${highlight(str, "vue")}</template>
 | 
			
		||||
    `;
 | 
			
		||||
  },
 | 
			
		||||
}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -1,44 +1,44 @@
 | 
			
		||||
import prism from 'prismjs'
 | 
			
		||||
import loadLanguages from 'prismjs/components/index'
 | 
			
		||||
import escapeHtml from 'escape-html'
 | 
			
		||||
import prism from "prismjs";
 | 
			
		||||
import loadLanguages from "prismjs/components/index";
 | 
			
		||||
import escapeHtml from "escape-html";
 | 
			
		||||
 | 
			
		||||
loadLanguages(['markup', 'css', 'javascript'])
 | 
			
		||||
loadLanguages(["markup", "css", "javascript"]);
 | 
			
		||||
 | 
			
		||||
function wrap(code: string, lang: string): string {
 | 
			
		||||
  if (lang === 'text') {
 | 
			
		||||
    code = escapeHtml(code)
 | 
			
		||||
  if (lang === "text") {
 | 
			
		||||
    code = escapeHtml(code);
 | 
			
		||||
  }
 | 
			
		||||
  return `<pre v-pre><code>${code}</code></pre>`
 | 
			
		||||
  return `<pre v-pre><code>${code}</code></pre>`;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default (str: string, lang: string): string => {
 | 
			
		||||
  if (!lang) {
 | 
			
		||||
    return wrap(str, 'text')
 | 
			
		||||
    return wrap(str, "text");
 | 
			
		||||
  }
 | 
			
		||||
  lang = lang.toLowerCase()
 | 
			
		||||
  const rawLang = lang
 | 
			
		||||
  if (lang === 'vue' || lang === 'html') {
 | 
			
		||||
    lang = 'markup'
 | 
			
		||||
  lang = lang.toLowerCase();
 | 
			
		||||
  const rawLang = lang;
 | 
			
		||||
  if (lang === "vue" || lang === "html") {
 | 
			
		||||
    lang = "markup";
 | 
			
		||||
  }
 | 
			
		||||
  if (lang === 'md') {
 | 
			
		||||
    lang = 'markdown'
 | 
			
		||||
  if (lang === "md") {
 | 
			
		||||
    lang = "markdown";
 | 
			
		||||
  }
 | 
			
		||||
  if (lang === 'ts') {
 | 
			
		||||
    lang = 'typescript'
 | 
			
		||||
  if (lang === "ts") {
 | 
			
		||||
    lang = "typescript";
 | 
			
		||||
  }
 | 
			
		||||
  if (lang === 'py') {
 | 
			
		||||
    lang = 'python'
 | 
			
		||||
  if (lang === "py") {
 | 
			
		||||
    lang = "python";
 | 
			
		||||
  }
 | 
			
		||||
  if (!prism.languages[lang]) {
 | 
			
		||||
    try {
 | 
			
		||||
      loadLanguages([lang])
 | 
			
		||||
      loadLanguages([lang]);
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      console.warn(lang, e)
 | 
			
		||||
      console.warn(lang, e);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  if (prism.languages[lang]) {
 | 
			
		||||
    const code = prism.highlight(str, prism.languages[lang], lang)
 | 
			
		||||
    return wrap(code, rawLang)
 | 
			
		||||
    const code = prism.highlight(str, prism.languages[lang], lang);
 | 
			
		||||
    return wrap(code, rawLang);
 | 
			
		||||
  }
 | 
			
		||||
  return wrap(str, 'text')
 | 
			
		||||
}
 | 
			
		||||
  return wrap(str, "text");
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -1,11 +1,11 @@
 | 
			
		||||
import MarkdownIt from 'markdown-it'
 | 
			
		||||
import MarkdownIt from "markdown-it";
 | 
			
		||||
 | 
			
		||||
export default (md: MarkdownIt): void => {
 | 
			
		||||
  const fence = md.renderer.rules.fence!
 | 
			
		||||
  const fence = md.renderer.rules.fence!;
 | 
			
		||||
  md.renderer.rules.fence = (...args) => {
 | 
			
		||||
    const [tokens, idx] = args
 | 
			
		||||
    const token = tokens[idx]
 | 
			
		||||
    const rawCode = fence(...args)
 | 
			
		||||
    return `<div class="language-${token.info.trim()}">${rawCode}</div>`
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
    const [tokens, idx] = args;
 | 
			
		||||
    const token = tokens[idx];
 | 
			
		||||
    const rawCode = fence(...args);
 | 
			
		||||
    return `<div class="language-${token.info.trim()}">${rawCode}</div>`;
 | 
			
		||||
  };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -1,34 +1,39 @@
 | 
			
		||||
import fs from 'fs'
 | 
			
		||||
import MarkdownIt from 'markdown-it'
 | 
			
		||||
import { RuleBlock } from 'markdown-it/lib/parser_block'
 | 
			
		||||
import fs from "fs";
 | 
			
		||||
import MarkdownIt from "markdown-it";
 | 
			
		||||
import { RuleBlock } from "markdown-it/lib/parser_block";
 | 
			
		||||
 | 
			
		||||
export default (md: MarkdownIt): void => {
 | 
			
		||||
  const parser: RuleBlock = (state, startLine, endLine, silent) => {
 | 
			
		||||
    const CH = '<'.charCodeAt(0)
 | 
			
		||||
    const pos = state.bMarks[startLine] + state.tShift[startLine]
 | 
			
		||||
    const max = state.eMarks[startLine]
 | 
			
		||||
    const CH = "<".charCodeAt(0);
 | 
			
		||||
    const pos = state.bMarks[startLine] + state.tShift[startLine];
 | 
			
		||||
    const max = state.eMarks[startLine];
 | 
			
		||||
    if (state.sCount[startLine] - state.blkIndent >= 4) {
 | 
			
		||||
      return false
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
    for (let i = 0; i < 3; ++i) {
 | 
			
		||||
      const ch = state.src.charCodeAt(pos + i)
 | 
			
		||||
      if (ch !== CH || pos + i >= max) return false
 | 
			
		||||
      const ch = state.src.charCodeAt(pos + i);
 | 
			
		||||
      if (ch !== CH || pos + i >= max) return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (silent) {
 | 
			
		||||
      return true
 | 
			
		||||
      return true;
 | 
			
		||||
    }
 | 
			
		||||
    const start = pos + 3
 | 
			
		||||
    const end = state.skipSpacesBack(max, pos)
 | 
			
		||||
    const rawPath = state.src.slice(start, end).trim().replace(/^@/, process.cwd())
 | 
			
		||||
    const content = fs.existsSync(rawPath) ? fs.readFileSync(rawPath).toString() : 'Not found: ' + rawPath
 | 
			
		||||
    const meta = rawPath.replace(rawPath, '')
 | 
			
		||||
    state.line = startLine + 1
 | 
			
		||||
    const token = state.push('fence', 'code', 0)
 | 
			
		||||
    token.info = rawPath.split('.').pop() + meta
 | 
			
		||||
    token.content = content
 | 
			
		||||
    token.markup = '```'
 | 
			
		||||
    token.map = [startLine, startLine + 1]
 | 
			
		||||
    return true
 | 
			
		||||
  }
 | 
			
		||||
  md.block.ruler.before('fence', 'snippet', parser)
 | 
			
		||||
}
 | 
			
		||||
    const start = pos + 3;
 | 
			
		||||
    const end = state.skipSpacesBack(max, pos);
 | 
			
		||||
    const rawPath = state.src
 | 
			
		||||
      .slice(start, end)
 | 
			
		||||
      .trim()
 | 
			
		||||
      .replace(/^@/, process.cwd());
 | 
			
		||||
    const content = fs.existsSync(rawPath)
 | 
			
		||||
      ? fs.readFileSync(rawPath).toString()
 | 
			
		||||
      : "Not found: " + rawPath;
 | 
			
		||||
    const meta = rawPath.replace(rawPath, "");
 | 
			
		||||
    state.line = startLine + 1;
 | 
			
		||||
    const token = state.push("fence", "code", 0);
 | 
			
		||||
    token.info = rawPath.split(".").pop() + meta;
 | 
			
		||||
    token.content = content;
 | 
			
		||||
    token.markup = "```";
 | 
			
		||||
    token.map = [startLine, startLine + 1];
 | 
			
		||||
    return true;
 | 
			
		||||
  };
 | 
			
		||||
  md.block.ruler.before("fence", "snippet", parser);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,16 @@
 | 
			
		||||
import { createRouter as _createRouter, createWebHistory, Router } from 'vue-router';
 | 
			
		||||
import zhCN from './zh-CN';
 | 
			
		||||
import {
 | 
			
		||||
  createRouter as _createRouter,
 | 
			
		||||
  createWebHistory,
 | 
			
		||||
  Router,
 | 
			
		||||
} from "vue-router";
 | 
			
		||||
import zhCN from "./zh-CN";
 | 
			
		||||
 | 
			
		||||
const routes = [...zhCN]
 | 
			
		||||
const routes = [...zhCN];
 | 
			
		||||
 | 
			
		||||
export function createRouter(): Router {
 | 
			
		||||
  const baseUrl = import.meta.env.BASE_URL
 | 
			
		||||
  const baseUrl = import.meta.env.BASE_URL;
 | 
			
		||||
  return _createRouter({
 | 
			
		||||
    history: createWebHistory(baseUrl),
 | 
			
		||||
    routes: routes,
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -10,9 +10,9 @@ const zhCN = [
 | 
			
		||||
      {
 | 
			
		||||
        path: "/zh-CN/index",
 | 
			
		||||
        component: () => import("../../docs/zh-CN/index.md"),
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
        meta: { title: "指南" },
 | 
			
		||||
      }
 | 
			
		||||
      },
 | 
			
		||||
    ],
 | 
			
		||||
  },
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
import path from 'path'
 | 
			
		||||
import { defineConfig } from 'vite'
 | 
			
		||||
import plugins from './src/plugin/common-plugins'
 | 
			
		||||
import path from "path";
 | 
			
		||||
import { defineConfig } from "vite";
 | 
			
		||||
import plugins from "./src/plugin/common-plugins";
 | 
			
		||||
 | 
			
		||||
export default defineConfig({
 | 
			
		||||
  resolve: {
 | 
			
		||||
@ -9,4 +9,4 @@ export default defineConfig({
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
  plugins,
 | 
			
		||||
})
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user