@mintjamsinc/ichigojs 0.1.74 → 0.1.76

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.
@@ -173,6 +173,8 @@ var StandardDirectiveName;
173
173
  StandardDirectiveName["V_TEXT"] = "v-text";
174
174
  /** Focus management directive. */
175
175
  StandardDirectiveName["V_FOCUS"] = "v-focus";
176
+ /** Template reference directive (Vue's `ref` / `$refs`). */
177
+ StandardDirectiveName["REF"] = "ref";
176
178
  })(StandardDirectiveName || (StandardDirectiveName = {}));
177
179
 
178
180
  // This file was generated. Do not modify manually!
@@ -9168,6 +9170,83 @@ class VDirectiveManager {
9168
9170
  }
9169
9171
  }
9170
9172
 
9173
+ // Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
9174
+ /**
9175
+ * The default Object.prototype.toString, used to detect plain objects that
9176
+ * have not overridden their string representation.
9177
+ */
9178
+ const objectToString = Object.prototype.toString;
9179
+ /**
9180
+ * Checks if the value is a non-null object.
9181
+ */
9182
+ function isObject(value) {
9183
+ return value !== null && typeof value === 'object';
9184
+ }
9185
+ /**
9186
+ * Checks if the value is a plain object (i.e. `[object Object]`).
9187
+ */
9188
+ function isPlainObject(value) {
9189
+ return objectToString.call(value) === '[object Object]';
9190
+ }
9191
+ /**
9192
+ * Converts a symbol to a readable string, leaving other values untouched.
9193
+ * Used when rendering Map keys and Set entries.
9194
+ */
9195
+ function stringifySymbol(value, index = '') {
9196
+ return typeof value === 'symbol' ? `Symbol(${value.description ?? index})` : value;
9197
+ }
9198
+ /**
9199
+ * JSON.stringify replacer that renders values JSON cannot represent natively
9200
+ * (Map, Set, Symbol, and non-plain objects) in a readable form.
9201
+ */
9202
+ function replacer(_key, value) {
9203
+ if (value instanceof Map) {
9204
+ return {
9205
+ [`Map(${value.size})`]: [...value.entries()].reduce((entries, [key, val], i) => {
9206
+ entries[`${stringifySymbol(key, i)} =>`] = val;
9207
+ return entries;
9208
+ }, {}),
9209
+ };
9210
+ }
9211
+ if (value instanceof Set) {
9212
+ return {
9213
+ [`Set(${value.size})`]: [...value.values()].map(v => stringifySymbol(v)),
9214
+ };
9215
+ }
9216
+ if (typeof value === 'symbol') {
9217
+ return stringifySymbol(value);
9218
+ }
9219
+ if (isObject(value) && !Array.isArray(value) && !isPlainObject(value)) {
9220
+ // Non-plain objects (Date, RegExp, DOM nodes, ...) render via their own toString
9221
+ return String(value);
9222
+ }
9223
+ return value;
9224
+ }
9225
+ /**
9226
+ * Converts a value to a string suitable for display in rendered output,
9227
+ * following Vue's `toDisplayString` semantics:
9228
+ * - strings are returned as-is
9229
+ * - null and undefined become an empty string
9230
+ * - arrays and plain objects (without a custom toString) are rendered as
9231
+ * pretty-printed JSON, with Map/Set/Symbol entries made readable
9232
+ * - everything else is converted with String()
9233
+ * @param value The value to convert.
9234
+ * @returns The display string for the value.
9235
+ */
9236
+ function toDisplayString(value) {
9237
+ if (typeof value === 'string') {
9238
+ return value;
9239
+ }
9240
+ if (value === null || value === undefined) {
9241
+ return '';
9242
+ }
9243
+ if (Array.isArray(value) ||
9244
+ (isObject(value) && (value.toString === objectToString || typeof value.toString !== 'function'))) {
9245
+ return JSON.stringify(value, replacer, 2);
9246
+ }
9247
+ return String(value);
9248
+ }
9249
+
9171
9250
  // Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
