@hyperfixi/engine 7.5.0 → 7.6.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.
@@ -0,0 +1,30 @@
1
+ (() => {
2
+ // kit:kit
3
+ var kit = globalThis._hyperscript && globalThis._hyperscript.kit || {};
4
+ var read = (name) => kit[name];
5
+ var config = /* @__PURE__ */ read("config");
6
+
7
+ // src/ext/tailwind.ts
8
+ var byClass = (cls) => (op, elt) => {
9
+ if (op === "toggle") elt.classList.toggle(cls);
10
+ else elt.classList.toggle(cls, op === "hide");
11
+ };
12
+ var tailwind = () => {
13
+ Object.assign(config.hideShowStrategies, {
14
+ twDisplay: byClass("hidden"),
15
+ twVisibility: byClass("invisible"),
16
+ twOpacity: byClass("opacity-0")
17
+ });
18
+ };
19
+
20
+ // ext/tailwind.js
21
+ var hs = globalThis._hyperscript;
22
+ if (!hs || !hs.register)
23
+ console.warn("[hyperfixi] ext/tailwind.js needs @hyperfixi/engine (hyperfixi-hs.js), loaded before it");
24
+ else if (!hs.kit)
25
+ console.warn("[hyperfixi] ext/tailwind.js needs hyperfixi-hs.js; with the Vite plugin, list it: extensions: ['tailwind']");
26
+ else if (!hs.extensions.has("tailwind")) {
27
+ hs.extensions.add("tailwind");
28
+ hs.register(tailwind);
29
+ }
30
+ })();
@@ -0,0 +1,16 @@
1
+ // src/ext/tailwind.ts
2
+ import { config } from "@hyperfixi/engine";
3
+ var byClass = (cls) => (op, elt) => {
4
+ if (op === "toggle") elt.classList.toggle(cls);
5
+ else elt.classList.toggle(cls, op === "hide");
6
+ };
7
+ var tailwind = () => {
8
+ Object.assign(config.hideShowStrategies, {
9
+ twDisplay: byClass("hidden"),
10
+ twVisibility: byClass("invisible"),
11
+ twOpacity: byClass("opacity-0")
12
+ });
13
+ };
14
+ export {
15
+ tailwind
16
+ };
@@ -0,0 +1 @@
1
+ (()=>{var a=globalThis._hyperscript&&globalThis._hyperscript.kit||{},l=i=>a[i];var n=l("config");var e=i=>(s,o)=>{s==="toggle"?o.classList.toggle(i):o.classList.toggle(i,s==="hide")},r=()=>{Object.assign(n.hideShowStrategies,{twDisplay:e("hidden"),twVisibility:e("invisible"),twOpacity:e("opacity-0")})};var t=globalThis._hyperscript;!t||!t.register?console.warn("[hyperfixi] ext/tailwind.js needs @hyperfixi/engine (hyperfixi-hs.js), loaded before it"):t.kit?t.extensions.has("tailwind")||(t.extensions.add("tailwind"),t.register(r)):console.warn("[hyperfixi] ext/tailwind.js needs hyperfixi-hs.js; with the Vite plugin, list it: extensions: ['tailwind']");})();
package/dist/full.js CHANGED
@@ -1,5 +1,11 @@
1
1
  "use strict";
2
2
  (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __export = (target, all3) => {
5
+ for (var name in all3)
6
+ __defProp(target, name, { get: all3[name], enumerable: true });
7
+ };
8
+
3
9
  // src/util.ts
4
10
  var isP = (v) => typeof v === "object" && v !== null && "then" in v && typeof v.then === "function";
5
11
  var then1 = (v, f) => isP(v) ? v.then(f) : f(v);
@@ -1733,6 +1739,7 @@
1733
1739
  };
