@unhead/schema-org 1.9.16 → 1.10.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const plugin = require('./shared/schema-org.97103adc.cjs');
3
+ const plugin = require('./shared/schema-org.74d623f8.cjs');
4
4
  const unhead = require('unhead');
5
5
  require('ufo');
6
6
 
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { U as UnheadSchemaOrg } from './shared/schema-org.2da2cd3d.mjs';
2
- export { H as HowToId, a1 as PluginSchemaOrg, P as PrimaryArticleId, k as PrimaryBookId, m as PrimaryBreadcrumbId, s as PrimaryEventId, X as PrimaryWebPageId, _ as PrimaryWebSiteId, M as ProductId, R as RecipeId, a2 as SchemaOrgUnheadPlugin, L as addressResolver, g as aggregateOfferResolver, h as aggregateRatingResolver, i as articleResolver, j as bookEditionResolver, l as bookResolver, o as breadcrumbResolver, p as commentResolver, q as courseResolver, c as createSchemaOrgGraph, a as dedupeNodes, d as defineSchemaOrgResolver, t as eventResolver, w as foodEstablishmentResolver, x as howToResolver, z as howToStepDirectionResolver, y as howToStepResolver, B as imageResolver, A as itemListResolver, C as jobPostingResolver, D as listItemResolver, E as localBusinessResolver, F as movieResolver, n as normaliseNodes, G as offerResolver, I as openingHoursResolver, J as organizationResolver, K as personResolver, u as placeResolver, N as productResolver, O as questionResolver, Q as ratingResolver, Z as readActionResolver, S as recipeResolver, r as resolveMeta, b as resolveNode, e as resolveNodeId, f as resolveRelation, V as reviewResolver, a0 as searchActionResolver, T as softwareAppResolver, W as videoResolver, v as virtualLocationResolver, Y as webPageResolver, $ as webSiteResolver } from './shared/schema-org.2da2cd3d.mjs';
1
+ import { U as UnheadSchemaOrg } from './shared/schema-org.dfa583ec.mjs';
2
+ export { H as HowToId, a1 as PluginSchemaOrg, P as PrimaryArticleId, k as PrimaryBookId, m as PrimaryBreadcrumbId, s as PrimaryEventId, X as PrimaryWebPageId, _ as PrimaryWebSiteId, M as ProductId, R as RecipeId, a2 as SchemaOrgUnheadPlugin, L as addressResolver, g as aggregateOfferResolver, h as aggregateRatingResolver, i as articleResolver, j as bookEditionResolver, l as bookResolver, o as breadcrumbResolver, p as commentResolver, q as courseResolver, c as createSchemaOrgGraph, a as dedupeNodes, d as defineSchemaOrgResolver, t as eventResolver, w as foodEstablishmentResolver, x as howToResolver, z as howToStepDirectionResolver, y as howToStepResolver, B as imageResolver, A as itemListResolver, C as jobPostingResolver, D as listItemResolver, E as localBusinessResolver, F as movieResolver, n as normaliseNodes, G as offerResolver, I as openingHoursResolver, J as organizationResolver, K as personResolver, u as placeResolver, N as productResolver, O as questionResolver, Q as ratingResolver, Z as readActionResolver, S as recipeResolver, r as resolveMeta, b as resolveNode, e as resolveNodeId, f as resolveRelation, V as reviewResolver, a0 as searchActionResolver, T as softwareAppResolver, W as videoResolver, v as virtualLocationResolver, Y as webPageResolver, $ as webSiteResolver } from './shared/schema-org.dfa583ec.mjs';
3
3
  import { getActiveHead, useHead } from 'unhead';
4
4
  import 'ufo';
5
5
 
@@ -51,17 +51,14 @@ function asArray(input) {
51
51
  return Array.isArray(input) ? input : [input];
52
52
  }