9172
9251
  /**
9173
9252
  * List of standard JavaScript global objects that should be available in expressions.
@@ -9288,8 +9367,9 @@ class VTextEvaluator {
9288
9367
  return GLOBAL_OBJECTS[name];
9289
9368
  return undefined;
9290
9369
  });
9291
- // Evaluate the expression and replace {{...}} in the text
9292
- result = result.replace(matches[i][0], String(evaluator.func(...values)));
9370
+ // Evaluate the expression and replace {{...}} in the text.
9371
+ // A function replacement keeps `$`-patterns in the value literal.
9372
+ result = result.replace(matches[i][0], () => toDisplayString(evaluator.func(...values)));
9293
9373
  });
9294
9374
  return result;
9295
9375
  };
@@ -13050,8 +13130,7 @@ class VTextDirective {
13050
13130
  },
13051
13131
  applyToDOM() {
13052
13132
  const element = vNode.node;
13053
- const textContent = evaluator.evaluate();
13054
- element.textContent = textContent ?? '';
13133
+ element.textContent = toDisplayString(evaluator.evaluate());
13055
13134
  }
13056
13135
  };
13057
13136
  return updater;
@@ -13341,6 +13420,240 @@ class VFocusDirective {
13341
13420
  }
13342
13421
  }
13343
13422
 
13423
+ // Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
13424
+ /**
13425
+ * Directive for registering template references (Vue's `ref` / `$refs`).
13426
+ *
13427
+ * Usage:
13428
+ * <input ref="search"> Static name. $refs.search === the element.
13429
+ * <my-card ref="card"></my-card> On a component: $refs.card === the host element.
13430
+ * <li v-for="i in items" ref="rows"> Inside v-for: $refs.rows === array of elements.
13431
+ * <input :ref="dynamicName"> Dynamic name from an expression (evaluated at mount).
13432
+ * <input :ref="el => collect(el)"> Function ref: called with the element on mount,
13433
+ * and with null on unmount (great for v-for / dynamic).
13434
+ *
13435
+ * Behavior notes:
13436
+ * - The reference is registered during the mount phase (before any `@mounted` hook fires) and
13437
+ * removed during the unmount phase, mirroring Vue's lifecycle for `$refs`.
13438
+ * - `$refs` is intentionally NON-reactive: registering or clearing a ref never schedules a render
13439
+ * and must not be used to drive reactive template output (this matches Vue).
13440
+ * - When the same `ref` name appears inside a `v-for` (i.e. one of the element's ancestors is a
13441
+ * `v-for` template), the entries are collected into an array, in registration order. Reused
13442
+ * v-for rows are not re-registered, so the array order is not guaranteed to match DOM order after
13443
+ * reordering — the same caveat Vue documents.
13444
+ * - Cleanup is identity-safe: a ref slot (or array entry) is only cleared when it still points at
13445
+ * THIS element, so a freshly mounted element that reused the name is never clobbered by the
13446
+ * teardown of the element it replaced.
13447
+ *
13448
+ * The directive is purely lifecycle-driven: it has no DOM updater and never templatizes the node.
13449
+ */
13450
+ class VRefDirective {
13451
+ /**
13452
+ * The virtual node to which this directive is applied.
13453
+ */
13454
+ #vNode;
13455
+ /**
13456
+ * The static ref name parsed from `ref="name"`. Undefined for the dynamic `:ref` form.
13457
+ */
13458
+ #staticName;
13459
+ /**
13460
+ * Expression evaluator for the dynamic `:ref` / `v-bind:ref` form. Undefined for static refs.
13461
+ */
13462
+ #evaluator;
13463
+ /**
13464
+ * The name under which this element was actually registered, retained so unmount removes the
13465
+ * exact same slot it created (the dynamic name is evaluated once at mount and may differ from
13466
+ * the source expression). Undefined when nothing was registered (function ref, or empty value).
13467
+ */
13468
+ #registeredName;
13469
+ /**
13470
+ * The function supplied by a function ref (`:ref="el => ..."`), retained so it can be invoked
13471
+ * with null on unmount. Undefined unless a function ref was used.
13472
+ */
13473
+ #functionRef;
13474
+ /**
13475
+ * Whether this ref is registered in array mode (collected because it lives inside a v-for).
13476
+ * Resolved lazily at mount time via {@link #isInsideForLoop}.
13477
+ */
13478
+ #asArray = false;
13479
+ /**
13480
+ * @param context The context for parsing the directive.
13481
+ */
13482
+ constructor(context) {
13483
+ this.#vNode = context.vNode;
13484
+ const attrName = context.attribute.name;
13485
+ const isDynamic = attrName !== StandardDirectiveName.REF; // ":ref" or "v-bind:ref"
13486
+ if (isDynamic) {
13487
+ // Dynamic / function ref: the value is an expression.
13488
+ const expression = context.attribute.value;
13489
+ if (expression && context.vNode.bindings) {
13490
+ this.#evaluator = ExpressionEvaluator.create(expression, context.vNode.bindings, context.vNode.vApplication.functionDependencies);
13491
+ }
13492
+ }
13493
+ else {
13494
+ // Static ref: the value is the literal name.
13495
+ const name = context.attribute.value.trim();
13496
+ this.#staticName = name.length > 0 ? name : undefined;
13497
+ }
13498
+ // Remove the directive attribute from the element so it does not linger in the DOM.
13499
+ this.#vNode.node.removeAttribute(attrName);
13500
+ }
13501
+ /**
13502
+ * @inheritdoc
13503
+ */
13504
+ get name() {
13505
+ return StandardDirectiveName.REF;
13506
+ }
13507
+ /**
13508
+ * @inheritdoc
13509
+ */
13510
+ get vNode() {
13511
+ return this.#vNode;
13512
+ }
13513
+ /**
13514
+ * @inheritdoc
13515
+ */
13516
+ get needsAnchor() {
13517
+ return false;
13518
+ }
13519
+ /**
13520
+ * @inheritdoc
13521
+ */
13522
+ get bindingsPreparer() {
13523
+ return undefined;
13524
+ }
13525
+ /**
13526
+ * @inheritdoc
13527
+ */
13528
+ get domUpdater() {
13529
+ // Refs are resolved once at mount; they are deliberately not reactive (see class docs).
13530
+ return undefined;
13531
+ }
13532
+ /**
13533
+ * @inheritdoc
13534
+ */
13535
+ get templatize() {
13536
+ return false;
13537
+ }
13538
+ /**
13539
+ * @inheritdoc
13540
+ */
13541
+ get dependentIdentifiers() {
13542
+ // This directive never drives reactive updates, so it contributes no dependencies.
13543
+ return [];
13544
+ }
13545
+ /**
13546
+ * @inheritdoc
13547
+ */
13548
+ get onMount() {
13549
+ // Register during the mount phase so the reference is available before any `@mounted`
13550
+ // hook runs (those fire a frame later via requestAnimationFrame).
13551
+ return () => this.#register();
13552
+ }
13553
+ /**
13554
+ * @inheritdoc
13555
+ */
13556
+ get onMounted() {
13557
+ return undefined;
13558
+ }
13559
+ /**
13560
+ * @inheritdoc
13561
+ */
13562
+ get onUpdate() {
13563
+ return undefined;
13564
+ }
13565
+ /**
13566
+ * @inheritdoc
13567
+ */
13568
+ get onUpdated() {
13569
+ return undefined;
13570
+ }
13571
+ /**
13572
+ * @inheritdoc
13573
+ */
13574
+ get onUnmount() {
13575
+ return undefined;
13576
+ }
13577
+ /**
13578
+ * @inheritdoc
13579
+ */
13580
+ get onUnmounted() {
13581
+ // Clear during the unmount phase. The element reference is still valid here.
13582
+ return () => this.#unregister();
13583
+ }
13584
+ /**
13585
+ * @inheritdoc
13586
+ */
13587
+ destroy() {
13588
+ // No additional cleanup beyond onUnmounted; kept for interface completeness.
13589
+ }
13590
+ /**
13591
+ * Registers this element under its resolved ref name (or invokes its function ref).
13592
+ */
13593
+ #register() {
13594
+ const element = this.#vNode.node;
13595
+ if (this.#evaluator) {
13596
+ // Dynamic / function ref.
13597
+ let value;
13598
+ try {
13599
+ value = this.#evaluator.evaluate();
13600
+ }
13601
+ catch {
13602
+ // Evaluation errors are already logged by ExpressionEvaluator; nothing to register.
13603
+ return;
13604
+ }
13605
+ if (typeof value === 'function') {
13606
+ this.#functionRef = value;
13607
+ this.#functionRef(element);
13608
+ return;
13609
+ }
13610
+ if (value === null || value === undefined || value === '') {
13611
+ return; // Nothing to register under an empty dynamic name.
13612
+ }
13613
+ this.#registeredName = String(value);
13614
+ }
13615
+ else if (this.#staticName) {
13616
+ this.#registeredName = this.#staticName;
13617
+ }
13618
+ if (!this.#registeredName) {
13619
+ return;
13620
+ }
13621
+ this.#asArray = this.#isInsideForLoop();
13622
+ this.#vNode.vApplication.registerRef(this.#registeredName, element, this.#asArray);
13623
+ }
13624
+ /**
13625
+ * Removes this element's reference (or invokes its function ref with null).
13626
+ */
13627
+ #unregister() {
13628
+ if (this.#functionRef) {
13629
+ this.#functionRef(null);
13630
+ this.#functionRef = undefined;
13631
+ return;
13632
+ }
13633
+ if (this.#registeredName) {
13634
+ this.#vNode.vApplication.unregisterRef(this.#registeredName, this.#vNode.node);
13635
+ this.#registeredName = undefined;
13636
+ }
13637
+ }
13638
+ /**
13639
+ * Determines whether this element is rendered inside a `v-for` by walking up the VNode tree.
13640
+ * A `v-for` multiplies its template into N rows, so a static ref name on (or within) a row is
13641
+ * shared by N elements and must be collected into an array — matching Vue's documented
13642
+ * "ref inside v-for yields an array" behavior. The walk inspects ancestors only: the directive
13643
+ * lives on a cloned row (or a descendant of one), and the clone's parent chain leads back to the
13644
+ * `v-for` template node, which still carries the `v-for` directive.
13645
+ */
13646
+ #isInsideForLoop() {
13647
+ for (let ancestor = this.#vNode.parentVNode; ancestor; ancestor = ancestor.parentVNode) {
13648
+ const hasFor = ancestor.directiveManager?.directives?.some(d => d.name === StandardDirectiveName.V_FOR);
13649
+ if (hasFor) {
13650
+ return true;
13651
+ }
13652
+ }
13653
+ return false;
13654
+ }
13655
+ }
13656
+
13344
13657
  // Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