1734
1740
  var createGrammar = () => ({
1735
1741
  commands: /* @__PURE__ */ Object.create(null),
1742
+ fallbacks: /* @__PURE__ */ Object.create(null),
1736
1743
  features: /* @__PURE__ */ Object.create(null),
1737
1744
  leaves: [],
1738
1745
  indirects: [],
@@ -1778,6 +1785,15 @@
1778
1785
  pos() {
1779
1786
  return this.cur().start;
1780
1787
  }
1788
+ /** Where the parser is, for `reset`: a command's fallback reads again from here. */
1789
+ mark() {
1790
+ return { i: this.i, last: this.last, follows: this.follows.length };
1791
+ }
1792
+ reset(mark2) {
1793
+ this.i = mark2.i;
1794
+ this.last = mark2.last;
1795
+ this.follows.length = mark2.follows;
1796
+ }
1781
1797
  /** End offset of the last consumed token — a node's `end`. */
1782
1798
  endPos() {
1783
1799
  return this.last.end;
@@ -1912,6 +1928,28 @@
1912
1928
  }
1913
1929
 
1914
1930
  // src/statements.ts
1931
+ function withFallbacks(p, rule, keyword, start) {
1932
+ const fallbacks = p.g.fallbacks[keyword];
1933
+ if (!fallbacks) return rule(p, keyword, start);
1934
+ const mark2 = p.mark();
1935
+ try {
1936
+ return rule(p, keyword, start);
1937
+ } catch (e) {
1938
+ if (!(e instanceof ParseError)) throw e;
1939
+ let error = e;
1940
+ for (const fallback of fallbacks) {
1941
+ p.reset(mark2);
1942
+ try {
1943
+ const cmd = fallback(p, keyword, start);
1944
+ if (cmd && p.pos() >= e.token.start) return cmd;
1945
+ } catch (f) {
1946
+ if (!(f instanceof ParseError)) throw f;
1947
+ if (f.token.start > error.token.start) error = f;
1948
+ }
1949
+ }
1950
+ throw error;
1951
+ }
1952
+ }
1915
1953
  function command(p) {
1916
1954
  const start = p.pos();
1917
1955
  if (p.matchOp("(")) {
@@ -1922,7 +1960,7 @@
1922
1960
  const t = p.cur();
1923
1961
  const rule = p.g.commands[t.value];
1924
1962
  let cmd;
1925
- if (rule) cmd = p.match(t.value) && rule(p, t.value, start);
1963
+ if (rule) cmd = p.match(t.value) && withFallbacks(p, rule, t.value, start);
1926
1964
  else if (t.type === "IDENTIFIER") cmd = p.g.pseudo?.(p, start);
1927
1965
  if (!cmd || !p.match("unless")) return cmd;
1928
1966
  const inner = cmd;
@@ -1997,8 +2035,21 @@
1997
2035
 
1998
2036
  // src/engine.ts
1999
2037
  var grammar = createGrammar();
2038
+ var registered = /* @__PURE__ */ new Set();
2039
+ var unread = /* @__PURE__ */ new Set();
2000
2040
  function register(...modules) {
2001
- for (const module of modules) module(grammar);
2041
+ const added = modules.filter((module) => !registered.has(module));
2042
+ for (const module of added) {
2043
+ registered.add(module);
2044
+ module(grammar);
2045
+ }
2046
+ if (!added.length) return;
2047
+ for (const elt of [...unread]) {
2048
+ unread.delete(elt);
2049
+ if (!elt.isConnected) continue;
2050
+ dropData(elt);
2051
+ initElement(elt);
2052
+ }
2002
2053
  }
2003
2054
  var parser = (src) => new Parser(grammar, tokenize(src), src);
2004
2055
  function parseProgram(src) {
@@ -2071,6 +2122,7 @@
2071
2122
  setTimeout(() => triggerEvent(target, "load", { hyperscript: true }), 1);
2072
2123
  } catch (e) {
2073
2124
  if (e instanceof ParseError) {
2125
+ unread.add(elt);
2074
2126
  if (src !== written) e.written = written;
2075
2127
  triggerEvent(elt, "hyperscript:parse-error", { errors: [e] });
2076
2128
  const from = e.written ? `
@@ -2137,6 +2189,12 @@
2137
2189
  addAfterProcessHook: (hook) => void afterProcess.push(hook),
2138
2190
  /** Not in upstream: rewrite a script as it is read, leaving the attribute as written. */
2139
2191
  addSourceTransform: (transform) => void transforms.push(transform),
2192
+ /** Not in upstream: add grammar modules, from a script tag (`dist/ext/<name>.js`) or a page. */
2193
+ register,
2194
+ // `kit` (what a module may call) is added by the script-tag bundle (`bundles/full.ts`) only,
2195
+ // so a bundle of the user's own keeps only the parts of the engine it uses.
2196
+ /** Not in upstream: the extension files (`dist/ext/<name>.js`) this page has loaded. */
2197
+ extensions: /* @__PURE__ */ new Set(),
2140
2198
  evaluate,
2141
2199
  parse: hostParse,
2142
2200
  process: processNode,
@@ -2145,7 +2203,7 @@
2145
2203
  cleanup,
2146
2204
  /** The part of upstream's `internals` that pages and tests reach for. */
2147
2205
  internals: { runtime: { cleanup, processNode } },
2148
- version: false ? "dev" : "7.5.0"
2206
+ version: false ? "dev" : "7.6.0"
2149
2207
  });
2150
2208
  function boot() {
2151
2209
  Object.assign(globalThis, { _hyperscript: api });
@@ -2215,7 +2273,10 @@
2215
2273
  else throw new Error("toggle needs a dialog, details, select or popover element");
2216
2274
  }
2217
2275
  function toggleElement(g) {
2218
- g.toggleElement = (p, target, start) => {
2276
+ (g.fallbacks.toggle ??= []).push((p, _keyword, start) => {
2277
+ p.matchAny("the", "my");
2278
+ const target = p.withFollow(["between", "as"], () => unary(p));
2279
+ if (p.peek("between")) return;
2219
2280
  const modal = p.match("as") ? !!p.req("modal") : !!p.match("modal");
2220
2281
  const text = p.text(target);
2221
2282
  const node = {
@@ -2230,7 +2291,7 @@
2230
2291
  })
2231
2292
  };
2232
2293
  return node;
2233
- };
2294
+ });
2234
2295
  }
2235
2296
 
2236
2297
  // src/commands/animation.ts
@@ -2687,13 +2748,7 @@
2687
2748
  node.between = [attribute2, attributeRef(p) ?? p.err("Expected attributeRef")];
2688
2749
  }
2689
2750
  } else if (!(node.classRefs = classRefs(p)) && !(node.attributeRef = attributeRef(p))) {
2690
- const element = p.g.toggleElement;
2691
- if (!element) node.target = p.withFollow(["between"], () => assignable(p));
2692
- else {
2693
- const target2 = p.withFollow(["between", "as"], () => unary(p));
2694
- if (!p.peek("between")) return element(p, target2, start);
2695
- node.target = writable(p, target2);
2696
- }
2751
+ node.target = p.withFollow(["between"], () => assignable(p));
2697
2752
  }
2698
2753
  if (!node.styleProp && !node.target) node.on = p.match("on") ? expr(p) : implicitMe(p);
2699
2754
  if (p.match("between")) {
@@ -5806,7 +5861,22 @@ return { ${functions.map((name) => `${name}:${name}`).join(",")} } `
5806
5861
  toggleElement
5807
5862
  ];
5808
5863
 
5864
+ // src/kit.ts
5865
+ var kit_exports = {};
5866
+ __export(kit_exports, {
5867
+ assignToNamespace: () => assignToNamespace,
5868
+ commandList: () => commandList,
5869
+ config: () => config,
5870
+ dotOrColonPath: () => dotOrColonPath,
5871
+ evalStatic: () => evalStatic,
5872
+ expr: () => expr,
5873
+ makeContext: () => makeContext,
5874
+ runList: () => runList,
5875
+ urlOrExpression: () => urlOrExpression
5876
+ });
5877
+
5809
5878
  // src/bundles/full.ts
5810
5879
  register(...everything);
5880
+ Object.assign(api, { kit: kit_exports });
5811
5881
  boot();
5812
5882
  })();