hyperbook 0.73.5 → 0.74.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.
Files changed (2) hide show
  1. package/dist/index.js +221 -43
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -167098,8 +167098,218 @@ var remarkLink_default = (ctx) => () => {
167098
167098
  var import_handlebars = __toESM(require_lib(), 1);
167099
167099
 
167100
167100
 
167101
+
167102
+ // src/queryParser.ts
167103
+ var tokenize = (source) => {
167104
+ const tokens = [];
167105
+ let i = 0;
167106
+ while (i < source.length) {
167107
+ if (/\s/.test(source[i])) {
167108
+ i++;
167109
+ continue;
167110
+ }
167111
+ if (source[i] === "(" || source[i] === ")") {
167112
+ tokens.push(source[i]);
167113
+ i++;
167114
+ continue;
167115
+ }
167116
+ if (source.slice(i, i + 3).toUpperCase() === "AND" && !/\w/.test(source[i + 3] || "")) {
167117
+ tokens.push("AND");
167118
+ i += 3;
167119
+ continue;
167120
+ }
167121
+ if (source.slice(i, i + 2).toUpperCase() === "OR" && !/\w/.test(source[i + 2] || "")) {
167122
+ tokens.push("OR");
167123
+ i += 2;
167124
+ continue;
167125
+ }
167126
+ if (source.slice(i, i + 3).toUpperCase() === "NOT" && !/\w/.test(source[i + 3] || "")) {
167127
+ tokens.push("NOT");
167128
+ i += 3;
167129
+ continue;
167130
+ }
167131
+ const condMatch = source.slice(i).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\(([^)]*)\)/);
167132
+ if (condMatch) {
167133
+ tokens.push(condMatch[0]);
167134
+ i += condMatch[0].length;
167135
+ continue;
167136
+ }
167137
+ i++;
167138
+ }
167139
+ return tokens;
167140
+ };
167141
+ var QueryParser = class {
167142
+ constructor(tokens) {
167143
+ this.tokens = tokens;
167144
+ this.pos = 0;
167145
+ }
167146
+ parse() {
167147
+ if (this.tokens.length === 0) {
167148
+ return null;
167149
+ }
167150
+ return this.parseOr();
167151
+ }
167152
+ parseOr() {
167153
+ let left = this.parseAnd();
167154
+ while (this.peek() === "OR") {
167155
+ this.consume("OR");
167156
+ const right = this.parseAnd();
167157
+ left = { type: "OR", left, right };
167158
+ }
167159
+ return left;
167160
+ }
167161
+ parseAnd() {
167162
+ let left = this.parseNot();
167163
+ while (this.peek() === "AND") {
167164
+ this.consume("AND");
167165
+ const right = this.parseNot();
167166
+ left = { type: "AND", left, right };
167167
+ }
167168
+ return left;
167169
+ }
167170
+ parseNot() {
167171
+ if (this.peek() === "NOT") {
167172
+ this.consume("NOT");
167173
+ const operand = this.parseNot();
167174
+ return { type: "NOT", operand };
167175
+ }
167176
+ return this.parsePrimary();
167177
+ }
167178
+ parsePrimary() {
167179
+ const token = this.peek();
167180
+ if (token === "(") {
167181
+ this.consume("(");
167182
+ const node3 = this.parseOr();
167183
+ this.consume(")");
167184
+ return node3;
167185
+ }
167186
+ return this.parseCondition();
167187
+ }
167188
+ parseCondition() {
167189
+ const token = this.next();
167190
+ if (!token) {
167191
+ throw new Error("Unexpected end of query");
167192
+ }
167193
+ const match = token.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\(([^)]*)\)$/);
167194
+ if (!match) {
167195
+ throw new Error(`Invalid condition: ${token}`);
167196
+ }
167197
+ return { type: "condition", field: match[1], regex: match[2] };
167198
+ }
167199
+ peek() {
167200
+ return this.tokens[this.pos];
167201
+ }
167202
+ next() {
167203
+ return this.tokens[this.pos++];
167204
+ }
167205
+ consume(expected) {
167206
+ const token = this.next();
167207
+ if (token !== expected) {
167208
+ throw new Error(`Expected ${expected}, got ${token}`);
167209
+ }
167210
+ }
167211
+ };
167212
+ var parseQuery = (source) => {
167213
+ const tokens = tokenize(source);
167214
+ const parser = new QueryParser(tokens);
167215
+ return parser.parse();
167216
+ };
167217
+ var evaluateQuery = (query, page) => {
167218
+ if (query === null) {
167219
+ return true;
167220
+ }
167221
+ switch (query.type) {
167222
+ case "AND":
167223
+ return evaluateQuery(query.left, page) && evaluateQuery(query.right, page);
167224
+ case "OR":
167225
+ return evaluateQuery(query.left, page) || evaluateQuery(query.right, page);
167226
+ case "NOT":
167227
+ return !evaluateQuery(query.operand, page);
167228
+ case "condition":
167229
+ return evaluateCondition(query.field, query.regex, page);
167230
+ default:
167231
+ return false;
167232
+ }
167233
+ };
167234
+ var evaluateCondition = (field, regex, page) => {
167235
+ const re2 = new RegExp(regex);
167236
+ if (field === "href") {
167237
+ return page.href ? re2.test(page.href) : false;
167238
+ } else if (field === "name") {
167239
+ return re2.test(page.name);
167240
+ } else if (field === "keyword") {
167241
+ if (!page.keywords || !Array.isArray(page.keywords)) {
167242
+ return false;
167243
+ }
167244
+ return page.keywords.some((k) => re2.test(k));
167245
+ } else if (field === "description") {
167246
+ return page.description ? re2.test(page.description) : false;
167247
+ } else {
167248
+ const value = page[field];
167249
+ if (value === void 0 || value === null) {
167250
+ return false;
167251
+ }
167252
+ if (typeof value === "string") {
167253
+ return re2.test(value);
167254
+ } else if (typeof value === "number" || typeof value === "boolean") {
167255
+ return re2.test(String(value));
167256
+ } else if (value instanceof Date) {
167257
+ return re2.test(value.toISOString());
167258
+ } else if (Array.isArray(value)) {
167259
+ return value.some((v) => {
167260
+ if (typeof v === "string") {
167261
+ return re2.test(v);
167262
+ } else if (typeof v === "number" || typeof v === "boolean") {
167263
+ return re2.test(String(v));
167264
+ }
167265
+ return false;
167266
+ });
167267
+ }
167268
+ return false;
167269
+ }
167270
+ };
167271
+ var compareValues = (val1, val2) => {
167272
+ if (val1 === void 0 || val1 === null) {
167273
+ if (val2 === void 0 || val2 === null) {
167274
+ return 0;
167275
+ } else {
167276
+ return 1;
167277
+ }
167278
+ } else if (val2 === void 0 || val2 === null) {
167279
+ return -1;
167280
+ } else if (typeof val1 === "string" && typeof val2 === "string") {
167281
+ return val1.localeCompare(val2);
167282
+ } else if (typeof val1 === "number" && typeof val2 === "number") {
167283
+ return val1 - val2;
167284
+ } else if (typeof val1 === "boolean" && typeof val2 === "boolean") {
167285
+ return (val1 ? 1 : 0) - (val2 ? 1 : 0);
167286
+ } else if (val1 instanceof Date && val2 instanceof Date) {
167287
+ return val1.getTime() - val2.getTime();
167288
+ } else if (val1 instanceof Date) {
167289
+ return val1.getTime() - new Date(String(val2)).getTime();
167290
+ } else if (val2 instanceof Date) {
167291
+ return new Date(String(val1)).getTime() - val2.getTime();
167292
+ } else {
167293
+ return String(val1).localeCompare(String(val2));
167294
+ }
167295
+ };
167296
+ var createPageSorter = (orderBy) => {
167297
+ const orderByKey = orderBy?.split(":")[0] || "name";
167298
+ const orderByMode = orderBy?.split(":")[1] || "desc";
167299
+ return (p1, p22) => {
167300
+ const val1 = p1[orderByKey];
167301
+ const val2 = p22[orderByKey];
167302
+ const result = compareValues(val1, val2);
167303
+ if (orderByMode === "desc") {
167304
+ return result * -1;
167305
+ }
167306
+ return result;
167307
+ };
167308
+ };
167309
+
167310
+ // src/remarkDirectivePagelist.ts
167101
167311
  var getPageList = (sections, pages) => {
167102
- let pageList = [...pages];
167312
+ let pageList = [...pages.filter((p4) => !p4.isEmpty)];
167103
167313
  for (const section of sections) {
167104
167314
  pageList = [
167105
167315
  ...pageList,
@@ -167132,7 +167342,8 @@ var remarkDirectivePagelist_default = (ctx) => () => {
167132
167342
  const {
167133
167343
  format: format2 = "ul",
167134
167344
  orderBy = "name:asc",
167135
- source = "href(.*)"
167345
+ source = "href(.*)",
167346
+ limit = null
167136
167347
  } = attributes4;
167137
167348
  expectLeafDirective(node3, file, name);
167138
167349
  registerDirective(file, name, [], ["style.css"], []);
@@ -167140,46 +167351,13 @@ var remarkDirectivePagelist_default = (ctx) => () => {
167140
167351
  data.hProperties = {
167141
167352
  class: "directive-pagelist"
167142
167353
  };
167143
- const sources = (source?.split(" AND ") || []).map((s3) => ({
167144
- type: s3.split("(")[0],
167145
- regex: s3.split("(")[1].split(")")[0] || ""
167146
- }));
167147
- let filteredPages = pageList.filter((p4) => {
167148
- let accept = true;
167149
- for (let source2 of sources) {
167150
- if (source2.type === "href") {
167151
- accept = accept && p4.href?.match(source2.regex) !== null;
167152
- } else if (source2.type === "name") {
167153
- accept = accept && p4.name.match(source2.regex) !== null;
167154
- } else if (source2.type === "keyword") {
167155
- let foundOne = false;
167156
- for (let keyword of p4.keywords || []) {
167157
- if (keyword.match(source2.regex)) {
167158
- foundOne = true;
167159
- break;
167160
- }
167161
- }
167162
- accept = accept && foundOne;
167163
- }
167164
- }
167165
- return accept;
167166
- });
167167
- const orderByKey = orderBy?.split(":")[0] || "name";
167168
- const orderByMode = orderBy?.split(":")[1] || "desc";
167169
- filteredPages = filteredPages.sort((p1, p22) => {
167170
- let result = 0;
167171
- if (orderByKey === "name") {
167172
- result = p1.name.localeCompare(p22.name);
167173
- } else if (orderByKey === "href") {
167174
- result = (p1.href || "").localeCompare(p22.href || "");
167175
- } else if (orderByKey === "index") {
167176
- result = (p1.index || 0) - (p22.index || 0);
167177
- }
167178
- if (orderByMode === "desc") {
167179
- return result * -1;
167180
- }
167181
- return result;
167182
- });
167354
+ const query = parseQuery(source || "href(.*)");
167355
+ let filteredPages = pageList.filter((p4) => evaluateQuery(query, p4));
167356
+ const sorter = createPageSorter(orderBy || "name:asc");
167357
+ filteredPages = filteredPages.sort((p1, p22) => sorter(p1, p22));
167358
+ if (limit !== null) {
167359
+ filteredPages = filteredPages.slice(0, Number(limit));
167360
+ }
167183
167361
  filteredPages = filteredPages.map((p4) => ({
167184
167362
  ...p4,
167185
167363
  href: ctx.makeUrl(p4.href || "", "book")
@@ -173971,7 +174149,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"application/1d-interleaved-parityfec
173971
174149
  /***/ ((module) => {
173972
174150
 
173973
174151
  "use strict";
173974
- module.exports = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.73.5","author":"Mike Barkmin","homepage":"https://github.com/openpatch/hyperbook#readme","license":"MIT","bin":{"hyperbook":"./dist/index.js"},"files":["dist"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/openpatch/hyperbook.git","directory":"packages/hyperbook"},"bugs":{"url":"https://github.com/openpatch/hyperbook/issues"},"engines":{"node":">=12.22.0"},"scripts":{"version":"pnpm build","lint":"tsc --noEmit","dev":"ncc build ./index.ts -w -o dist/","build":"rimraf dist && ncc build ./index.ts -o ./dist/ --no-cache --no-source-map-register --external favicons --external sharp && node postbuild.mjs"},"dependencies":{"favicons":"^7.2.0"},"devDependencies":{"create-hyperbook":"workspace:*","@hyperbook/fs":"workspace:*","@hyperbook/markdown":"workspace:*","@hyperbook/types":"workspace:*","@pnpm/exportable-manifest":"1000.0.6","@types/archiver":"6.0.3","@types/async-retry":"1.4.9","@types/cross-spawn":"6.0.6","@types/lunr":"^2.3.7","@types/prompts":"2.4.9","@types/tar":"6.1.13","@types/ws":"^8.5.14","@vercel/ncc":"0.38.3","archiver":"7.0.1","async-retry":"1.3.3","chalk":"5.4.1","chokidar":"4.0.3","commander":"12.1.0","cpy":"11.1.0","cross-spawn":"7.0.6","domutils":"^3.2.2","extract-zip":"^2.0.1","got":"12.6.0","htmlparser2":"^10.0.0","lunr":"^2.3.9","lunr-languages":"^1.14.0","mime":"^4.0.6","prompts":"2.4.2","rimraf":"6.0.1","tar":"7.4.3","update-check":"1.5.4","ws":"^8.18.0"}}');
174152
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.74.0","author":"Mike Barkmin","homepage":"https://github.com/openpatch/hyperbook#readme","license":"MIT","bin":{"hyperbook":"./dist/index.js"},"files":["dist"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/openpatch/hyperbook.git","directory":"packages/hyperbook"},"bugs":{"url":"https://github.com/openpatch/hyperbook/issues"},"engines":{"node":">=12.22.0"},"scripts":{"version":"pnpm build","lint":"tsc --noEmit","dev":"ncc build ./index.ts -w -o dist/","build":"rimraf dist && ncc build ./index.ts -o ./dist/ --no-cache --no-source-map-register --external favicons --external sharp && node postbuild.mjs"},"dependencies":{"favicons":"^7.2.0"},"devDependencies":{"create-hyperbook":"workspace:*","@hyperbook/fs":"workspace:*","@hyperbook/markdown":"workspace:*","@hyperbook/types":"workspace:*","@pnpm/exportable-manifest":"1000.0.6","@types/archiver":"6.0.3","@types/async-retry":"1.4.9","@types/cross-spawn":"6.0.6","@types/lunr":"^2.3.7","@types/prompts":"2.4.9","@types/tar":"6.1.13","@types/ws":"^8.5.14","@vercel/ncc":"0.38.3","archiver":"7.0.1","async-retry":"1.3.3","chalk":"5.4.1","chokidar":"4.0.3","commander":"12.1.0","cpy":"11.1.0","cross-spawn":"7.0.6","domutils":"^3.2.2","extract-zip":"^2.0.1","got":"12.6.0","htmlparser2":"^10.0.0","lunr":"^2.3.9","lunr-languages":"^1.14.0","mime":"^4.0.6","prompts":"2.4.2","rimraf":"6.0.1","tar":"7.4.3","update-check":"1.5.4","ws":"^8.18.0"}}');
173975
174153
 
173976
174154
  /***/ })
173977
174155
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperbook",
3
- "version": "0.73.5",
3
+ "version": "0.74.0",
4
4
  "author": "Mike Barkmin",
5
5
  "homepage": "https://github.com/openpatch/hyperbook#readme",
6
6
  "license": "MIT",
@@ -57,9 +57,9 @@
57
57
  "update-check": "1.5.4",
58
58
  "ws": "^8.18.0",
59
59
  "create-hyperbook": "0.3.0",
60
- "@hyperbook/types": "0.18.0",
61
- "@hyperbook/markdown": "0.46.2",
62
- "@hyperbook/fs": "0.21.2"
60
+ "@hyperbook/fs": "0.21.2",
61
+ "@hyperbook/markdown": "0.47.0",
62
+ "@hyperbook/types": "0.18.0"
63
63
  },
64
64
  "scripts": {
65
65
  "version": "pnpm build",