13345
13658
  /**
13346
13659
  * The directive parser for standard directives.
@@ -13385,15 +13698,33 @@ class VStandardDirectiveParser {
13385
13698
  context.attribute.name === StandardDirectiveName.V_TEXT ||
13386
13699
  // v-focus, v-focus.<modifier>
13387
13700
  context.attribute.name === StandardDirectiveName.V_FOCUS ||
13388
- context.attribute.name.startsWith(StandardDirectiveName.V_FOCUS + ".")) {
13701
+ context.attribute.name.startsWith(StandardDirectiveName.V_FOCUS + ".") ||
13702
+ // ref, :ref, v-bind:ref
13703
+ this.#isRefAttribute(context.attribute.name)) {
13389
13704
  return true;
13390
13705
  }
13391
13706
  return false;
13392
13707
  }
13708
+ /**
13709
+ * Determines whether the attribute is a template reference (`ref`, `:ref`, or `v-bind:ref`).
13710
+ * The dynamic forms also match the generic v-bind shorthand, so {@link parse} dispatches them
13711
+ * to VRefDirective explicitly before the v-bind branch is reached.
13712
+ */
13713
+ #isRefAttribute(name) {
13714
+ return name === StandardDirectiveName.REF ||
13715
+ name === ":" + StandardDirectiveName.REF ||
13716
+ name === StandardDirectiveName.V_BIND + ":" + StandardDirectiveName.REF;
13717
+ }
13393
13718
  /**
13394
13719
  * @inheritdoc
13395
13720
  */
