@vueuse/head
Advanced tools
Comparing version 0.7.12 to 0.7.13
@@ -88,2 +88,3 @@ import * as vue from 'vue'; | ||
}; | ||
_position?: number; | ||
}; | ||
@@ -90,0 +91,0 @@ declare type HeadClient = { |
@@ -61,3 +61,4 @@ "use strict"; | ||
// src/stringify-attrs.ts | ||
var htmlEscape = (str) => str.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">"); | ||
var stringifyAttrName = (str) => str.replace(/[\s"'><\/=]/g, "").replace(/[^a-zA-Z0-9_-]/g, ""); | ||
var stringifyAttrValue = (str) => str.replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">"); | ||
var stringifyAttrs = (attributes) => { | ||
@@ -72,5 +73,5 @@ const handledAttributes = []; | ||
} | ||
let attribute = htmlEscape(key); | ||
let attribute = stringifyAttrName(key); | ||
if (value !== true) { | ||
attribute += `="${htmlEscape(String(value))}"`; | ||
attribute += `="${stringifyAttrValue(String(value))}"`; | ||
} | ||
@@ -97,3 +98,3 @@ handledAttributes.push(attribute); | ||
// src/index.ts | ||
var getTagDeduper = (tag) => { | ||
var tagDedupeKey = (tag) => { | ||
if (!["meta", "base", "script", "link"].includes(tag.tag)) { | ||
@@ -104,9 +105,9 @@ return false; | ||
if (tagName === "base") { | ||
return true; | ||
return "base"; | ||
} | ||
if (tagName === "link" && props.rel === "canonical") { | ||
return { propValue: "canonical" }; | ||
return "canonical"; | ||
} | ||
if (props.charset) { | ||
return { propKey: "charset" }; | ||
return "charset"; | ||
} | ||
@@ -122,3 +123,3 @@ const name = ["key", "id", "name", "property", "http-equiv"]; | ||
if (value !== void 0) { | ||
return { propValue: n }; | ||
return `${tagName}-${n}-${value}`; | ||
} | ||
@@ -294,29 +295,8 @@ } | ||
const deduped = []; | ||
const deduping = {}; | ||
const titleTemplate = allHeadObjs.map((i) => (0, import_vue.unref)(i).titleTemplate).reverse().find((i) => i != null); | ||
allHeadObjs.forEach((objs) => { | ||
allHeadObjs.forEach((objs, headObjectIdx) => { | ||
const tags = headObjToTags((0, import_vue.unref)(objs)); | ||
tags.forEach((tag) => { | ||
const dedupe = getTagDeduper(tag); | ||
if (dedupe) { | ||
let index = -1; | ||
for (let i = 0; i < deduped.length; i++) { | ||
const prev = deduped[i]; | ||
if (prev.tag !== tag.tag) { | ||
continue; | ||
} | ||
if (dedupe === true) { | ||
index = i; | ||
} else if (dedupe.propValue && (0, import_vue.unref)(prev.props[dedupe.propValue]) === (0, import_vue.unref)(tag.props[dedupe.propValue])) { | ||
index = i; | ||
} else if (dedupe.propKey && prev.props[dedupe.propKey] && tag.props[dedupe.propKey]) { | ||
index = i; | ||
} | ||
if (index !== -1) { | ||
break; | ||
} | ||
} | ||
if (index !== -1) { | ||
deduped.splice(index, 1); | ||
} | ||
} | ||
tags.forEach((tag, tagIdx) => { | ||
tag._position = headObjectIdx * 1e4 + tagIdx; | ||
if (titleTemplate && tag.tag === "title") { | ||
@@ -328,6 +308,12 @@ tag.props.children = renderTemplate( | ||
} | ||
deduped.push(tag); | ||
const dedupeKey = tagDedupeKey(tag); | ||
if (dedupeKey) { | ||
deduping[dedupeKey] = tag; | ||
} else { | ||
deduped.push(tag); | ||
} | ||
}); | ||
}); | ||
return deduped; | ||
deduped.push(...Object.values(deduping)); | ||
return deduped.sort((a, b) => a._position - b._position); | ||
}, | ||
@@ -334,0 +320,0 @@ addHeadObjs(objs) { |
{ | ||
"name": "@vueuse/head", | ||
"packageManager": "pnpm@7.5.0", | ||
"version": "0.7.12", | ||
"version": "0.7.13", | ||
"license": "MIT", | ||
@@ -24,7 +24,7 @@ "description": "Document head manager for Vue 3. SSR ready.", | ||
"scripts": { | ||
"test": "node -r esbuild-register scripts/run-test.ts", | ||
"example": "vite example", | ||
"play:vite": "vite examples/vite-ssr", | ||
"build": "tsup src/index.ts --format esm,cjs --dts", | ||
"prepublishOnly": "npm run build", | ||
"test:e2e": "ava", | ||
"test": "nuxi prepare examples/nuxt3 && vitest", | ||
"test:e2e": "vitest tests/e2e", | ||
"release": "kanpai" | ||
@@ -40,11 +40,2 @@ }, | ||
}, | ||
"ava": { | ||
"extensions": [ | ||
"ts", | ||
"tsx" | ||
], | ||
"require": [ | ||
"esbuild-register" | ||
] | ||
}, | ||
"simple-git-hooks": { | ||
@@ -61,3 +52,3 @@ "pre-commit": "npx lint-staged" | ||
"@egoist/prettier-config": "^1.0.0", | ||
"@happy-dom/global-registrator": "^6.0.4", | ||
"@nuxt/test-utils": "3.0.0-rc.10", | ||
"@vitejs/plugin-vue": "^3.1.0", | ||
@@ -67,11 +58,12 @@ "@vitejs/plugin-vue-jsx": "^2.0.1", | ||
"@vue/server-renderer": "^3.2.39", | ||
"ava": "^4.3.3", | ||
"chrome-location": "^1.2.1", | ||
"esbuild-register": "^3.3.3", | ||
"execa": "^5.1.1", | ||
"happy-dom": "^6.0.4", | ||
"cheerio": "1.0.0-rc.12", | ||
"execa": "^6.1.0", | ||
"get-port-please": "^2.6.1", | ||
"jsdom": "^20.0.0", | ||
"kanpai": "^0.11.0", | ||
"lint-staged": "^13.0.3", | ||
"node-fetch": "^3.2.10", | ||
"playwright-core": "^1.25.2", | ||
"mlly": "^0.5.14", | ||
"nuxt": "3.0.0-rc.10", | ||
"pathe": "^0.3.7", | ||
"playwright": "^1.25.2", | ||
"prettier": "^2.7.1", | ||
@@ -82,2 +74,3 @@ "simple-git-hooks": "^2.8.0", | ||
"vite": "^3.1.2", | ||
"vitest": "^0.23.4", | ||
"vue": "^3.2.39", | ||
@@ -91,3 +84,6 @@ "vue-router": "^4.1.5" | ||
"@zhead/schema-vue": "^0.7.3" | ||
}, | ||
"resolutions": { | ||
"@vueuse/head": "link:." | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41005
24
1126