@daz4126/helium 1.0.0-beta.2 → 1.0.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/helium.js CHANGED
@@ -46,11 +46,9 @@ const defaultEngine = {
46
46
  }
47
47
  };
48
48
 
49
- // Factory function to create helium with custom engine and prefixes
49
+ // Factory function to create helium with custom engine
50
50
  export function createHelium(options = {}) {
51
51
  const engine = options.engine ?? defaultEngine;
52
- const prefix = options.prefix ?? 'he'; // 'he' or 'xe'
53
- const rootAttr = options.rootAttr ?? 'helium'; // 'helium' or 'xenon'
54
52
 
55
53
  // Engine-aware expression parser (CSP-safe when using jexpr engine)
56
54
  const evalExpr = v => {
@@ -61,13 +59,10 @@ export function createHelium(options = {}) {
61
59
  } catch { return v; }
62
60
  };
63
61
 
64
- // Build prefix-aware regex and matcher
65
- const ATTR_REGEX = new RegExp(`^(@|:|data-${prefix})`);
66
-
67
62
  const match = (name, ...attrs) => {
68
63
  const p = name.split(/[.:]/)[0];
69
64
  if (p === ":" || p === "") return false;
70
- return attrs.some(a => p === `@${a}` || p === `data-${prefix}-${a}`);
65
+ return attrs.some(a => p === `@${a}` || p === 'data-he-' + a);
71
66
  };
72
67
 
73
68
  // Single global object to hold all settings (scoped to this instance)
@@ -76,8 +71,8 @@ export function createHelium(options = {}) {
76
71
  async function helium(initialState = {}) {
77
72
  const inits = [];
78
73
  const ALL = Symbol("all");
79
- const root = document.querySelector(`[\\@${rootAttr}]`) || document.querySelector(`[data-${rootAttr}]`) || document.body;
80
- const storageKey = root.getAttribute('@local-storage') || root.getAttribute(`data-${prefix}-local-storage`);
74
+ const root = document.querySelector('[\\@helium]') || document.querySelector('[data-helium]') || document.body;
75
+ const storageKey = root.getAttribute('@local-storage') || root.getAttribute('data-he-local-storage');
81
76
 
82
77
  // Initialize or reuse HELIUM object
83
78
  if (!HELIUM) {
@@ -387,7 +382,8 @@ export function createHelium(options = {}) {
387
382
  const heElements = [element, ...element.querySelectorAll("*")].filter(e => {
388
383
  if (HELIUM.processed.has(e)) return false;
389
384
  for (let i = 0; i < e.attributes.length; i++) {
390
- if (ATTR_REGEX.test(e.attributes[i].name)) return true;
385
+ const n = e.attributes[i].name;
386
+ if (n[0] === '@' || n[0] === ':' || n.startsWith('data-he')) return true;
391
387
  }
392
388
  return false;
393
389
  });
@@ -400,7 +396,7 @@ export function createHelium(options = {}) {
400
396
  const importPromises = [];
401
397
 
402
398
  heElements.forEach((el) => {
403
- const importAttr = el.getAttribute("@import") || el.getAttribute(`data-${prefix}-import`);
399
+ const importAttr = el.getAttribute("@import") || el.getAttribute('data-he-import');
404
400
  if (importAttr) {
405
401
  importAttr.split(",").map((m) => m.trim()).forEach((moduleName) => {
406
402
  // Build path: use as-is for URLs, otherwise resolve relative to document location
@@ -448,7 +444,7 @@ export function createHelium(options = {}) {
448
444
  const {name, value} = attrs[i];
449
445
 
450
446
  // Skip non-helium attributes early
451
- if (!name.startsWith('@') && !name.startsWith(':') && !name.startsWith(`data-${prefix}`)) continue;
447
+ if (name[0] !== '@' && name[0] !== ':' && !name.startsWith('data-he')) continue;
452
448
 
453
449
  // Initialize state first if needed (skip reserved words, only if not already set)
454
450
  if (match(name, "text", "html", "bind") && isValidIdentifier(value) && !RESERVED.has(value) && state[value] == null) {
@@ -456,11 +452,11 @@ export function createHelium(options = {}) {
456
452
  }
457
453
 
458
454
  // Process the attribute
459
- if (name === "@data" || name === `data-${prefix}`) {
455
+ if (name === "@data" || name === 'data-he') {
460
456
  Object.assign(state, evalExpr(value));
461
457
  }
462
- else if (name.startsWith(":") || name.startsWith(`data-${prefix}-attr:`)) {
463
- const propName = name.startsWith(":") ? name.slice(1) : name.slice(prefix.length + 11);
458
+ else if (name.startsWith(":") || name.startsWith('data-he-attr:')) {
459
+ const propName = name.startsWith(":") ? name.slice(1) : name.slice(13);
464
460
  deferredBindings.push({el, prop: propName, compiled: compile(value, true)});
465
461
  }
466
462
  else if (match(name, "ref")) {
@@ -496,8 +492,8 @@ export function createHelium(options = {}) {
496
492
  else if (match(name, "init")) {
497
493
  inits.push({ compiled: compile(value, true), el });
498
494
  }
499
- else if (name.startsWith("@") || name.startsWith(`data-${prefix}`)) {
500
- const fullName = name.startsWith("@") ? name.slice(1) : name.slice(prefix.length + 6);
495
+ else if (name.startsWith("@") || name.startsWith('data-he')) {
496
+ const fullName = name.startsWith("@") ? name.slice(1) : name.slice(8);
501
497
  const [eventName, ...mods] = fullName.split(".");
502
498
  const isHttpMethod = ["get", "post", "put", "patch", "delete"].includes(eventName);
503
499
  const event = isHttpMethod ? getEvent(el) : eventName;
@@ -517,7 +513,7 @@ export function createHelium(options = {}) {
517
513
  }
518
514
  if (!mods.includes("outside") || !el.contains(e.target)) {
519
515
  if (isHttpMethod) {
520
- const getAttr = name => el.getAttribute(`data-${prefix}-${name}`) || el.getAttribute(`@${name}`);
516
+ const getAttr = a => el.getAttribute('data-he-' + a) || el.getAttribute('@' + a);
521
517
  const pairs = (getAttr('target') || "").split(",").map(p => p.split(":").map(s => s.trim()));
522
518
  const target = pairs.map(([target]) => target);
523
519
  const action = pairs.map(([, action]) => action);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daz4126/helium",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.3",
4
4
  "main": "helium.js",
5
5
  "type": "module",
6
6
  "exports": {