13396
13721
  parse(context) {
13722
+ // ref, :ref, v-bind:ref
13723
+ // Checked before the v-bind branch below, since ":ref" / "v-bind:ref" also match the
13724
+ // generic v-bind shorthand but must be handled as template references, not attribute binds.
13725
+ if (this.#isRefAttribute(context.attribute.name)) {
13726
+ return new VRefDirective(context);
13727
+ }
13397
13728
  if (context.attribute.name === StandardDirectiveName.V_IF) {
13398
13729
  return new VIfDirective(context);
13399
13730
  }
@@ -13830,6 +14161,17 @@ class VApplication {
13830
14161
  * The watcher manager for this application.
13831
14162
  */
13832
14163
  #watcher;
14164
+ /**
14165
+ * Template references registered by the `ref` directive, exposed to data(), methods, and
14166
+ * expressions as `$refs` (Vue's `$refs`). Each entry is either a single Element or, for a
14167
+ * `ref` used inside `v-for`, an array of Elements.
14168
+ *
14169
+ * This object is intentionally marked raw (non-reactive): mutating it when an element mounts or
14170
+ * unmounts must never schedule a render, and it must not be used to drive reactive template
14171
+ * output — matching Vue's semantics for `$refs`. It is held as a direct field (in addition to
14172
+ * being injected as the `$refs` binding) so registration is a plain property write.
14173
+ */
14174
+ #refs = {};
13833
14175
  /**
13834
14176
  * Flag to indicate if an update is already scheduled.
13835
14177
  */
@@ -13930,6 +14272,13 @@ class VApplication {
13930
14272
  get functionDependencies() {
13931
14273
  return this.#functionDependencies;
13932
14274
  }
14275
+ /**
14276
+ * Gets the template references registered via the `ref` directive (Vue's `$refs`). The same
14277
+ * object is exposed to data(), methods, and expressions as `$refs`. Non-reactive by design.
14278
+ */
14279
+ get refs() {
14280
+ return this.#refs;
14281
+ }
13933
14282
  /**
13934
14283
  * Mounts the application.
13935
14284
  * @param target The CSS selector string or HTMLElement to mount the application to.
@@ -14058,6 +14407,56 @@ class VApplication {
14058
14407
  }
14059
14408
  return identifiers;
14060
14409
  }
14410
+ /**
14411
+ * Registers a template reference under the given name. Called by the `ref` directive during the
14412
+ * mount phase. When {@param asArray} is true (the element lives inside a `v-for`), references
14413
+ * accumulate into an array in registration order; otherwise the name holds a single element.
14414
+ *
14415
+ * Mutates the raw (non-reactive) `$refs` object directly, so this never schedules a render.
14416
+ *
14417
+ * @param name The ref name.
14418
+ * @param element The element (or component host element) to register.
14419
+ * @param asArray Whether to collect into an array (refs used inside a v-for).
14420
+ */
14421
+ registerRef(name, element, asArray) {
14422
+ if (asArray) {
14423
+ const current = this.#refs[name];
14424
+ if (Array.isArray(current)) {
14425
+ if (!current.includes(element)) {
14426
+ current.push(element);
14427
+ }
14428
+ }
14429
+ else {
14430
+ this.#refs[name] = [element];
14431
+ }
14432
+ return;
14433
+ }
14434
+ this.#refs[name] = element;
14435
+ }
14436
+ /**
14437
+ * Removes a template reference registered under the given name. Called by the `ref` directive
14438
+ * during the unmount phase. The removal is identity-safe: an entry is only cleared when it still
14439
+ * points at {@param element}, so a newly mounted element that reused the name is never clobbered
14440
+ * by the teardown of the element it replaced.
14441
+ *
14442
+ * @param name The ref name.
14443
+ * @param element The element whose registration should be removed.
14444
+ */
14445
+ unregisterRef(name, element) {
14446
+ const current = this.#refs[name];
14447
+ if (Array.isArray(current)) {
14448
+ const index = current.indexOf(element);
14449
+ if (index !== -1) {
14450
+ current.splice(index, 1);
14451
+ }
14452
+ if (current.length === 0) {
14453
+ delete this.#refs[name];
14454
+ }
14455
+ }
14456
+ else if (current === element) {
14457
+ delete this.#refs[name];
14458
+ }
14459
+ }
14061
14460
  /**
14062
14461
  * Initializes bindings from data, computed properties, and methods.
14063
14462
  * @returns The initialized bindings object.
@@ -14078,6 +14477,10 @@ class VApplication {
14078
14477
  this.#bindings.set('$nextTick', (callback) => this.#nextTick(callback));
14079
14478
  this.#bindings.set('$markRaw', (obj) => ReactiveProxy.markRaw(obj));
14080
14479
  this.#bindings.set('$emit', (name, detail, options) => this.#emit(name, detail, options));
14480
+ // Inject the (non-reactive) $refs container. Marking it raw prevents VBindings from wrapping
14481
+ // it in a reactive proxy, so populating it from the ref directive never schedules a render.
14482
+ ReactiveProxy.markRaw(this.#refs);
14483
+ this.#bindings.set('$refs', this.#refs);
14081
14484
  // Add methods
14082
14485
  if (this.#options.methods) {
14083
14486
  for (const [key, method] of Object.entries(this.#options.methods)) {
@@ -14707,5 +15110,5 @@ function defineComponent(tagName, options) {
14707
15110
  customElements.define(tagName, ComponentElement);
14708
15111
  }
14709
15112
 
14710
- export { ExpressionUtils, IchigoElement, ReactiveProxy, VComponent, VComponentRegistry, VDOM, defineComponent };
15113
+ export { ExpressionUtils, IchigoElement, ReactiveProxy, VComponent, VComponentRegistry, VDOM, defineComponent, toDisplayString };
14711
15114
  //# sourceMappingURL=ichigo.esm.js.map