53
53
  function dedupeMerge(node, field, value) {
54
- const dedupeMerge2 = [];
55
- const input = asArray(node[field]);
56
- dedupeMerge2.push(...input);
57
- const data = new Set(dedupeMerge2);
54
+ const data = new Set(asArray(node[field]));
58
55
  data.add(value);
59
- node[field] = [...data.values()].filter(Boolean);
56
+ node[field] = [...data].filter(Boolean);
60
57
  }
61
58
  function prefixId(url, id) {
62
59
  if (ufo.hasProtocol(id))
63
60
  return id;
64
- if (!id.startsWith("#"))
61
+ if (id[0] !== "#")
65
62
  id = `#${id}`;
66
63
  return ufo.withBase(id, url);
67
64
  }
@@ -85,7 +82,7 @@ function resolveDefaultType(node, defaultType) {
85
82
  node["@type"] = types.size === 1 ? val : [...types.values()];
86
83
  }
87
84
  function resolveWithBase(base, urlOrPath) {
88
- if (!urlOrPath || ufo.hasProtocol(urlOrPath) || !urlOrPath.startsWith("/") && !urlOrPath.startsWith("#"))
85
+ if (!urlOrPath || ufo.hasProtocol(urlOrPath) || urlOrPath[0] !== "/" && urlOrPath[0] !== "#")
89
86
  return urlOrPath;
90
87
  return ufo.withBase(urlOrPath, base);
91
88
  }
@@ -95,16 +92,19 @@ function resolveAsGraphKey(key) {
95
92
  return key.substring(key.lastIndexOf("#"));
96
93
  }
97
94
  function stripEmptyProperties(obj) {
98
- Object.keys(obj).forEach((k) => {
95
+ for (const k in obj) {
96
+ if (!Object.prototype.hasOwnProperty.call(obj, k)) {
97
+ continue;
98
+ }
99
99
  if (obj[k] && typeof obj[k] === "object") {
100
100
  if (obj[k].__v_isReadonly || obj[k].__v_isRef)
101
101
  return;
102
102
  stripEmptyProperties(obj[k]);
103
103
  return;
104
104
  }
105
- if (obj[k] === "" || obj[k] === null || typeof obj[k] === "undefined")
105
+ if (obj[k] === "" || obj[k] === null || obj[k] === void 0)
106
106
  delete obj[k];
107
- });
107
+ }
108
108
  return obj;
109
109
  }
110
110
 
@@ -1718,39 +1718,45 @@ function hashCode(s) {
1718
1718
  }
1719
1719
 
1720
1720
  const sepSub = "%separator";
