diff --git a/plugins/plugin-md-power/src/client/components/CanIUse.vue b/plugins/plugin-md-power/src/client/components/CanIUse.vue new file mode 100644 index 00000000..c23310fc --- /dev/null +++ b/plugins/plugin-md-power/src/client/components/CanIUse.vue @@ -0,0 +1,93 @@ + + + + + + + diff --git a/plugins/plugin-md-power/src/client/composables/setupCanIUse.ts b/plugins/plugin-md-power/src/client/composables/setupCanIUse.ts deleted file mode 100644 index 66bd33ba..00000000 --- a/plugins/plugin-md-power/src/client/composables/setupCanIUse.ts +++ /dev/null @@ -1,20 +0,0 @@ -let isBind = false -export function setupCanIUse(): void { - if (isBind) - return - isBind = true - - window.addEventListener('message', (message) => { - const data = message.data - - if (typeof data === 'string' && data.includes('ciu_embed')) { - const [, feature, height] = data.split(':') - const el = document.querySelector(`.ciu_embed[data-feature="${feature}"]:not([data-skip])`) - if (el) { - const h = Number.parseInt(height) + 30 - ;(el.childNodes[0] as any).height = `${h}px` - el.setAttribute('data-skip', 'true') - } - } - }) -} diff --git a/plugins/plugin-md-power/src/node/features/caniuse.ts b/plugins/plugin-md-power/src/node/features/caniuse.ts index e420e69e..da0665f6 100644 --- a/plugins/plugin-md-power/src/node/features/caniuse.ts +++ b/plugins/plugin-md-power/src/node/features/caniuse.ts @@ -7,8 +7,11 @@ import type Token from 'markdown-it/lib/token.mjs' import type { RuleBlock } from 'markdown-it/lib/parser_block.mjs' import type { Markdown } from 'vuepress/markdown' import container from 'markdown-it-container' +import { customAlphabet } from 'nanoid' import type { CanIUseMode, CanIUseOptions, CanIUseTokenMeta } from '../../shared/index.js' +const nanoid = customAlphabet('abcdefghijklmnopqrstuvwxyz', 5) + // @[caniuse]() const minLength = 12 @@ -17,6 +20,7 @@ const START_CODES = [64, 91, 99, 97, 110, 105, 117, 115, 101] // regexp to match the import syntax const SYNTAX_RE = /^@\[caniuse(?:\s*?(embed|image)?(?:{([0-9,\-]*?)})?)\]\(([^)]*)\)/ +const UNDERLINE_RE = /_+/g function createCanIUseRuleBlock(defaultMode: CanIUseMode): RuleBlock { return (state, startLine, endLine, silent) => { @@ -76,18 +80,16 @@ function resolveCanIUse({ feature, mode, versions }: CanIUseTokenMeta): string {
` } - const periods = resolveVersions(versions) - const accessible = 'false' - const image = 'none' - const url = 'https://caniuse.bitsofco.de/embed/index.html' - const src = `${url}?feat=${feature}&periods=${periods}&accessible-colours=${accessible}&image-base=${image}` + feature = feature.replace(UNDERLINE_RE, '_') + const { past, future } = resolveVersions(versions) + const meta = nanoid() - return `