@unhead/schema-org 0.0.7 → 0.1.0

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Schema.org for Vue. Supports typed and automated Google Rich Results
4
4
 
5
- [Documentation](https://vue-schema-org.netlify.app/)
5
+ [Documentation](https://unhead-schema-org.harlanzw.com//)
6
6
 
7
7
  ## License
8
8
 
package/dist/index.cjs CHANGED
@@ -1,14 +1,73 @@
1
1
  'use strict';
2
2
 
3
- const ohash = require('ohash');
4
- const defu = require('defu');
5
- const ufo = require('ufo');
6
3
  const unhead = require('unhead');
7
4
 
8
5
  function defineSchemaOrgResolver(schema) {
9
6
  return schema;
10
7
  }
11
8
 
9
+ const PROTOCOL_REGEX = /^\w{2,}:(\/\/)?/;
10
+ const PROTOCOL_RELATIVE_REGEX = /^\/\/[^/]+/;
11
+ function hasProtocol(inputString, acceptProtocolRelative = false) {
12
+ return PROTOCOL_REGEX.test(inputString) || acceptProtocolRelative && PROTOCOL_RELATIVE_REGEX.test(inputString);
13
+ }
14
+ const TRAILING_SLASH_RE = /\/$|\/\?/;
15
+ function hasTrailingSlash(input = "", queryParameters = false) {
16
+ if (!queryParameters) {
17
+ return input.endsWith("/");
18
+ }
19
+ return TRAILING_SLASH_RE.test(input);
20
+ }
21
+ function withoutTrailingSlash(input = "", queryParameters = false) {
22
+ if (!queryParameters) {
23
+ return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
24
+ }
25
+ if (!hasTrailingSlash(input, true)) {
26
+ return input || "/";
27
+ }
28
+ const [s0, ...s] = input.split("?");
29
+ return (s0.slice(0, -1) || "/") + (s.length > 0 ? `?${s.join("?")}` : "");
30
+ }
31
+ function withTrailingSlash(input = "", queryParameters = false) {
32
+ if (!queryParameters) {
33
+ return input.endsWith("/") ? input : input + "/";
34
+ }
35
+ if (hasTrailingSlash(input, true)) {
36
+ return input || "/";
37
+ }
38
+ const [s0, ...s] = input.split("?");
39
+ return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
40
+ }
41
+ function hasLeadingSlash(input = "") {
42
+ return input.startsWith("/");
43
+ }
44
+ function withoutLeadingSlash(input = "") {
45
+ return (hasLeadingSlash(input) ? input.slice(1) : input) || "/";
46
+ }
47
+ function withBase(input, base) {
48
+ if (isEmptyURL(base) || hasProtocol(input)) {
49
+ return input;
50
+ }
51
+ const _base = withoutTrailingSlash(base);
52
+ if (input.startsWith(_base)) {
53
+ return input;
54
+ }
55
+ return joinURL(_base, input);
56
+ }
57
+ function isEmptyURL(url) {
58
+ return !url || url === "/";
59
+ }
60
+ function isNonEmptyURL(url) {
61
+ return url && url !== "/";
62
+ }
63
+ function joinURL(base, ...input) {
64
+ let url = base || "";
65
+ for (const index of input.filter((url2) => isNonEmptyURL(url2))) {
66
+ url = url ? withTrailingSlash(url) + withoutLeadingSlash(index) : index;
67
+ }
68
+ return url;
69
+ }
70
+
12
71
  const idReference = (node) => ({
13
72
  "@id": typeof node !== "string" ? node["@id"] : node
14
73
  });
@@ -47,11 +106,11 @@ const dedupeMerge = (node, field, value) => {
47
106
  node[field] = [...data.values()].filter(Boolean);
48
107
  };
49
108
  const prefixId = (url, id) => {
50
- if (ufo.hasProtocol(id))
109
+ if (hasProtocol(id))
51
110
  return url;
52
111
  if (!id.startsWith("#"))
53
112
  id = `#${id}`;
54
- return ufo.joinURL(url, id);
113
+ return joinURL(url, id);
55
114
  };
56
115
  const trimLength = (val, length) => {
57
116
  if (!val)
@@ -73,9 +132,9 @@ const resolveDefaultType = (node, defaultType) => {
73
132
  node["@type"] = types.size === 1 ? val : [...types.values()];
74
133
  };
75
134
  const resolveWithBase = (base, urlOrPath) => {
76
- if (!urlOrPath || ufo.hasProtocol(urlOrPath) || !urlOrPath.startsWith("/") && !urlOrPath.startsWith("#"))
135
+ if (!urlOrPath || hasProtocol(urlOrPath) || !urlOrPath.startsWith("/") && !urlOrPath.startsWith("#"))
77
136
  return urlOrPath;
78
- return ufo.withBase(urlOrPath, base);
137
+ return withBase(urlOrPath, base);
79
138
  };
80
139
  const resolveAsGraphKey = (key) => {
81
140
  if (!key)
@@ -95,6 +154,12 @@ const stripEmptyProperties = (obj) => {
95
154
  });
96
155
  return obj;
97
156
  };
157
+ function hashCode(s) {
158
+ let h = 9;
159
+ for (let i = 0; i < s.length; )
160
+ h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
161
+ return ((h ^ h >>> 9) + 65536).toString(16).substring(1, 8).toLowerCase();
162
+ }
98
163
 
99
164
  const offerResolver = defineSchemaOrgResolver({
100
165
  cast(node) {
@@ -115,7 +180,7 @@ const offerResolver = defineSchemaOrgResolver({
115
180
  if (node.url)
116
181
  resolveWithBase(ctx.meta.host, node.url);
117
182
  if (node.availability)
118
- node.availability = ufo.withBase(node.availability, "https://schema.org/");
183
+ node.availability = withBase(node.availability, "https://schema.org/");
119
184
  if (node.priceValidUntil)
120
185
  node.priceValidUntil = resolvableDateToIso(node.priceValidUntil);
121
186
  return node;
@@ -353,7 +418,7 @@ const readActionResolver = defineSchemaOrgResolver({
353
418
  const PrimaryWebPageId = "#webpage";
354
419
  const webPageResolver = defineSchemaOrgResolver({
355
420
  defaults({ meta }) {
356
- const endPath = ufo.withoutTrailingSlash(meta.url.substring(meta.url.lastIndexOf("/") + 1));
421
+ const endPath = withoutTrailingSlash(meta.url.substring(meta.url.lastIndexOf("/") + 1));
357
422
  let type = "WebPage";
358
423
  switch (endPath) {
359
424
  case "about":
@@ -488,7 +553,7 @@ const bookEditionResolver = defineSchemaOrgResolver({
488
553
  ],
489
554
  resolve(node, ctx) {
490
555
  if (node.bookFormat)
491
- node.bookFormat = ufo.withBase(node.bookFormat, "https://schema.org/");
556
+ node.bookFormat = withBase(node.bookFormat, "https://schema.org/");
492
557
  if (node.datePublished)
493
558
  node.datePublished = resolvableDateToDate(node.datePublished);
494
559
  node.author = resolveRelation(node.author, ctx);
@@ -516,7 +581,7 @@ const bookResolver = defineSchemaOrgResolver({
516
581
  node.workExample = resolveRelation(node.workExample, ctx, bookEditionResolver);
517
582
  node.author = resolveRelation(node.author, ctx);
518
583
  if (node.url)
519
- ufo.withBase(node.url, ctx.meta.host);
584
+ withBase(node.url, ctx.meta.host);
520
585
  return node;
521
586
  },
522
587
  resolveRootNode(node, { find }) {
@@ -612,9 +677,9 @@ const eventResolver = defineSchemaOrgResolver({
612
677
  });
613
678
  node.offers = resolveRelation(node.offers, ctx, offerResolver);
614
679
  if (node.eventAttendanceMode)
615
- node.eventAttendanceMode = ufo.withBase(node.eventAttendanceMode, "https://schema.org/");
680
+ node.eventAttendanceMode = withBase(node.eventAttendanceMode, "https://schema.org/");
616
681
  if (node.eventStatus)
617
- node.eventStatus = ufo.withBase(node.eventStatus, "https://schema.org/");
682
+ node.eventStatus = withBase(node.eventStatus, "https://schema.org/");
618
683
  const isOnline = node.eventStatus === "https://schema.org/EventMovedOnline";
619
684
  const dates = ["startDate", "previousStartDate", "endDate"];
620
685
  dates.forEach((date) => {
@@ -793,6 +858,487 @@ const movieResolver = defineSchemaOrgResolver({
793
858
  }
794
859
  });
795
860
 
861
+ const defaults = {
862
+ ignoreUnknown: false,
863
+ respectType: false,
864
+ respectFunctionNames: false,
865
+ respectFunctionProperties: false,
866
+ unorderedObjects: true,
867
+ unorderedArrays: false,
868
+ unorderedSets: false
869
+ };
870
+ function objectHash(object, options = {}) {
871
+ options = { ...defaults, ...options };
872
+ const hasher = createHasher(options);
873
+ hasher.dispatch(object);
874
+ return hasher.toString();
875
+ }
876
+ function createHasher(options) {
877
+ const buff = [];
878
+ let context = [];
879
+ const write = (str) => {
880
+ buff.push(str);
881
+ };
882
+ return {
883
+ toString() {
884
+ return buff.join("");
885
+ },
886
+ getContext() {
887
+ return context;
888
+ },
889
+ dispatch(value) {
890
+ if (options.replacer) {
891
+ value = options.replacer(value);
892
+ }
893
+ const type = value === null ? "null" : typeof value;
894
+ return this["_" + type](value);
895
+ },
896
+ _object(object) {
897
+ const pattern = /\[object (.*)]/i;
898
+ const objString = Object.prototype.toString.call(object);
899
+ const _objType = pattern.exec(objString);
900
+ const objType = _objType ? _objType[1].toLowerCase() : "unknown:[" + objString.toLowerCase() + "]";
901
+ let objectNumber = null;
902
+ if ((objectNumber = context.indexOf(object)) >= 0) {
903
+ return this.dispatch("[CIRCULAR:" + objectNumber + "]");
904
+ } else {
905
+ context.push(object);
906
+ }
907
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
908
+ write("buffer:");
909
+ return write(object.toString("utf8"));
910
+ }
911
+ if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
912
+ if (this["_" + objType]) {
913
+ this["_" + objType](object);
914
+ } else if (options.ignoreUnknown) {
915
+ return write("[" + objType + "]");
916
+ } else {
917
+ throw new Error('Unknown object type "' + objType + '"');
918
+ }
919
+ } else {
920
+ let keys = Object.keys(object);
921
+ if (options.unorderedObjects) {
922
+ keys = keys.sort();
923
+ }
924
+ if (options.respectType !== false && !isNativeFunction(object)) {
925
+ keys.splice(0, 0, "prototype", "__proto__", "letructor");
926
+ }
927
+ if (options.excludeKeys) {
928
+ keys = keys.filter(function(key) {
929
+ return !options.excludeKeys(key);
930
+ });
931
+ }
932
+ write("object:" + keys.length + ":");
933
+ for (const key of keys) {
934
+ this.dispatch(key);
935
+ write(":");
936
+ if (!options.excludeValues) {
937
+ this.dispatch(object[key]);
938
+ }
939
+ write(",");
940
+ }
941
+ }
942
+ },
943
+ _array(arr, unordered) {
944
+ unordered = typeof unordered !== "undefined" ? unordered : options.unorderedArrays !== false;
945
+ write("array:" + arr.length + ":");
946
+ if (!unordered || arr.length <= 1) {
947
+ for (const entry of arr) {
948
+ this.dispatch(entry);
949
+ }
950
+ return;
951
+ }
952
+ const contextAdditions = [];
953
+ const entries = arr.map((entry) => {
954
+ const hasher = createHasher(options);
955
+ hasher.dispatch(entry);
956
+ contextAdditions.push(hasher.getContext());
957
+ return hasher.toString();
958
+ });
959
+ context = [...context, ...contextAdditions];
960
+ entries.sort();
961
+ return this._array(entries, false);
962
+ },
963
+ _date(date) {
964
+ return write("date:" + date.toJSON());
965
+ },
966
+ _symbol(sym) {
967
+ return write("symbol:" + sym.toString());
968
+ },
969
+ _error(err) {
970
+ return write("error:" + err.toString());
971
+ },
972
+ _boolean(bool) {
973
+ return write("bool:" + bool.toString());
974
+ },
975
+ _string(string) {
976
+ write("string:" + string.length + ":");
977
+ write(string.toString());
978
+ },
979
+ _function(fn) {
980
+ write("fn:");
981
+ if (isNativeFunction(fn)) {
982
+ this.dispatch("[native]");
983
+ } else {
984
+ this.dispatch(fn.toString());
985
+ }
986
+ if (options.respectFunctionNames !== false) {
987
+ this.dispatch("function-name:" + String(fn.name));
988
+ }
989
+ if (options.respectFunctionProperties) {
990
+ this._object(fn);
991
+ }
992
+ },
993
+ _number(number) {
994
+ return write("number:" + number.toString());
995
+ },
996
+ _xml(xml) {
997
+ return write("xml:" + xml.toString());
998
+ },
999
+ _null() {
1000
+ return write("Null");
1001
+ },
1002
+ _undefined() {
1003
+ return write("Undefined");
1004
+ },
1005
+ _regexp(regex) {
1006
+ return write("regex:" + regex.toString());
1007
+ },
1008
+ _uint8array(arr) {
1009
+ write("uint8array:");
1010
+ return this.dispatch(Array.prototype.slice.call(arr));
1011
+ },
1012
+ _uint8clampedarray(arr) {
1013
+ write("uint8clampedarray:");
1014
+ return this.dispatch(Array.prototype.slice.call(arr));
1015
+ },
1016
+ _int8array(arr) {
1017
+ write("int8array:");
1018
+ return this.dispatch(Array.prototype.slice.call(arr));
1019
+ },
1020
+ _uint16array(arr) {
1021
+ write("uint16array:");
1022
+ return this.dispatch(Array.prototype.slice.call(arr));
1023
+ },
1024
+ _int16array(arr) {
1025
+ write("int16array:");
1026
+ return this.dispatch(Array.prototype.slice.call(arr));
1027
+ },
1028
+ _uint32array(arr) {
1029
+ write("uint32array:");
1030
+ return this.dispatch(Array.prototype.slice.call(arr));
1031
+ },
1032
+ _int32array(arr) {
1033
+ write("int32array:");
1034
+ return this.dispatch(Array.prototype.slice.call(arr));
1035
+ },
1036
+ _float32array(arr) {
1037
+ write("float32array:");
1038
+ return this.dispatch(Array.prototype.slice.call(arr));
1039
+ },
1040
+ _float64array(arr) {
1041
+ write("float64array:");
1042
+ return this.dispatch(Array.prototype.slice.call(arr));
1043
+ },
1044
+ _arraybuffer(arr) {
1045
+ write("arraybuffer:");
1046
+ return this.dispatch(new Uint8Array(arr));
1047
+ },
1048
+ _url(url) {
1049
+ return write("url:" + url.toString());
1050
+ },
1051
+ _map(map) {
1052
+ write("map:");
1053
+ const arr = [...map];
1054
+ return this._array(arr, options.unorderedSets !== false);
1055
+ },
1056
+ _set(set) {
1057
+ write("set:");
1058
+ const arr = [...set];
1059
+ return this._array(arr, options.unorderedSets !== false);
1060
+ },
1061
+ _file(file) {
1062
+ write("file:");
1063
+ return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
1064
+ },
1065
+ _blob() {
1066
+ if (options.ignoreUnknown) {
1067
+ return write("[blob]");
1068
+ }
1069
+ throw new Error('Hashing Blob objects is currently not supported\nUse "options.replacer" or "options.ignoreUnknown"\n');
1070
+ },
1071
+ _domwindow() {
1072
+ return write("domwindow");
1073
+ },
1074
+ _bigint(number) {
1075
+ return write("bigint:" + number.toString());
1076
+ },
1077
+ _process() {
1078
+ return write("process");
1079
+ },
1080
+ _timer() {
1081
+ return write("timer");
1082
+ },
1083
+ _pipe() {
1084
+ return write("pipe");
1085
+ },
1086
+ _tcp() {
1087
+ return write("tcp");
1088
+ },
1089
+ _udp() {
1090
+ return write("udp");
1091
+ },
1092
+ _tty() {
1093
+ return write("tty");
1094
+ },
1095
+ _statwatcher() {
1096
+ return write("statwatcher");
1097
+ },
1098
+ _securecontext() {
1099
+ return write("securecontext");
1100
+ },
1101
+ _connection() {
1102
+ return write("connection");
1103
+ },
1104
+ _zlib() {
1105
+ return write("zlib");
1106
+ },
1107
+ _context() {
1108
+ return write("context");
1109
+ },
1110
+ _nodescript() {
1111
+ return write("nodescript");
1112
+ },
1113
+ _httpparser() {
1114
+ return write("httpparser");
1115
+ },
1116
+ _dataview() {
1117
+ return write("dataview");
1118
+ },
1119
+ _signal() {
1120
+ return write("signal");
1121
+ },
1122
+ _fsevent() {
1123
+ return write("fsevent");
1124
+ },
1125
+ _tlswrap() {
1126
+ return write("tlswrap");
1127
+ }
1128
+ };
1129
+ }
1130
+ function isNativeFunction(f) {
1131
+ if (typeof f !== "function") {
1132
+ return false;
1133
+ }
1134
+ const exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code]\s+}$/i;
1135
+ return exp.exec(Function.prototype.toString.call(f)) != null;
1136
+ }
1137
+
1138
+ class WordArray {
1139
+ constructor(words, sigBytes) {
1140
+ words = this.words = words || [];
1141
+ this.sigBytes = sigBytes !== void 0 ? sigBytes : words.length * 4;
1142
+ }
1143
+ toString(encoder) {
1144
+ return (encoder || Hex).stringify(this);
1145
+ }
1146
+ concat(wordArray) {
1147
+ this.clamp();
1148
+ if (this.sigBytes % 4) {
1149
+ for (let i = 0; i < wordArray.sigBytes; i++) {
1150
+ const thatByte = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
1151
+ this.words[this.sigBytes + i >>> 2] |= thatByte << 24 - (this.sigBytes + i) % 4 * 8;
1152
+ }
1153
+ } else {
1154
+ for (let j = 0; j < wordArray.sigBytes; j += 4) {
1155
+ this.words[this.sigBytes + j >>> 2] = wordArray.words[j >>> 2];
1156
+ }
1157
+ }
1158
+ this.sigBytes += wordArray.sigBytes;
1159
+ return this;
1160
+ }
1161
+ clamp() {
1162
+ this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8;
1163
+ this.words.length = Math.ceil(this.sigBytes / 4);
1164
+ }
1165
+ clone() {
1166
+ return new WordArray([...this.words]);
1167
+ }
1168
+ }
1169
+ const Hex = {
1170
+ stringify(wordArray) {
1171
+ const hexChars = [];
1172
+ for (let i = 0; i < wordArray.sigBytes; i++) {
1173
+ const bite = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
1174
+ hexChars.push(
1175
+ (bite >>> 4).toString(16),
1176
+ (bite & 15).toString(16)
1177
+ );
1178
+ }
1179
+ return hexChars.join("");
1180
+ }
1181
+ };
1182
+ const Base64 = {
1183
+ stringify(wordArray) {
1184
+ const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
1185
+ const base64Chars = [];
1186
+ for (let i = 0; i < wordArray.sigBytes; i += 3) {
1187
+ const byte1 = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
1188
+ const byte2 = wordArray.words[i + 1 >>> 2] >>> 24 - (i + 1) % 4 * 8 & 255;
1189
+ const byte3 = wordArray.words[i + 2 >>> 2] >>> 24 - (i + 2) % 4 * 8 & 255;
1190
+ const triplet = byte1 << 16 | byte2 << 8 | byte3;
1191
+ for (let j = 0; j < 4 && i * 8 + j * 6 < wordArray.sigBytes * 8; j++) {
1192
+ base64Chars.push(keyStr.charAt(triplet >>> 6 * (3 - j) & 63));
1193
+ }
1194
+ }
1195
+ return base64Chars.join("");
1196
+ }
1197
+ };
1198
+ const Latin1 = {
1199
+ parse(latin1Str) {
1200
+ const latin1StrLength = latin1Str.length;
1201
+ const words = [];
1202
+ for (let i = 0; i < latin1StrLength; i++) {
1203
+ words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8;
1204
+ }
1205
+ return new WordArray(words, latin1StrLength);
1206
+ }
1207
+ };
1208
+ const Utf8 = {
1209
+ parse(utf8Str) {
1210
+ return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
1211
+ }
1212
+ };
1213
+ class BufferedBlockAlgorithm {
1214
+ constructor() {
1215
+ this._minBufferSize = 0;
1216
+ this.blockSize = 512 / 32;
1217
+ this.reset();
1218
+ }
1219
+ reset() {
1220
+ this._data = new WordArray();
1221
+ this._nDataBytes = 0;
1222
+ }
1223
+ _append(data) {
1224
+ if (typeof data === "string") {
1225
+ data = Utf8.parse(data);
1226
+ }
1227
+ this._data.concat(data);
1228
+ this._nDataBytes += data.sigBytes;
1229
+ }
1230
+ _doProcessBlock(_dataWords, _offset) {
1231
+ }
1232
+ _process(doFlush) {
1233
+ let processedWords;
1234
+ let nBlocksReady = this._data.sigBytes / (this.blockSize * 4);
1235
+ if (doFlush) {
1236
+ nBlocksReady = Math.ceil(nBlocksReady);
1237
+ } else {
1238
+ nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
1239
+ }
1240
+ const nWordsReady = nBlocksReady * this.blockSize;
1241
+ const nBytesReady = Math.min(nWordsReady * 4, this._data.sigBytes);
1242
+ if (nWordsReady) {
1243
+ for (let offset = 0; offset < nWordsReady; offset += this.blockSize) {
1244
+ this._doProcessBlock(this._data.words, offset);
1245
+ }
1246
+ processedWords = this._data.words.splice(0, nWordsReady);
1247
+ this._data.sigBytes -= nBytesReady;
1248
+ }
1249
+ return new WordArray(processedWords, nBytesReady);
1250
+ }
1251
+ }
1252
+ class Hasher extends BufferedBlockAlgorithm {
1253
+ update(messageUpdate) {
1254
+ this._append(messageUpdate);
1255
+ this._process();
1256
+ return this;
1257
+ }
1258
+ finalize(messageUpdate) {
1259
+ if (messageUpdate) {
1260
+ this._append(messageUpdate);
1261
+ }
1262
+ }
1263
+ }
1264
+
1265
+ const H = [1779033703, -1150833019, 1013904242, -1521486534, 1359893119, -1694144372, 528734635, 1541459225];
1266
+ const K = [1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993, -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987, 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885, -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872, -1866530822, -1538233109, -1090935817, -965641998];
1267
+ const W = [];
1268
+ class SHA256 extends Hasher {
1269
+ constructor() {
1270
+ super();
1271
+ this.reset();
1272
+ }
1273
+ reset() {
1274
+ super.reset();
1275
+ this._hash = new WordArray([...H]);
1276
+ }
1277
+ _doProcessBlock(M, offset) {
1278
+ const H2 = this._hash.words;
1279
+ let a = H2[0];
1280
+ let b = H2[1];
1281
+ let c = H2[2];
1282
+ let d = H2[3];
1283
+ let e = H2[4];
1284
+ let f = H2[5];
1285
+ let g = H2[6];
1286
+ let h = H2[7];
1287
+ for (let i = 0; i < 64; i++) {
1288
+ if (i < 16) {
1289
+ W[i] = M[offset + i] | 0;
1290
+ } else {
1291
+ const gamma0x = W[i - 15];
1292
+ const gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
1293
+ const gamma1x = W[i - 2];
1294
+ const gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
1295
+ W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
1296
+ }
1297
+ const ch = e & f ^ ~e & g;
1298
+ const maj = a & b ^ a & c ^ b & c;
1299
+ const sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
1300
+ const sigma1 = (e << 26 | e >>> 6) ^ (e << 21 | e >>> 11) ^ (e << 7 | e >>> 25);
1301
+ const t1 = h + sigma1 + ch + K[i] + W[i];
1302
+ const t2 = sigma0 + maj;
1303
+ h = g;
1304
+ g = f;
1305
+ f = e;
1306
+ e = d + t1 | 0;
1307
+ d = c;
1308
+ c = b;
1309
+ b = a;
1310
+ a = t1 + t2 | 0;
1311
+ }
1312
+ H2[0] = H2[0] + a | 0;
1313
+ H2[1] = H2[1] + b | 0;
1314
+ H2[2] = H2[2] + c | 0;
1315
+ H2[3] = H2[3] + d | 0;
1316
+ H2[4] = H2[4] + e | 0;
1317
+ H2[5] = H2[5] + f | 0;
1318
+ H2[6] = H2[6] + g | 0;
1319
+ H2[7] = H2[7] + h | 0;
1320
+ }
1321
+ finalize(messageUpdate) {
1322
+ super.finalize(messageUpdate);
1323
+ const nBitsTotal = this._nDataBytes * 8;
1324
+ const nBitsLeft = this._data.sigBytes * 8;
1325
+ this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
1326
+ this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(nBitsTotal / 4294967296);
1327
+ this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
1328
+ this._data.sigBytes = this._data.words.length * 4;
1329
+ this._process();
1330
+ return this._hash;
1331
+ }
1332
+ }
1333
+ function sha256base64(message) {
1334
+ return new SHA256().finalize(message).toString(Base64);
1335
+ }
1336
+
1337
+ function hash(object, options = {}) {
1338
+ const hashed = typeof object === "string" ? object : objectHash(object, options);
1339
+ return sha256base64(hashed).slice(0, 10);
1340
+ }
1341
+
796
1342
  const ProductId = "#product";
797
1343
  const productResolver = defineSchemaOrgResolver({
798
1344
  defaults: {
@@ -805,7 +1351,7 @@ const productResolver = defineSchemaOrgResolver({
805
1351
  ],
806
1352
  idPrefix: ["url", ProductId],
807
1353
  resolve(node, ctx) {
808
- setIfEmpty(node, "sku", ohash.hash(node.name));
1354
+ setIfEmpty(node, "sku", hash(node.name));
809
1355
  node.aggregateOffer = resolveRelation(node.aggregateOffer, ctx, aggregateOfferResolver);
810
1356
  node.aggregateRating = resolveRelation(node.aggregateRating, ctx, aggregateRatingResolver);
811
1357
  node.offers = resolveRelation(node.offers, ctx, offerResolver);
@@ -1033,7 +1579,7 @@ const resolveMeta = (meta) => {
1033
1579
  meta.host = document.location.host;
1034
1580
  if (!meta.url && meta.canonicalUrl)
1035
1581
  meta.url = meta.canonicalUrl;
1036
- meta.url = ufo.joinURL(meta.host, meta.path);
1582
+ meta.url = joinURL(meta.host, meta.path);
1037
1583
  return {
1038
1584
  host: meta.host,
1039
1585
  url: meta.url,
@@ -1053,7 +1599,10 @@ const resolveNode = (node, ctx, resolver) => {
1053
1599
  let defaults = resolver.defaults || {};
1054
1600
  if (typeof defaults === "function")
1055
1601
  defaults = defaults(ctx);
1056
- node = defu.defu(node, defaults);
1602
+ node = {
1603
+ ...defaults,
1604
+ ...node
1605
+ };
1057
1606
  }
1058
1607
  resolver.inheritMeta?.forEach((entry) => {
1059
1608
  if (typeof entry === "string")
@@ -1094,7 +1643,7 @@ const resolveNodeId = (node, ctx, resolver, resolveAsRoot = false) => {
1094
1643
  if (!key.startsWith("_"))
1095
1644
  hashNodeData[key] = val;
1096
1645
  });
1097
- node["@id"] = prefixId(ctx.meta[prefix], `#/schema/${alias}/${ohash.hash(hashNodeData)}`);
1646
+ node["@id"] = prefixId(ctx.meta[prefix], `#/schema/${alias}/${hashCode(JSON.stringify(hashNodeData))}`);
1098
1647
  }
1099
1648
  return node;
1100
1649
  };
@@ -1143,7 +1692,7 @@ const dedupeNodes = (nodes) => {
1143
1692
  const dedupedNodes = {};
1144
1693
  for (const key of sortedNodeKeys) {
1145
1694
  const n = nodes[key];
1146
- const nodeKey = resolveAsGraphKey(n["@id"] || ohash.hash(n));
1695
+ const nodeKey = resolveAsGraphKey(n["@id"] || hash(n));
1147
1696
  const groupedKeys = groupBy(Object.keys(n), (key2) => {
1148
1697
  const val = n[key2];
1149
1698
  if (key2.startsWith("_"))
package/dist/index.mjs CHANGED
@@ -1,12 +1,71 @@
1
- import { hash } from 'ohash';
2
- import { defu } from 'defu';
3
- import { hasProtocol, joinURL, withBase, withoutTrailingSlash } from 'ufo';
4
1
  import { useHead } from 'unhead';
5
2
 
6
3
  function defineSchemaOrgResolver(schema) {
7
4
  return schema;
8
5
  }
9
6
 
7
+ const PROTOCOL_REGEX = /^\w{2,}:(\/\/)?/;
8
+ const PROTOCOL_RELATIVE_REGEX = /^\/\/[^/]+/;
9
+ function hasProtocol(inputString, acceptProtocolRelative = false) {
10
+ return PROTOCOL_REGEX.test(inputString) || acceptProtocolRelative && PROTOCOL_RELATIVE_REGEX.test(inputString);
11
+ }
12
+ const TRAILING_SLASH_RE = /\/$|\/\?/;
13
+ function hasTrailingSlash(input = "", queryParameters = false) {
14
+ if (!queryParameters) {
15
+ return input.endsWith("/");
16
+ }
17
+ return TRAILING_SLASH_RE.test(input);
18
+ }
19
+ function withoutTrailingSlash(input = "", queryParameters = false) {
20
+ if (!queryParameters) {
21
+ return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
22
+ }
23
+ if (!hasTrailingSlash(input, true)) {
24
+ return input || "/";
25
+ }
26
+ const [s0, ...s] = input.split("?");
27
+ return (s0.slice(0, -1) || "/") + (s.length > 0 ? `?${s.join("?")}` : "");
28
+ }
29
+ function withTrailingSlash(input = "", queryParameters = false) {
30
+ if (!queryParameters) {
31
+ return input.endsWith("/") ? input : input + "/";
32
+ }
33
+ if (hasTrailingSlash(input, true)) {
34
+ return input || "/";
35
+ }
36
+ const [s0, ...s] = input.split("?");
37
+ return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "");
38
+ }
39
+ function hasLeadingSlash(input = "") {
40
+ return input.startsWith("/");
41
+ }
42
+ function withoutLeadingSlash(input = "") {
43
+ return (hasLeadingSlash(input) ? input.slice(1) : input) || "/";
44
+ }
45
+ function withBase(input, base) {
46
+ if (isEmptyURL(base) || hasProtocol(input)) {
47
+ return input;
48
+ }
49
+ const _base = withoutTrailingSlash(base);
50
+ if (input.startsWith(_base)) {
51
+ return input;
52
+ }
53
+ return joinURL(_base, input);
54
+ }
55
+ function isEmptyURL(url) {
56
+ return !url || url === "/";
57
+ }
58
+ function isNonEmptyURL(url) {
59
+ return url && url !== "/";
60
+ }
61
+ function joinURL(base, ...input) {
62
+ let url = base || "";
63
+ for (const index of input.filter((url2) => isNonEmptyURL(url2))) {
64
+ url = url ? withTrailingSlash(url) + withoutLeadingSlash(index) : index;
65
+ }
66
+ return url;
67
+ }
68
+
10
69
  const idReference = (node) => ({
11
70
  "@id": typeof node !== "string" ? node["@id"] : node
12
71
  });
@@ -93,6 +152,12 @@ const stripEmptyProperties = (obj) => {
93
152
  });
94
153
  return obj;
95
154
  };
155
+ function hashCode(s) {
156
+ let h = 9;
157
+ for (let i = 0; i < s.length; )
158
+ h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
159
+ return ((h ^ h >>> 9) + 65536).toString(16).substring(1, 8).toLowerCase();
160
+ }
96
161
 
97
162
  const offerResolver = defineSchemaOrgResolver({
98
163
  cast(node) {
@@ -791,6 +856,487 @@ const movieResolver = defineSchemaOrgResolver({
791
856
  }
792
857
  });
793
858
 
859
+ const defaults = {
860
+ ignoreUnknown: false,
861
+ respectType: false,
862
+ respectFunctionNames: false,
863
+ respectFunctionProperties: false,
864
+ unorderedObjects: true,
865
+ unorderedArrays: false,
866
+ unorderedSets: false
867
+ };
868
+ function objectHash(object, options = {}) {
869
+ options = { ...defaults, ...options };
870
+ const hasher = createHasher(options);
871
+ hasher.dispatch(object);
872
+ return hasher.toString();
873
+ }
874
+ function createHasher(options) {
875
+ const buff = [];
876
+ let context = [];
877
+ const write = (str) => {
878
+ buff.push(str);
879
+ };
880
+ return {
881
+ toString() {
882
+ return buff.join("");
883
+ },
884
+ getContext() {
885
+ return context;
886
+ },
887
+ dispatch(value) {
888
+ if (options.replacer) {
889
+ value = options.replacer(value);
890
+ }
891
+ const type = value === null ? "null" : typeof value;
892
+ return this["_" + type](value);
893
+ },
894
+ _object(object) {
895
+ const pattern = /\[object (.*)]/i;
896
+ const objString = Object.prototype.toString.call(object);
897
+ const _objType = pattern.exec(objString);
898
+ const objType = _objType ? _objType[1].toLowerCase() : "unknown:[" + objString.toLowerCase() + "]";
899
+ let objectNumber = null;
900
+ if ((objectNumber = context.indexOf(object)) >= 0) {
901
+ return this.dispatch("[CIRCULAR:" + objectNumber + "]");
902
+ } else {
903
+ context.push(object);
904
+ }
905
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
906
+ write("buffer:");
907
+ return write(object.toString("utf8"));
908
+ }
909
+ if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
910
+ if (this["_" + objType]) {
911
+ this["_" + objType](object);
912
+ } else if (options.ignoreUnknown) {
913
+ return write("[" + objType + "]");
914
+ } else {
915
+ throw new Error('Unknown object type "' + objType + '"');
916
+ }
917
+ } else {
918
+ let keys = Object.keys(object);
919
+ if (options.unorderedObjects) {
920
+ keys = keys.sort();
921
+ }
922
+ if (options.respectType !== false && !isNativeFunction(object)) {
923
+ keys.splice(0, 0, "prototype", "__proto__", "letructor");
924
+ }
925
+ if (options.excludeKeys) {
926
+ keys = keys.filter(function(key) {
927
+ return !options.excludeKeys(key);
928
+ });
929
+ }
930
+ write("object:" + keys.length + ":");
931
+ for (const key of keys) {
932
+ this.dispatch(key);
933
+ write(":");
934
+ if (!options.excludeValues) {
935
+ this.dispatch(object[key]);
936
+ }
937
+ write(",");
938
+ }
939
+ }
940
+ },
941
+ _array(arr, unordered) {
942
+ unordered = typeof unordered !== "undefined" ? unordered : options.unorderedArrays !== false;
943
+ write("array:" + arr.length + ":");
944
+ if (!unordered || arr.length <= 1) {
945
+ for (const entry of arr) {
946
+ this.dispatch(entry);
947
+ }
948
+ return;
949
+ }
950
+ const contextAdditions = [];
951
+ const entries = arr.map((entry) => {
952
+ const hasher = createHasher(options);
953
+ hasher.dispatch(entry);
954
+ contextAdditions.push(hasher.getContext());
955
+ return hasher.toString();
956
+ });
957
+ context = [...context, ...contextAdditions];
958
+ entries.sort();
959
+ return this._array(entries, false);
960
+ },
961
+ _date(date) {
962
+ return write("date:" + date.toJSON());
963
+ },
964
+ _symbol(sym) {
965
+ return write("symbol:" + sym.toString());
966
+ },
967
+ _error(err) {
968
+ return write("error:" + err.toString());
969
+ },
970
+ _boolean(bool) {
971
+ return write("bool:" + bool.toString());
972
+ },
973
+ _string(string) {
974
+ write("string:" + string.length + ":");
975
+ write(string.toString());
976
+ },
977
+ _function(fn) {
978
+ write("fn:");
979
+ if (isNativeFunction(fn)) {
980
+ this.dispatch("[native]");
981
+ } else {
982
+ this.dispatch(fn.toString());
983
+ }
984
+ if (options.respectFunctionNames !== false) {
985
+ this.dispatch("function-name:" + String(fn.name));
986
+ }
987
+ if (options.respectFunctionProperties) {
988
+ this._object(fn);
989
+ }
990
+ },
991
+ _number(number) {
992
+ return write("number:" + number.toString());
993
+ },
994
+ _xml(xml) {
995
+ return write("xml:" + xml.toString());
996
+ },
997
+ _null() {
998
+ return write("Null");
999
+ },
1000
+ _undefined() {
1001
+ return write("Undefined");
1002
+ },
1003
+ _regexp(regex) {
1004
+ return write("regex:" + regex.toString());
1005
+ },
1006
+ _uint8array(arr) {
1007
+ write("uint8array:");
1008
+ return this.dispatch(Array.prototype.slice.call(arr));
1009
+ },
1010
+ _uint8clampedarray(arr) {
1011
+ write("uint8clampedarray:");
1012
+ return this.dispatch(Array.prototype.slice.call(arr));
1013
+ },
1014
+ _int8array(arr) {
1015
+ write("int8array:");
1016
+ return this.dispatch(Array.prototype.slice.call(arr));
1017
+ },
1018
+ _uint16array(arr) {
1019
+ write("uint16array:");
1020
+ return this.dispatch(Array.prototype.slice.call(arr));
1021
+ },
1022
+ _int16array(arr) {
1023
+ write("int16array:");
1024
+ return this.dispatch(Array.prototype.slice.call(arr));
1025
+ },
1026
+ _uint32array(arr) {
1027
+ write("uint32array:");
1028
+ return this.dispatch(Array.prototype.slice.call(arr));
1029
+ },
1030
+ _int32array(arr) {
1031
+ write("int32array:");
1032
+ return this.dispatch(Array.prototype.slice.call(arr));
1033
+ },
1034
+ _float32array(arr) {
1035
+ write("float32array:");
1036
+ return this.dispatch(Array.prototype.slice.call(arr));
1037
+ },
1038
+ _float64array(arr) {
1039
+ write("float64array:");
1040
+ return this.dispatch(Array.prototype.slice.call(arr));
1041
+ },
1042
+ _arraybuffer(arr) {
1043
+ write("arraybuffer:");
1044
+ return this.dispatch(new Uint8Array(arr));
1045
+ },
1046
+ _url(url) {
1047
+ return write("url:" + url.toString());
1048
+ },
1049
+ _map(map) {
1050
+ write("map:");
1051
+ const arr = [...map];
1052
+ return this._array(arr, options.unorderedSets !== false);
1053
+ },
1054
+ _set(set) {
1055
+ write("set:");
1056
+ const arr = [...set];
1057
+ return this._array(arr, options.unorderedSets !== false);
1058
+ },
1059
+ _file(file) {
1060
+ write("file:");
1061
+ return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
1062
+ },
1063
+ _blob() {
1064
+ if (options.ignoreUnknown) {
1065
+ return write("[blob]");
1066
+ }
1067
+ throw new Error('Hashing Blob objects is currently not supported\nUse "options.replacer" or "options.ignoreUnknown"\n');
1068
+ },
1069
+ _domwindow() {
1070
+ return write("domwindow");
1071
+ },
1072
+ _bigint(number) {
1073
+ return write("bigint:" + number.toString());
1074
+ },
1075
+ _process() {
1076
+ return write("process");
1077
+ },
1078
+ _timer() {
1079
+ return write("timer");
1080
+ },
1081
+ _pipe() {
1082
+ return write("pipe");
1083
+ },
1084
+ _tcp() {
1085
+ return write("tcp");
1086
+ },
1087
+ _udp() {
1088
+ return write("udp");
1089
+ },
1090
+ _tty() {
1091
+ return write("tty");
1092
+ },
1093
+ _statwatcher() {
1094
+ return write("statwatcher");
1095
+ },
1096
+ _securecontext() {
1097
+ return write("securecontext");
1098
+ },
1099
+ _connection() {
1100
+ return write("connection");
1101
+ },
1102
+ _zlib() {
1103
+ return write("zlib");
1104
+ },
1105
+ _context() {
1106
+ return write("context");
1107
+ },
1108
+ _nodescript() {
1109
+ return write("nodescript");
1110
+ },
1111
+ _httpparser() {
1112
+ return write("httpparser");
1113
+ },
1114
+ _dataview() {
1115
+ return write("dataview");
1116
+ },
1117
+ _signal() {
1118
+ return write("signal");
1119
+ },
1120
+ _fsevent() {
1121
+ return write("fsevent");
1122
+ },
1123
+ _tlswrap() {
1124
+ return write("tlswrap");
1125
+ }
1126
+ };
1127
+ }
1128
+ function isNativeFunction(f) {
1129
+ if (typeof f !== "function") {
1130
+ return false;
1131
+ }
1132
+ const exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code]\s+}$/i;
1133
+ return exp.exec(Function.prototype.toString.call(f)) != null;
1134
+ }
1135
+
1136
+ class WordArray {
1137
+ constructor(words, sigBytes) {
1138
+ words = this.words = words || [];
1139
+ this.sigBytes = sigBytes !== void 0 ? sigBytes : words.length * 4;
1140
+ }
1141
+ toString(encoder) {
1142
+ return (encoder || Hex).stringify(this);
1143
+ }
1144
+ concat(wordArray) {
1145
+ this.clamp();
1146
+ if (this.sigBytes % 4) {
1147
+ for (let i = 0; i < wordArray.sigBytes; i++) {
1148
+ const thatByte = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
1149
+ this.words[this.sigBytes + i >>> 2] |= thatByte << 24 - (this.sigBytes + i) % 4 * 8;
1150
+ }
1151
+ } else {
1152
+ for (let j = 0; j < wordArray.sigBytes; j += 4) {
1153
+ this.words[this.sigBytes + j >>> 2] = wordArray.words[j >>> 2];
1154
+ }
1155
+ }
1156
+ this.sigBytes += wordArray.sigBytes;
1157
+ return this;
1158
+ }
1159
+ clamp() {
1160
+ this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8;
1161
+ this.words.length = Math.ceil(this.sigBytes / 4);
1162
+ }
1163
+ clone() {
1164
+ return new WordArray([...this.words]);
1165
+ }
1166
+ }
1167
+ const Hex = {
1168
+ stringify(wordArray) {
1169
+ const hexChars = [];
1170
+ for (let i = 0; i < wordArray.sigBytes; i++) {
1171
+ const bite = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
1172
+ hexChars.push(
1173
+ (bite >>> 4).toString(16),
1174
+ (bite & 15).toString(16)
1175
+ );
1176
+ }
1177
+ return hexChars.join("");
1178
+ }
1179
+ };
1180
+ const Base64 = {
1181
+ stringify(wordArray) {
1182
+ const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
1183
+ const base64Chars = [];
1184
+ for (let i = 0; i < wordArray.sigBytes; i += 3) {
1185
+ const byte1 = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
1186
+ const byte2 = wordArray.words[i + 1 >>> 2] >>> 24 - (i + 1) % 4 * 8 & 255;
1187
+ const byte3 = wordArray.words[i + 2 >>> 2] >>> 24 - (i + 2) % 4 * 8 & 255;
1188
+ const triplet = byte1 << 16 | byte2 << 8 | byte3;
1189
+ for (let j = 0; j < 4 && i * 8 + j * 6 < wordArray.sigBytes * 8; j++) {
1190
+ base64Chars.push(keyStr.charAt(triplet >>> 6 * (3 - j) & 63));
1191
+ }
1192
+ }
1193
+ return base64Chars.join("");
1194
+ }
1195
+ };
1196
+ const Latin1 = {
1197
+ parse(latin1Str) {
1198
+ const latin1StrLength = latin1Str.length;
1199
+ const words = [];
1200
+ for (let i = 0; i < latin1StrLength; i++) {
1201
+ words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8;
1202
+ }
1203
+ return new WordArray(words, latin1StrLength);
1204
+ }
1205
+ };
1206
+ const Utf8 = {
1207
+ parse(utf8Str) {
1208
+ return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
1209
+ }
1210
+ };
1211
+ class BufferedBlockAlgorithm {
1212
+ constructor() {
1213
+ this._minBufferSize = 0;
1214
+ this.blockSize = 512 / 32;
1215
+ this.reset();
1216
+ }
1217
+ reset() {
1218
+ this._data = new WordArray();
1219
+ this._nDataBytes = 0;
1220
+ }
1221
+ _append(data) {
1222
+ if (typeof data === "string") {
1223
+ data = Utf8.parse(data);
1224
+ }
1225
+ this._data.concat(data);
1226
+ this._nDataBytes += data.sigBytes;
1227
+ }
1228
+ _doProcessBlock(_dataWords, _offset) {
1229
+ }
1230
+ _process(doFlush) {
1231
+ let processedWords;
1232
+ let nBlocksReady = this._data.sigBytes / (this.blockSize * 4);
1233
+ if (doFlush) {
1234
+ nBlocksReady = Math.ceil(nBlocksReady);
1235
+ } else {
1236
+ nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
1237
+ }
1238
+ const nWordsReady = nBlocksReady * this.blockSize;
1239
+ const nBytesReady = Math.min(nWordsReady * 4, this._data.sigBytes);
1240
+ if (nWordsReady) {
1241
+ for (let offset = 0; offset < nWordsReady; offset += this.blockSize) {
1242
+ this._doProcessBlock(this._data.words, offset);
1243
+ }
1244
+ processedWords = this._data.words.splice(0, nWordsReady);
1245
+ this._data.sigBytes -= nBytesReady;
1246
+ }
1247
+ return new WordArray(processedWords, nBytesReady);
1248
+ }
1249
+ }
1250
+ class Hasher extends BufferedBlockAlgorithm {
1251
+ update(messageUpdate) {
1252
+ this._append(messageUpdate);
1253
+ this._process();
1254
+ return this;
1255
+ }
1256
+ finalize(messageUpdate) {
1257
+ if (messageUpdate) {
1258
+ this._append(messageUpdate);
1259
+ }
1260
+ }
1261
+ }
1262
+
1263
+ const H = [1779033703, -1150833019, 1013904242, -1521486534, 1359893119, -1694144372, 528734635, 1541459225];
1264
+ const K = [1116352408, 1899447441, -1245643825, -373957723, 961987163, 1508970993, -1841331548, -1424204075, -670586216, 310598401, 607225278, 1426881987, 1925078388, -2132889090, -1680079193, -1046744716, -459576895, -272742522, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, -1740746414, -1473132947, -1341970488, -1084653625, -958395405, -710438585, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, -2117940946, -1838011259, -1564481375, -1474664885, -1035236496, -949202525, -778901479, -694614492, -200395387, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, -2067236844, -1933114872, -1866530822, -1538233109, -1090935817, -965641998];
1265
+ const W = [];
1266
+ class SHA256 extends Hasher {
1267
+ constructor() {
1268
+ super();
1269
+ this.reset();
1270
+ }
1271
+ reset() {
1272
+ super.reset();
1273
+ this._hash = new WordArray([...H]);
1274
+ }
1275
+ _doProcessBlock(M, offset) {
1276
+ const H2 = this._hash.words;
1277
+ let a = H2[0];
1278
+ let b = H2[1];
1279
+ let c = H2[2];
1280
+ let d = H2[3];
1281
+ let e = H2[4];
1282
+ let f = H2[5];
1283
+ let g = H2[6];
1284
+ let h = H2[7];
1285
+ for (let i = 0; i < 64; i++) {
1286
+ if (i < 16) {
1287
+ W[i] = M[offset + i] | 0;
1288
+ } else {
1289
+ const gamma0x = W[i - 15];
1290
+ const gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
1291
+ const gamma1x = W[i - 2];
1292
+ const gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
1293
+ W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
1294
+ }
1295
+ const ch = e & f ^ ~e & g;
1296
+ const maj = a & b ^ a & c ^ b & c;
1297
+ const sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
1298
+ const sigma1 = (e << 26 | e >>> 6) ^ (e << 21 | e >>> 11) ^ (e << 7 | e >>> 25);
1299
+ const t1 = h + sigma1 + ch + K[i] + W[i];
1300
+ const t2 = sigma0 + maj;
1301
+ h = g;
1302
+ g = f;
1303
+ f = e;
1304
+ e = d + t1 | 0;
1305
+ d = c;
1306
+ c = b;
1307
+ b = a;
1308
+ a = t1 + t2 | 0;
1309
+ }
1310
+ H2[0] = H2[0] + a | 0;
1311
+ H2[1] = H2[1] + b | 0;
1312
+ H2[2] = H2[2] + c | 0;
1313
+ H2[3] = H2[3] + d | 0;
1314
+ H2[4] = H2[4] + e | 0;
1315
+ H2[5] = H2[5] + f | 0;
1316
+ H2[6] = H2[6] + g | 0;
1317
+ H2[7] = H2[7] + h | 0;
1318
+ }
1319
+ finalize(messageUpdate) {
1320
+ super.finalize(messageUpdate);
1321
+ const nBitsTotal = this._nDataBytes * 8;
1322
+ const nBitsLeft = this._data.sigBytes * 8;
1323
+ this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
1324
+ this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(nBitsTotal / 4294967296);
1325
+ this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
1326
+ this._data.sigBytes = this._data.words.length * 4;
1327
+ this._process();
1328
+ return this._hash;
1329
+ }
1330
+ }
1331
+ function sha256base64(message) {
1332
+ return new SHA256().finalize(message).toString(Base64);
1333
+ }
1334
+
1335
+ function hash(object, options = {}) {
1336
+ const hashed = typeof object === "string" ? object : objectHash(object, options);
1337
+ return sha256base64(hashed).slice(0, 10);
1338
+ }
1339
+
794
1340
  const ProductId = "#product";
795
1341
  const productResolver = defineSchemaOrgResolver({
796
1342
  defaults: {
@@ -1051,7 +1597,10 @@ const resolveNode = (node, ctx, resolver) => {
1051
1597
  let defaults = resolver.defaults || {};
1052
1598
  if (typeof defaults === "function")
1053
1599
  defaults = defaults(ctx);
1054
- node = defu(node, defaults);
1600
+ node = {
1601
+ ...defaults,
1602
+ ...node
1603
+ };
1055
1604
  }
1056
1605
  resolver.inheritMeta?.forEach((entry) => {
1057
1606
  if (typeof entry === "string")
@@ -1092,7 +1641,7 @@ const resolveNodeId = (node, ctx, resolver, resolveAsRoot = false) => {
1092
1641
  if (!key.startsWith("_"))
1093
1642
  hashNodeData[key] = val;
1094
1643
  });
1095
- node["@id"] = prefixId(ctx.meta[prefix], `#/schema/${alias}/${hash(hashNodeData)}`);
1644
+ node["@id"] = prefixId(ctx.meta[prefix], `#/schema/${alias}/${hashCode(JSON.stringify(hashNodeData))}`);
1096
1645
  }
1097
1646
  return node;
1098
1647
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unhead/schema-org",
3
- "version": "0.0.7",
3
+ "version": "0.1.0",
4
4
  "packageManager": "pnpm@7.8.0",
5
5
  "description": "Node Schema.org for Simple and Automated Google Rich Results",
6
6
  "author": "Harlan Wilton <harlan@harlanzw.com>",
@@ -34,14 +34,10 @@
34
34
  "dist"
35
35
  ],
36
36
  "peerDependencies": {
37
- "unhead": ">=1.0.8"
38
- },
39
- "dependencies": {
40
- "defu": "^6.1.1",
41
- "ohash": "^1.0.0",
42
- "ufo": "^1.0.1"
37
+ "unhead": ">=1.0.9"
43
38
  },
44
39
  "devDependencies": {
40
+ "ufo": "^1.0.1",
45
41
  "unhead": "latest"
46
42
  },
47
43
  "scripts": {