1721
+ function sub(p, token) {
1722
+ let val;
1723
+ if (token === "s" || token === "pageTitle") {
1724
+ val = p.pageTitle;
1725
+ } else if (token.includes(".")) {
1726
+ const dotIndex = token.indexOf(".");
1727
+ val = p[token.substring(0, dotIndex)]?.[token.substring(dotIndex + 1)];
1728
+ } else {
1729
+ val = p[token];
1730
+ }
1731
+ return val !== void 0 ? (val || "").replace(/"/g, '\\"') : void 0;
1732
+ }
1733
+ const sepSubRe = new RegExp(`${sepSub}(?:\\s*${sepSub})*`, "g");
1721
1734
  function processTemplateParams(s, p, sep) {
1722
1735
  if (typeof s !== "string" || !s.includes("%"))
1723
1736
  return s;
1724
- function sub(token) {
1725
- let val;
1726
- if (["s", "pageTitle"].includes(token)) {
1727
- val = p.pageTitle;
1728
- } else if (token.includes(".")) {
1729
- val = token.split(".").reduce((acc, key) => acc ? acc[key] || void 0 : void 0, p);
1730
- } else {
1731
- val = p[token];
1732
- }
1733
- return typeof val !== "undefined" ? (val || "").replace(/"/g, '\\"') : false;
1734
- }
1735
1737
  let decoded = s;
1736
1738
  try {
1737
1739
  decoded = decodeURI(s);
1738
1740
  } catch {
1739
1741
  }
1740
- const tokens = (decoded.match(/%(\w+\.+\w+)|%(\w+)/g) || []).sort().reverse();
1741
- tokens.forEach((token) => {
1742
- const re = sub(token.slice(1));
1743
- if (typeof re === "string") {
1744
- s = s.replace(new RegExp(`\\${token}(\\W|$)`, "g"), (_, args) => `${re}${args}`).trim();
1742
+ const tokens = decoded.match(/%\w+(?:\.\w+)?/g);
1743
+ if (!tokens) {
1744
+ return s;
1745
+ }
1746
+ const hasSepSub = s.includes(sepSub);
1747
+ s = s.replace(/%\w+(?:\.\w+)?/g, (token) => {
1748
+ if (token === sepSub || !tokens.includes(token)) {
1749
+ return token;
1745
1750
  }
1746
- });
1747
- if (s.includes(sepSub)) {
1751
+ const re = sub(p, token.slice(1));
1752
+ return re !== void 0 ? re : token;
1753
+ }).trim();
1754
+ if (hasSepSub) {
1748
1755
  if (s.endsWith(sepSub))
1749
- s = s.slice(0, -sepSub.length).trim();
1756
+ s = s.slice(0, -sepSub.length);
1750
1757
  if (s.startsWith(sepSub))
1751
- s = s.slice(sepSub.length).trim();
1752
- s = s.replace(new RegExp(`\\${sepSub}\\s*\\${sepSub}`, "g"), sepSub);
1753
- s = processTemplateParams(s, { separator: sep }, sep);
1758
+ s = s.slice(sepSub.length);
1759
+ s = s.replace(sepSubRe, sep).trim();
1754
1760
  }
1755
1761
  return s;
1756
1762
  }
@@ -1918,10 +1924,15 @@ function resolveNodeId(node, ctx, resolver, resolveAsRoot = false) {
1918
1924
  alias = type.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
1919
1925
  }
1920
1926
  const hashNodeData = {};
1921
- Object.entries(node).forEach(([key, val]) => {
1922
- if (!key.startsWith("_"))
1923
- hashNodeData[key] = val;
1924
- });
1927
+ for (const key in node) {
1928
+ if (key[0] === "_") {
1929
+ continue;
1930
+ }
1931
+ if (!Object.prototype.hasOwnProperty.call(node, key)) {
1932
+ continue;
1933
+ }
1934
+ hashNodeData[key] = node[key];
1935
+ }
1925
1936
  node["@id"] = prefixId(ctx.meta[prefix], `#/schema/${alias}/${node["@id"] || hashCode(JSON.stringify(hashNodeData))}`);
1926
1937
  return node;
1927
1938
  }
@@ -2059,7 +2070,7 @@ function normaliseNodes(nodes) {
2059
2070
  const nodeKey = resolveAsGraphKey(n["@id"] || hash(n));
2060
2071
  const groupedKeys = groupBy(Object.keys(n), (key2) => {
2061
2072
  const val = n[key2];
2062
- if (key2.startsWith("_"))
2073
+ if (key2[0] === "_")
2063
2074
  return "ignored";
2064
2075
  if (Array.isArray(val) || typeof val === "object")
2065
2076
  return "relations";
@@ -2134,10 +2145,10 @@ function SchemaOrgUnheadPlugin(config, meta, options) {
2134
2145
  return defineHeadPlugin((head) => ({
2135
2146
  key: "schema-org",
2136
2147
  hooks: {
2137
- "entries:resolve": function() {
2148
+ "entries:resolve": () => {
2138
2149
  graph = createSchemaOrgGraph();
2139
2150
  },
2140
- "tag:normalise": async function({ tag }) {
2151
+ "tag:normalise": async ({ tag }) => {
2141
2152
  if (tag.key === "schema-org-graph") {
2142
2153
  const { loadResolver } = await Promise.resolve().then(function () { return resolver; });
2143
2154
  const nodes = await tag.props.nodes;
@@ -2175,7 +2186,7 @@ function SchemaOrgUnheadPlugin(config, meta, options) {
2175
2186
  delete tag.props.schemaOrg;
2176
2187
  }
2177
2188
  },
2178
- "tags:resolve": async function(ctx) {
2189
+ "tags:resolve": async (ctx) => {
2179
2190
  for (const tag of ctx.tags) {
2180
2191
  if (tag.tag === "script" && tag.key === "schema-org-graph") {
2181
2192
  const minify = options?.minify || process.env.NODE_ENV === "production";
@@ -49,17 +49,14 @@ function asArray(input) {
49
49
  return Array.isArray(input) ? input : [input];
50
50
  }
51
51
  function dedupeMerge(node, field, value) {
52
- const dedupeMerge2 = [];
53
- const input = asArray(node[field]);
54
- dedupeMerge2.push(...input);
55
- const data = new Set(dedupeMerge2);
52
+ const data = new Set(asArray(node[field]));
56
53
  data.add(value);
57
- node[field] = [...data.values()].filter(Boolean);
54
+ node[field] = [...data].filter(Boolean);
58
55
  }
59
56
  function prefixId(url, id) {
60
57
  if (hasProtocol(id))
61
58
  return id;
62
- if (!id.startsWith("#"))
59
+ if (id[0] !== "#")
63
60
  id = `#${id}`;
64
61
  return withBase(id, url);
65
62
  }
@@ -83,7 +80,7 @@ function resolveDefaultType(node, defaultType) {
83
80
  node["@type"] = types.size === 1 ? val : [...types.values()];
84
81
  }
85
82
  function resolveWithBase(base, urlOrPath) {
86
- if (!urlOrPath || hasProtocol(urlOrPath) || !urlOrPath.startsWith("/") && !urlOrPath.startsWith("#"))
83
+ if (!urlOrPath || hasProtocol(urlOrPath) || urlOrPath[0] !== "/" && urlOrPath[0] !== "#")
87
84
  return urlOrPath;
88
85
  return withBase(urlOrPath, base);
89
86
  }
@@ -93,16 +90,19 @@ function resolveAsGraphKey(key) {
93
90
  return key.substring(key.lastIndexOf("#"));
94
91
  }
95
92
  function stripEmptyProperties(obj) {
96
- Object.keys(obj).forEach((k) => {
93
+ for (const k in obj) {
94
+ if (!Object.prototype.hasOwnProperty.call(obj, k)) {
95
+ continue;
96
+ }
97
97
  if (obj[k] && typeof obj[k] === "object") {
98
98
  if (obj[k].__v_isReadonly || obj[k].__v_isRef)
99
99
  return;
100
100
  stripEmptyProperties(obj[k]);
101
101
  return;
102
102
  }
103
- if (obj[k] === "" || obj[k] === null || typeof obj[k] === "undefined")
103
+ if (obj[k] === "" || obj[k] === null || obj[k] === void 0)
104
104
  delete obj[k];
105
- });
105
+ }
106
106
  return obj;
107
107
  }
108
108
 
@@ -1716,39 +1716,45 @@ function hashCode(s) {
1716
1716
  }
1717
1717
 
1718
1718
  const sepSub = "%separator";
1719
+ function sub(p, token) {
1720
+ let val;
1721
+ if (token === "s" || token === "pageTitle") {
1722
+ val = p.pageTitle;
1723
+ } else if (token.includes(".")) {
1724
+ const dotIndex = token.indexOf(".");
1725
+ val = p[token.substring(0, dotIndex)]?.[token.substring(dotIndex + 1)];
1726
+ } else {
1727
+ val = p[token];
1728
+ }
1729
+ return val !== void 0 ? (val || "").replace(/"/g, '\\"') : void 0;
1730
+ }
1731
+ const sepSubRe = new RegExp(`${sepSub}(?:\\s*${sepSub})*`, "g");
1719
1732
  function processTemplateParams(s, p, sep) {
1720
1733
  if (typeof s !== "string" || !s.includes("%"))
1721
1734
  return s;
1722
- function sub(token) {
1723
- let val;
1724
- if (["s", "pageTitle"].includes(token)) {
1725
- val = p.pageTitle;
1726
- } else if (token.includes(".")) {
1727
- val = token.split(".").reduce((acc, key) => acc ? acc[key] || void 0 : void 0, p);
1728
- } else {
1729
- val = p[token];
1730
- }
1731
- return typeof val !== "undefined" ? (val || "").replace(/"/g, '\\"') : false;
1732
- }
1733
1735
  let decoded = s;
1734
1736
  try {
1735
1737
  decoded = decodeURI(s);
1736
1738
  } catch {
1737
1739
  }
1738
- const tokens = (decoded.match(/%(\w+\.+\w+)|%(\w+)/g) || []).sort().reverse();
1739
- tokens.forEach((token) => {
1740
- const re = sub(token.slice(1));
1741
- if (typeof re === "string") {
1742
- s = s.replace(new RegExp(`\\${token}(\\W|$)`, "g"), (_, args) => `${re}${args}`).trim();
1740
+ const tokens = decoded.match(/%\w+(?:\.\w+)?/g);
1741
+ if (!tokens) {
1742
+ return s;
1743
+ }
1744
+ const hasSepSub = s.includes(sepSub);
1745
+ s = s.replace(/%\w+(?:\.\w+)?/g, (token) => {
1746
+ if (token === sepSub || !tokens.includes(token)) {
1747
+ return token;
1743
1748
  }
1744
- });
1745
- if (s.includes(sepSub)) {
1749
+ const re = sub(p, token.slice(1));
1750
+ return re !== void 0 ? re : token;
1751
+ }).trim();
1752
+ if (hasSepSub) {
1746
1753
  if (s.endsWith(sepSub))
1747
- s = s.slice(0, -sepSub.length).trim();
1754
+ s = s.slice(0, -sepSub.length);
1748
1755
  if (s.startsWith(sepSub))
1749
- s = s.slice(sepSub.length).trim();
1750
- s = s.replace(new RegExp(`\\${sepSub}\\s*\\${sepSub}`, "g"), sepSub);
1751
- s = processTemplateParams(s, { separator: sep }, sep);
1756
+ s = s.slice(sepSub.length);
1757
+ s = s.replace(sepSubRe, sep).trim();
1752
1758
  }
1753
1759
  return s;
1754
1760
  }
@@ -1916,10 +1922,15 @@ function resolveNodeId(node, ctx, resolver, resolveAsRoot = false) {
1916
1922
  alias = type.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
1917
1923
  }
1918
1924
  const hashNodeData = {};
1919
- Object.entries(node).forEach(([key, val]) => {
1920
- if (!key.startsWith("_"))
1921
- hashNodeData[key] = val;
1922
- });
1925
+ for (const key in node) {
1926
+ if (key[0] === "_") {
1927
+ continue;
1928
+ }
1929
+ if (!Object.prototype.hasOwnProperty.call(node, key)) {
1930
+ continue;
1931
+ }
1932
+ hashNodeData[key] = node[key];
1933
+ }
1923
1934
  node["@id"] = prefixId(ctx.meta[prefix], `#/schema/${alias}/${node["@id"] || hashCode(JSON.stringify(hashNodeData))}`);
1924
1935
  return node;
1925
1936
  }
@@ -2057,7 +2068,7 @@ function normaliseNodes(nodes) {
2057
2068
  const nodeKey = resolveAsGraphKey(n["@id"] || hash(n));
2058
2069
  const groupedKeys = groupBy(Object.keys(n), (key2) => {
2059
2070
  const val = n[key2];
2060
- if (key2.startsWith("_"))
2071
+ if (key2[0] === "_")
2061
2072
  return "ignored";
2062
2073
  if (Array.isArray(val) || typeof val === "object")
2063
2074
  return "relations";
@@ -2132,10 +2143,10 @@ function SchemaOrgUnheadPlugin(config, meta, options) {
2132
2143
  return defineHeadPlugin((head) => ({
2133
2144
  key: "schema-org",
2134
2145
  hooks: {
2135
- "entries:resolve": function() {
2146
+ "entries:resolve": () => {
2136
2147
  graph = createSchemaOrgGraph();
2137
2148
  },
2138
- "tag:normalise": async function({ tag }) {
2149
+ "tag:normalise": async ({ tag }) => {
2139
2150
  if (tag.key === "schema-org-graph") {
2140
2151
  const { loadResolver } = await Promise.resolve().then(function () { return resolver; });
2141
2152
  const nodes = await tag.props.nodes;
@@ -2173,7 +2184,7 @@ function SchemaOrgUnheadPlugin(config, meta, options) {
2173
2184
  delete tag.props.schemaOrg;
2174
2185
  }
2175
2186
  },
2176
- "tags:resolve": async function(ctx) {
2187
+ "tags:resolve": async (ctx) => {
2177
2188
  for (const tag of ctx.tags) {
2178
2189
  if (tag.tag === "script" && tag.key === "schema-org-graph") {
2179
2190
  const minify = options?.minify || process.env.NODE_ENV === "production";
package/dist/vue.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const plugin = require('./shared/schema-org.97103adc.cjs');
3
+ const plugin = require('./shared/schema-org.74d623f8.cjs');
4
4
  const vue = require('@unhead/vue');
5
5
  const vue$1 = require('vue');
6
6
  require('ufo');
@@ -236,7 +236,7 @@ function fixKey(s) {
236
236
  function ignoreKey(s) {
237
237
  if (s.startsWith("aria-") || s.startsWith("data-"))
238
238
  return false;
239
- return ["class", "style"].includes(s);
239
+ return s === "class" || s === "style";
240
240
  }
241
241
  function defineSchemaOrgComponent(name, defineFn) {
242
242
  return vue$1.defineComponent({
package/dist/vue.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { U as UnheadSchemaOrg } from './shared/schema-org.2da2cd3d.mjs';
2
- export { a1 as PluginSchemaOrg, a2 as SchemaOrgUnheadPlugin } from './shared/schema-org.2da2cd3d.mjs';
1
+ import { U as UnheadSchemaOrg } from './shared/schema-org.dfa583ec.mjs';
2
+ export { a1 as PluginSchemaOrg, a2 as SchemaOrgUnheadPlugin } from './shared/schema-org.dfa583ec.mjs';
3
3
  import { injectHead, useHead } from '@unhead/vue';
4
4
  import { defineComponent, ref, computed, unref, h } from 'vue';
5
5
  import 'ufo';
@@ -235,7 +235,7 @@ function fixKey(s) {
235
235
  function ignoreKey(s) {
236
236
  if (s.startsWith("aria-") || s.startsWith("data-"))
237
237
  return false;
238
- return ["class", "style"].includes(s);
238
+ return s === "class" || s === "style";
239
239
  }
240
240
  function defineSchemaOrgComponent(name, defineFn) {
241
241
  return defineComponent({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unhead/schema-org",
3
- "version": "1.9.16",
3
+ "version": "1.10.0-beta.3",
4
4
  "description": "Unhead Schema.org for Simple and Automated Google Rich Results",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
@@ -39,15 +39,19 @@
39
39
  "dist"
40
40
  ],
41
41
  "dependencies": {
42
- "ufo": "^1.5.3"
42
+ "ufo": "^1.5.4"
43
+ },
44
+ "build": {
45
+ "external": [
46
+ "vue"
47
+ ]
43
48
  },
44
49
  "devDependencies": {
45
- "unplugin-vue-components": "^0.27.2",
46
- "vue": "^3.4.31",
47
- "@unhead/shared": "1.9.16",
48
- "@unhead/schema": "1.9.16",
49
- "@unhead/vue": "1.9.16",
50
- "unhead": "1.9.16"
50
+ "unplugin-vue-components": "^0.27.3",
51
+ "@unhead/schema": "1.10.0-beta.3",
52
+ "@unhead/shared": "1.10.0-beta.3",
53
+ "@unhead/vue": "1.10.0-beta.3",
54
+ "unhead": "1.10.0-beta.3"
51
55
  },
52
56
  "scripts": {
53
57
  "build": "unbuild .",