@mintjamsinc/ichigojs 0.1.9 → 0.1.10
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/README.md +52 -1
- package/dist/ichigo.esm.js +224 -2
- package/dist/ichigo.esm.js.map +1 -1
- package/dist/ichigo.esm.min.js +1 -1
- package/dist/ichigo.esm.min.js.map +1 -1
- package/dist/ichigo.umd.js +224 -2
- package/dist/ichigo.umd.js.map +1 -1
- package/dist/ichigo.umd.min.js +1 -1
- package/dist/ichigo.umd.min.js.map +1 -1
- package/dist/types/ichigo/directives/StandardDirectiveName.d.ts +4 -2
- package/dist/types/ichigo/directives/VPerformanceDirective.d.ts +18 -28
- package/package.json +1 -1
package/dist/ichigo.umd.js
CHANGED
@@ -74,10 +74,12 @@
|
|
74
74
|
StandardDirectiveName["V_BIND"] = "v-bind";
|
75
75
|
/** Two-way data binding directives. */
|
76
76
|
StandardDirectiveName["V_MODEL"] = "v-model";
|
77
|
-
/**
|
77
|
+
/** Resize observer directives. */
|
78
78
|
StandardDirectiveName["V_RESIZE"] = "v-resize";
|
79
79
|
/** Intersection observer directives. */
|
80
80
|
StandardDirectiveName["V_INTERSECTION"] = "v-intersection";
|
81
|
+
/** Performance observer directives. */
|
82
|
+
StandardDirectiveName["V_PERFORMANCE"] = "v-performance";
|
81
83
|
})(StandardDirectiveName || (StandardDirectiveName = {}));
|
82
84
|
|
83
85
|
// This file was generated. Do not modify manually!
|
@@ -9927,6 +9929,220 @@
|
|
9927
9929
|
}
|
9928
9930
|
}
|
9929
9931
|
|
9932
|
+
// Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
|
9933
|
+
/**
|
9934
|
+
* Directive for observing performance metrics using PerformanceObserver.
|
9935
|
+
* The `v-performance` directive allows you to monitor various performance entries.
|
9936
|
+
*
|
9937
|
+
* Example usage:
|
9938
|
+
* <div v-performance="handlePerformance">Performance monitoring</div>
|
9939
|
+
* <div v-performance="handlePerformance" :options.performance="{entryTypes: ['measure']}">Performance monitoring</div>
|
9940
|
+
*
|
9941
|
+
* By default (without options), it observes 'mark' and 'measure' entry types.
|
9942
|
+
*
|
9943
|
+
* The handler receives PerformanceObserverEntryList, PerformanceObserver, options (with droppedEntriesCount), and $ctx as arguments:
|
9944
|
+
* handlePerformance(entries, observer, options, $ctx) {
|
9945
|
+
* entries.getEntries().forEach(entry => {
|
9946
|
+
* console.log(`${entry.name}: ${entry.duration}ms`);
|
9947
|
+
* });
|
9948
|
+
* if (options?.droppedEntriesCount) {
|
9949
|
+
* console.log(`Dropped entries: ${options.droppedEntriesCount}`);
|
9950
|
+
* }
|
9951
|
+
* }
|
9952
|
+
*
|
9953
|
+
* Options can be provided via :options or :options.performance attribute:
|
9954
|
+
* :options="{entryTypes: ['measure', 'mark']}"
|
9955
|
+
* :options.performance="{type: 'navigation', buffered: true}"
|
9956
|
+
*
|
9957
|
+
* This directive is useful for performance monitoring, profiling, and identifying
|
9958
|
+
* performance bottlenecks in your application.
|
9959
|
+
*/
|
9960
|
+
class VPerformanceDirective {
|
9961
|
+
/**
|
9962
|
+
* The virtual node to which this directive is applied.
|
9963
|
+
*/
|
9964
|
+
#vNode;
|
9965
|
+
/**
|
9966
|
+
* A list of variable and function names used in the directive's expression.
|
9967
|
+
*/
|
9968
|
+
#dependentIdentifiers;
|
9969
|
+
/**
|
9970
|
+
* The performance handler wrapper function.
|
9971
|
+
*/
|
9972
|
+
#handlerWrapper;
|
9973
|
+
/**
|
9974
|
+
* The PerformanceObserver instance.
|
9975
|
+
*/
|
9976
|
+
#performanceObserver;
|
9977
|
+
/**
|
9978
|
+
* @param context The context for parsing the directive.
|
9979
|
+
*/
|
9980
|
+
constructor(context) {
|
9981
|
+
this.#vNode = context.vNode;
|
9982
|
+
// Parse the expression to extract identifiers and create the handler wrapper
|
9983
|
+
const expression = context.attribute.value;
|
9984
|
+
if (expression) {
|
9985
|
+
this.#dependentIdentifiers = ExpressionUtils.extractIdentifiers(expression, context.vNode.vApplication.functionDependencies);
|
9986
|
+
this.#handlerWrapper = this.#createPerformanceHandlerWrapper(expression);
|
9987
|
+
}
|
9988
|
+
// Remove the directive attribute from the element
|
9989
|
+
this.#vNode.node.removeAttribute(context.attribute.name);
|
9990
|
+
}
|
9991
|
+
/**
|
9992
|
+
* @inheritdoc
|
9993
|
+
*/
|
9994
|
+
get name() {
|
9995
|
+
return StandardDirectiveName.V_PERFORMANCE;
|
9996
|
+
}
|
9997
|
+
/**
|
9998
|
+
* @inheritdoc
|
9999
|
+
*/
|
10000
|
+
get vNode() {
|
10001
|
+
return this.#vNode;
|
10002
|
+
}
|
10003
|
+
/**
|
10004
|
+
* @inheritdoc
|
10005
|
+
*/
|
10006
|
+
get needsAnchor() {
|
10007
|
+
return false;
|
10008
|
+
}
|
10009
|
+
/**
|
10010
|
+
* @inheritdoc
|
10011
|
+
*/
|
10012
|
+
get bindingsPreparer() {
|
10013
|
+
return undefined;
|
10014
|
+
}
|
10015
|
+
/**
|
10016
|
+
* @inheritdoc
|
10017
|
+
*/
|
10018
|
+
get domUpdater() {
|
10019
|
+
return undefined;
|
10020
|
+
}
|
10021
|
+
/**
|
10022
|
+
* @inheritdoc
|
10023
|
+
*/
|
10024
|
+
get templatize() {
|
10025
|
+
return false;
|
10026
|
+
}
|
10027
|
+
/**
|
10028
|
+
* @inheritdoc
|
10029
|
+
*/
|
10030
|
+
get dependentIdentifiers() {
|
10031
|
+
return this.#dependentIdentifiers ?? [];
|
10032
|
+
}
|
10033
|
+
/**
|
10034
|
+
* @inheritdoc
|
10035
|
+
*/
|
10036
|
+
get onMount() {
|
10037
|
+
return undefined;
|
10038
|
+
}
|
10039
|
+
/**
|
10040
|
+
* @inheritdoc
|
10041
|
+
*/
|
10042
|
+
get onMounted() {
|
10043
|
+
if (!this.#handlerWrapper) {
|
10044
|
+
return undefined;
|
10045
|
+
}
|
10046
|
+
const handler = this.#handlerWrapper;
|
10047
|
+
return () => {
|
10048
|
+
// Get options from :options.performance or :options directive
|
10049
|
+
let optionsDirective = this.#vNode.directiveManager?.optionsDirective('performance');
|
10050
|
+
// Evaluate the options expression
|
10051
|
+
let options;
|
10052
|
+
if (optionsDirective && optionsDirective.expression) {
|
10053
|
+
// Evaluate the options expression
|
10054
|
+
const identifiers = optionsDirective.dependentIdentifiers;
|
10055
|
+
const values = identifiers.map(id => this.#vNode.bindings?.get(id));
|
10056
|
+
const args = identifiers.join(", ");
|
10057
|
+
const funcBody = `return (${optionsDirective.expression});`;
|
10058
|
+
const func = new Function(args, funcBody);
|
10059
|
+
options = func(...values);
|
10060
|
+
}
|
10061
|
+
// Create PerformanceObserver and start observing
|
10062
|
+
// Note: The callback receives a third argument 'options' with droppedEntriesCount in modern browsers
|
10063
|
+
// TypeScript's type definition only includes 2 arguments, so we use type assertion
|
10064
|
+
this.#performanceObserver = new PerformanceObserver(((...args) => {
|
10065
|
+
const [entries, observer, callbackOptions] = args;
|
10066
|
+
handler(entries, observer, callbackOptions);
|
10067
|
+
}));
|
10068
|
+
// If no options provided, use default: observe marks and measures
|
10069
|
+
if (!options) {
|
10070
|
+
options = { entryTypes: ['mark', 'measure'] };
|
10071
|
+
}
|
10072
|
+
// Start observing with options
|
10073
|
+
this.#performanceObserver.observe(options);
|
10074
|
+
};
|
10075
|
+
}
|
10076
|
+
/**
|
10077
|
+
* @inheritdoc
|
10078
|
+
*/
|
10079
|
+
get onUpdate() {
|
10080
|
+
return undefined;
|
10081
|
+
}
|
10082
|
+
/**
|
10083
|
+
* @inheritdoc
|
10084
|
+
*/
|
10085
|
+
get onUpdated() {
|
10086
|
+
return undefined;
|
10087
|
+
}
|
10088
|
+
/**
|
10089
|
+
* @inheritdoc
|
10090
|
+
*/
|
10091
|
+
get onUnmount() {
|
10092
|
+
return undefined;
|
10093
|
+
}
|
10094
|
+
/**
|
10095
|
+
* @inheritdoc
|
10096
|
+
*/
|
10097
|
+
get onUnmounted() {
|
10098
|
+
return undefined;
|
10099
|
+
}
|
10100
|
+
/**
|
10101
|
+
* @inheritdoc
|
10102
|
+
*/
|
10103
|
+
destroy() {
|
10104
|
+
// Disconnect the PerformanceObserver when the directive is destroyed
|
10105
|
+
if (this.#performanceObserver) {
|
10106
|
+
this.#performanceObserver.disconnect();
|
10107
|
+
this.#performanceObserver = undefined;
|
10108
|
+
}
|
10109
|
+
}
|
10110
|
+
/**
|
10111
|
+
* Creates a wrapper function for performance handlers.
|
10112
|
+
* @param expression The expression string to evaluate.
|
10113
|
+
* @returns A function that handles the performance event.
|
10114
|
+
*/
|
10115
|
+
#createPerformanceHandlerWrapper(expression) {
|
10116
|
+
const identifiers = this.#dependentIdentifiers ?? [];
|
10117
|
+
const vNode = this.#vNode;
|
10118
|
+
// Return a function that handles the performance event with proper scope
|
10119
|
+
return (entries, observer, options) => {
|
10120
|
+
const bindings = vNode.bindings;
|
10121
|
+
const $ctx = {
|
10122
|
+
element: vNode.node,
|
10123
|
+
vnode: vNode,
|
10124
|
+
userData: vNode.userData
|
10125
|
+
};
|
10126
|
+
// If the expression is just a method name, call it with bindings as 'this'
|
10127
|
+
const trimmedExpr = expression.trim();
|
10128
|
+
if (identifiers.includes(trimmedExpr) && typeof bindings?.get(trimmedExpr) === 'function') {
|
10129
|
+
const methodName = trimmedExpr;
|
10130
|
+
const originalMethod = bindings?.get(methodName);
|
10131
|
+
// Call the method with bindings as 'this' context
|
10132
|
+
// Pass entries, observer, options, and $ctx as arguments
|
10133
|
+
return originalMethod(entries, observer, options, $ctx);
|
10134
|
+
}
|
10135
|
+
// For inline expressions, evaluate normally
|
10136
|
+
// Note: inline expressions receive entries, observer, options, and $ctx as parameters
|
10137
|
+
const values = identifiers.map(id => vNode.bindings?.get(id));
|
10138
|
+
const args = [...identifiers, 'entries', 'observer', 'options', '$ctx'].join(", ");
|
10139
|
+
const funcBody = `return (${expression});`;
|
10140
|
+
const func = new Function(args, funcBody);
|
10141
|
+
return func.call(bindings?.raw, ...values, entries, observer, options, $ctx);
|
10142
|
+
};
|
10143
|
+
}
|
10144
|
+
}
|
10145
|
+
|
9930
10146
|
// Copyright (c) 2025 MintJams Inc. Licensed under MIT License.
|
9931
10147
|
/**
|
9932
10148
|
* Directive for observing element resize events using ResizeObserver.
|
@@ -10357,7 +10573,9 @@
|
|
10357
10573
|
// v-resize
|
10358
10574
|
context.attribute.name === StandardDirectiveName.V_RESIZE ||
|
10359
10575
|
// v-intersection
|
10360
|
-
context.attribute.name === StandardDirectiveName.V_INTERSECTION
|
10576
|
+
context.attribute.name === StandardDirectiveName.V_INTERSECTION ||
|
10577
|
+
// v-performance
|
10578
|
+
context.attribute.name === StandardDirectiveName.V_PERFORMANCE) {
|
10361
10579
|
return true;
|
10362
10580
|
}
|
10363
10581
|
return false;
|
@@ -10404,6 +10622,10 @@
|
|
10404
10622
|
if (context.attribute.name === StandardDirectiveName.V_INTERSECTION) {
|
10405
10623
|
return new VIntersectionDirective(context);
|
10406
10624
|
}
|
10625
|
+
// v-performance
|
10626
|
+
if (context.attribute.name === StandardDirectiveName.V_PERFORMANCE) {
|
10627
|
+
return new VPerformanceDirective(context);
|
10628
|
+
}
|
10407
10629
|
throw new Error(`The attribute "${context.attribute.name}" cannot be parsed by ${this.name}.`);
|
10408
10630
|
}
|
10409
10631
|
}
|