@11ty/client 4.0.0-alpha.4 → 4.0.0-alpha.6

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.
@@ -1,4 +1,4 @@
1
- /*! Eleventy v4.0.0-alpha.4 (@11ty/client/liquid Engine Bundle) */
1
+ /*! Eleventy v4.0.0-alpha.6 (@11ty/client/liquid Engine Bundle) */
2
2
  var __create = Object.create;
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1519,7 +1519,7 @@ var GLOBAL_FS_NAME, fs2, mkdir, existsSync2, mkdirSync, readFileSync2, statSync,
1519
1519
  var init_shim_consume_fs = __esm({
1520
1520
  "../../node_modules/@11ty/package-bundler/shims/shim-consume-fs.js"() {
1521
1521
  GLOBAL_FS_NAME = "eleventyFileSystem";
1522
- fs2 = window[GLOBAL_FS_NAME] || globalThis[GLOBAL_FS_NAME];
1522
+ fs2 = typeof window !== "undefined" && window[GLOBAL_FS_NAME] || typeof globalThis !== "undefined" && globalThis[GLOBAL_FS_NAME];
1523
1523
  if (!fs2) {
1524
1524
  let noopError = function() {
1525
1525
  throw new Error("This function was not included in your Eleventy bundle. Make sure you load memfs.js before using the virtual file system.");
@@ -2278,7 +2278,7 @@ var Drop = class {
2278
2278
  static {
2279
2279
  __name(this, "Drop");
2280
2280
  }
2281
- liquidMethodMissing(key) {
2281
+ liquidMethodMissing(key, context) {
2282
2282
  return void 0;
2283
2283
  }
2284
2284
  };
@@ -2343,8 +2343,7 @@ function toValue(value) {
2343
2343
  }
2344
2344
  __name(toValue, "toValue");
2345
2345
  function toNumber(value) {
2346
- value = Number(value);
2347
- return isNaN(value) ? 0 : value;
2346
+ return +toValue(value) || 0;
2348
2347
  }
2349
2348
  __name(toNumber, "toNumber");
2350
2349
  function isNumber(value) {
@@ -2456,6 +2455,12 @@ function argumentsToValue(fn) {
2456
2455
  };
2457
2456
  }
2458
2457
  __name(argumentsToValue, "argumentsToValue");
2458
+ function argumentsToNumber(fn) {
2459
+ return function(...args) {
2460
+ return fn.call(this, ...args.map(toNumber));
2461
+ };
2462
+ }
2463
+ __name(argumentsToNumber, "argumentsToNumber");
2459
2464
  function escapeRegExp(text) {
2460
2465
  return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
2461
2466
  }
@@ -3223,12 +3228,12 @@ var Limiter = class {
3223
3228
  this.limit = limit2;
3224
3229
  }
3225
3230
  use(count) {
3226
- count = toNumber(count);
3231
+ count = +count || 0;
3227
3232
  assert(this.base + count <= this.limit, this.message);
3228
3233
  this.base += count;
3229
3234
  }
3230
3235
  check(count) {
3231
- count = toNumber(count);
3236
+ count = +count || 0;
3232
3237
  assert(count <= this.limit, this.message);
3233
3238
  }
3234
3239
  };
@@ -5339,7 +5344,7 @@ var Context = class _Context {
5339
5344
  if (isString(paths))
5340
5345
  paths = paths.split(".");
5341
5346
  for (let i = 0; i < paths.length; i++) {
5342
- scope = yield readProperty(scope, paths[i], this.ownPropertyOnly);
5347
+ scope = yield this.readProperty(scope, paths[i]);
5343
5348
  if (strictVariables && isUndefined(scope)) {
5344
5349
  throw new InternalUndefinedVariableError(paths.slice(0, i + 1).join("."));
5345
5350
  }
@@ -5375,28 +5380,27 @@ var Context = class _Context {
5375
5380
  return this.environments;
5376
5381
  return this.globals;
5377
5382
  }
5383
+ readProperty(obj, key) {
5384
+ obj = toLiquid(obj);
5385
+ key = toValue(key);
5386
+ if (isNil(obj))
5387
+ return obj;
5388
+ if (isArray(obj) && key < 0)
5389
+ return obj[obj.length + +key];
5390
+ const value = readJSProperty(obj, key, this.ownPropertyOnly);
5391
+ if (value === void 0 && obj instanceof Drop)
5392
+ return obj.liquidMethodMissing(key, this);
5393
+ if (isFunction(value))
5394
+ return value.call(obj);
5395
+ if (key === "size")
5396
+ return readSize(obj);
5397
+ else if (key === "first")
5398
+ return readFirst(obj);
5399
+ else if (key === "last")
5400
+ return readLast(obj);
5401
+ return value;
5402
+ }
5378
5403
  };
5379
- function readProperty(obj, key, ownPropertyOnly) {
5380
- obj = toLiquid(obj);
5381
- key = toValue(key);
5382
- if (isNil(obj))
5383
- return obj;
5384
- if (isArray(obj) && key < 0)
5385
- return obj[obj.length + +key];
5386
- const value = readJSProperty(obj, key, ownPropertyOnly);
5387
- if (value === void 0 && obj instanceof Drop)
5388
- return obj.liquidMethodMissing(key);
5389
- if (isFunction(value))
5390
- return value.call(obj);
5391
- if (key === "size")
5392
- return readSize(obj);
5393
- else if (key === "first")
5394
- return readFirst(obj);
5395
- else if (key === "last")
5396
- return readLast(obj);
5397
- return value;
5398
- }
5399
- __name(readProperty, "readProperty");
5400
5404
  function readJSProperty(obj, key, ownPropertyOnly) {
5401
5405
  if (ownPropertyOnly && !hasOwnProperty.call(obj, key) && !(obj instanceof Drop))
5402
5406
  return void 0;
@@ -5429,28 +5433,23 @@ var BlockMode;
5429
5433
  BlockMode2[BlockMode2["OUTPUT"] = 0] = "OUTPUT";
5430
5434
  BlockMode2[BlockMode2["STORE"] = 1] = "STORE";
5431
5435
  })(BlockMode || (BlockMode = {}));
5432
- var abs = argumentsToValue(Math.abs);
5433
- var at_least = argumentsToValue(Math.max);
5434
- var at_most = argumentsToValue(Math.min);
5435
- var ceil = argumentsToValue(Math.ceil);
5436
- var divided_by = argumentsToValue((dividend, divisor, integerArithmetic = false) => integerArithmetic ? Math.floor(dividend / divisor) : dividend / divisor);
5437
- var floor = argumentsToValue(Math.floor);
5438
- var minus = argumentsToValue((v, arg) => v - arg);
5439
- var modulo = argumentsToValue((v, arg) => v % arg);
5440
- var times = argumentsToValue((v, arg) => v * arg);
5436
+ var abs = argumentsToNumber(Math.abs);
5437
+ var at_least = argumentsToNumber(Math.max);
5438
+ var at_most = argumentsToNumber(Math.min);
5439
+ var ceil = argumentsToNumber(Math.ceil);
5440
+ var divided_by = argumentsToNumber((dividend, divisor, integerArithmetic = false) => integerArithmetic ? Math.floor(dividend / divisor) : dividend / divisor);
5441
+ var floor = argumentsToNumber(Math.floor);
5442
+ var minus = argumentsToNumber((v, arg) => v - arg);
5443
+ var plus = argumentsToNumber((lhs, rhs) => lhs + rhs);
5444
+ var modulo = argumentsToNumber((v, arg) => v % arg);
5445
+ var times = argumentsToNumber((v, arg) => v * arg);
5441
5446
  function round(v, arg = 0) {
5442
- v = toValue(v);
5443
- arg = toValue(arg);
5447
+ v = toNumber(v);
5448
+ arg = toNumber(arg);
5444
5449
  const amp = Math.pow(10, arg);
5445
5450
  return Math.round(v * amp) / amp;
5446
5451
  }
5447
5452
  __name(round, "round");
5448
- function plus(v, arg) {
5449
- v = toValue(v);
5450
- arg = toValue(arg);
5451
- return Number(v) + Number(arg);
5452
- }
5453
- __name(plus, "plus");
5454
5453
  var mathFilters = /* @__PURE__ */ Object.freeze({
5455
5454
  __proto__: null,
5456
5455
  abs,
@@ -5460,10 +5459,10 @@ var mathFilters = /* @__PURE__ */ Object.freeze({
5460
5459
  divided_by,
5461
5460
  floor,
5462
5461
  minus,
5462
+ plus,
5463
5463
  modulo,
5464
5464
  times,
5465
- round,
5466
- plus
5465
+ round
5467
5466
  });
5468
5467
  var url_decode = /* @__PURE__ */ __name((x) => decodeURIComponent(stringify(x)).replace(/\+/g, " "), "url_decode");
5469
5468
  var url_encode = /* @__PURE__ */ __name((x) => encodeURIComponent(stringify(x)).replace(/%20/g, "+"), "url_encode");
@@ -6075,7 +6074,32 @@ var stringFilters = /* @__PURE__ */ Object.freeze({
6075
6074
  number_of_words,
6076
6075
  array_to_sentence_string
6077
6076
  });
6078
- var filters = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, htmlFilters), mathFilters), urlFilters), arrayFilters), dateFilters), stringFilters), misc);
6077
+ function base64Encode(str) {
6078
+ return btoa(String.fromCharCode(...new TextEncoder().encode(str)));
6079
+ }
6080
+ __name(base64Encode, "base64Encode");
6081
+ function base64Decode(str) {
6082
+ return new TextDecoder().decode(Uint8Array.from(atob(str), (c) => c.charCodeAt(0)));
6083
+ }
6084
+ __name(base64Decode, "base64Decode");
6085
+ function base64_encode(value) {
6086
+ const str = stringify(value);
6087
+ this.context.memoryLimit.use(str.length);
6088
+ return base64Encode(str);
6089
+ }
6090
+ __name(base64_encode, "base64_encode");
6091
+ function base64_decode(value) {
6092
+ const str = stringify(value);
6093
+ this.context.memoryLimit.use(str.length);
6094
+ return base64Decode(str);
6095
+ }
6096
+ __name(base64_decode, "base64_decode");
6097
+ var base64Filters = /* @__PURE__ */ Object.freeze({
6098
+ __proto__: null,
6099
+ base64_encode,
6100
+ base64_decode
6101
+ });
6102
+ var filters = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, htmlFilters), mathFilters), urlFilters), arrayFilters), dateFilters), stringFilters), base64Filters), misc);
6079
6103
  var AssignTag = class extends Tag {
6080
6104
  static {
6081
6105
  __name(this, "AssignTag");
@@ -7512,9 +7536,10 @@ var Liquid2 = class _Liquid extends TemplateEngine {
7512
7536
  root: [this.dirs.includes, this.dirs.input],
7513
7537
  // supplemented in compile with inputPath below
7514
7538
  extname: ".liquid",
7515
- strictFilters: true
7516
- // TODO?
7539
+ strictFilters: true,
7517
7540
  // cache: true,
7541
+ jsTruthy: true
7542
+ // Breaking in v4 #3507
7518
7543
  };
7519
7544
  let options = Object.assign(defaults, this.liquidOptions || {});
7520
7545
  return options;
@@ -7704,6 +7729,7 @@ var Liquid2 = class _Liquid extends TemplateEngine {
7704
7729
  }
7705
7730
  async compile(str, inputPath) {
7706
7731
  let engine = this.liquidLib;
7732
+ let liquidOptions = this.liquidOptions;
7707
7733
  let tmplReady = engine.parse(str, inputPath);
7708
7734
  let options = {};
7709
7735
  if (!inputPath || inputPath === "liquid" || inputPath === "md") {
@@ -7712,6 +7738,14 @@ var Liquid2 = class _Liquid extends TemplateEngine {
7712
7738
  }
7713
7739
  return async function(data) {
7714
7740
  let tmpl = await tmplReady;
7741
+ options.globals = Object.assign(
7742
+ {
7743
+ page: data?.page,
7744
+ eleventy: data?.eleventy,
7745
+ collections: data?.collections
7746
+ },
7747
+ liquidOptions?.globals
7748
+ );
7715
7749
  return engine.render(tmpl, data, options);
7716
7750
  };
7717
7751
  }
@@ -1,4 +1,4 @@
1
- /*! Eleventy v4.0.0-alpha.4 (@11ty/client/md Engine Bundle) */
1
+ /*! Eleventy v4.0.0-alpha.6 (@11ty/client/md Engine Bundle) */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
4
  var __export = (target, all) => {