@sc4rfurryx/proteusjs 1.0.0 → 1.1.1
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/LICENSE +1 -1
- package/README.md +331 -77
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapters/react.d.ts +140 -0
- package/dist/adapters/react.esm.js +849 -0
- package/dist/adapters/react.esm.js.map +1 -0
- package/dist/adapters/svelte.d.ts +181 -0
- package/dist/adapters/svelte.esm.js +909 -0
- package/dist/adapters/svelte.esm.js.map +1 -0
- package/dist/adapters/vue.d.ts +205 -0
- package/dist/adapters/vue.esm.js +873 -0
- package/dist/adapters/vue.esm.js.map +1 -0
- package/dist/modules/a11y-audit.d.ts +31 -0
- package/dist/modules/a11y-audit.esm.js +64 -0
- package/dist/modules/a11y-audit.esm.js.map +1 -0
- package/dist/modules/a11y-primitives.d.ts +36 -0
- package/dist/modules/a11y-primitives.esm.js +114 -0
- package/dist/modules/a11y-primitives.esm.js.map +1 -0
- package/dist/modules/anchor.d.ts +30 -0
- package/dist/modules/anchor.esm.js +219 -0
- package/dist/modules/anchor.esm.js.map +1 -0
- package/dist/modules/container.d.ts +60 -0
- package/dist/modules/container.esm.js +194 -0
- package/dist/modules/container.esm.js.map +1 -0
- package/dist/modules/perf.d.ts +82 -0
- package/dist/modules/perf.esm.js +257 -0
- package/dist/modules/perf.esm.js.map +1 -0
- package/dist/modules/popover.d.ts +33 -0
- package/dist/modules/popover.esm.js +191 -0
- package/dist/modules/popover.esm.js.map +1 -0
- package/dist/modules/scroll.d.ts +43 -0
- package/dist/modules/scroll.esm.js +195 -0
- package/dist/modules/scroll.esm.js.map +1 -0
- package/dist/modules/transitions.d.ts +35 -0
- package/dist/modules/transitions.esm.js +120 -0
- package/dist/modules/transitions.esm.js.map +1 -0
- package/dist/modules/typography.d.ts +72 -0
- package/dist/modules/typography.esm.js +168 -0
- package/dist/modules/typography.esm.js.map +1 -0
- package/dist/proteus.cjs.js +1554 -12
- package/dist/proteus.cjs.js.map +1 -1
- package/dist/proteus.d.ts +516 -12
- package/dist/proteus.esm.js +1545 -12
- package/dist/proteus.esm.js.map +1 -1
- package/dist/proteus.esm.min.js +3 -3
- package/dist/proteus.esm.min.js.map +1 -1
- package/dist/proteus.js +1554 -12
- package/dist/proteus.js.map +1 -1
- package/dist/proteus.min.js +3 -3
- package/dist/proteus.min.js.map +1 -1
- package/package.json +69 -7
- package/src/adapters/react.ts +264 -0
- package/src/adapters/svelte.ts +321 -0
- package/src/adapters/vue.ts +268 -0
- package/src/index.ts +33 -6
- package/src/modules/a11y-audit/index.ts +84 -0
- package/src/modules/a11y-primitives/index.ts +152 -0
- package/src/modules/anchor/index.ts +259 -0
- package/src/modules/container/index.ts +230 -0
- package/src/modules/perf/index.ts +291 -0
- package/src/modules/popover/index.ts +238 -0
- package/src/modules/scroll/index.ts +251 -0
- package/src/modules/transitions/index.ts +145 -0
- package/src/modules/typography/index.ts +239 -0
- package/src/utils/version.ts +1 -1
@@ -0,0 +1,194 @@
|
|
1
|
+
/*!
|
2
|
+
* ProteusJS v1.1.1
|
3
|
+
* Shape-shifting responsive design that adapts like the sea god himself
|
4
|
+
* (c) 2025 sc4rfurry
|
5
|
+
* Released under the MIT License
|
6
|
+
*/
|
7
|
+
/**
|
8
|
+
* @sc4rfurryx/proteusjs/container
|
9
|
+
* Container/Style Query helpers with visualization devtools
|
10
|
+
*
|
11
|
+
* @version 1.1.0
|
12
|
+
* @author sc4rfurry
|
13
|
+
* @license MIT
|
14
|
+
*/
|
15
|
+
/**
|
16
|
+
* Sugar on native container queries with dev visualization
|
17
|
+
*/
|
18
|
+
function defineContainer(target, name, opts = {}) {
|
19
|
+
const targetEl = typeof target === 'string' ? document.querySelector(target) : target;
|
20
|
+
if (!targetEl) {
|
21
|
+
throw new Error('Target element not found');
|
22
|
+
}
|
23
|
+
const { type = 'size', inlineSize: _inlineSize = true } = opts;
|
24
|
+
const containerName = name || `container-${Math.random().toString(36).substring(2, 11)}`;
|
25
|
+
// Apply container properties
|
26
|
+
const element = targetEl;
|
27
|
+
element.style.containerName = containerName;
|
28
|
+
element.style.containerType = type;
|
29
|
+
// Warn if containment settings are missing
|
30
|
+
const computedStyle = getComputedStyle(element);
|
31
|
+
if (!computedStyle.contain || computedStyle.contain === 'none') {
|
32
|
+
console.warn(`Container "${containerName}" may need explicit containment settings for optimal performance`);
|
33
|
+
}
|
34
|
+
// Dev overlay (only in development)
|
35
|
+
if (process.env['NODE_ENV'] === 'development' || window.__PROTEUS_DEV__) {
|
36
|
+
createDevOverlay(element, containerName);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
/**
|
40
|
+
* Create development overlay showing container bounds and breakpoints
|
41
|
+
*/
|
42
|
+
function createDevOverlay(element, name) {
|
43
|
+
const overlay = document.createElement('div');
|
44
|
+
overlay.className = 'proteus-container-overlay';
|
45
|
+
overlay.style.cssText = `
|
46
|
+
position: absolute;
|
47
|
+
top: 0;
|
48
|
+
left: 0;
|
49
|
+
right: 0;
|
50
|
+
bottom: 0;
|
51
|
+
pointer-events: none;
|
52
|
+
border: 2px dashed rgba(255, 0, 255, 0.5);
|
53
|
+
background: rgba(255, 0, 255, 0.05);
|
54
|
+
z-index: 9999;
|
55
|
+
font-family: monospace;
|
56
|
+
font-size: 12px;
|
57
|
+
color: #ff00ff;
|
58
|
+
`;
|
59
|
+
const label = document.createElement('div');
|
60
|
+
label.style.cssText = `
|
61
|
+
position: absolute;
|
62
|
+
top: -20px;
|
63
|
+
left: 0;
|
64
|
+
background: rgba(255, 0, 255, 0.9);
|
65
|
+
color: white;
|
66
|
+
padding: 2px 6px;
|
67
|
+
border-radius: 3px;
|
68
|
+
font-size: 10px;
|
69
|
+
white-space: nowrap;
|
70
|
+
`;
|
71
|
+
label.textContent = `Container: ${name}`;
|
72
|
+
const sizeInfo = document.createElement('div');
|
73
|
+
sizeInfo.style.cssText = `
|
74
|
+
position: absolute;
|
75
|
+
bottom: 2px;
|
76
|
+
right: 2px;
|
77
|
+
background: rgba(0, 0, 0, 0.7);
|
78
|
+
color: white;
|
79
|
+
padding: 2px 4px;
|
80
|
+
border-radius: 2px;
|
81
|
+
font-size: 10px;
|
82
|
+
`;
|
83
|
+
overlay.appendChild(label);
|
84
|
+
overlay.appendChild(sizeInfo);
|
85
|
+
// Position overlay relative to container
|
86
|
+
if (getComputedStyle(element).position === 'static') {
|
87
|
+
element.style.position = 'relative';
|
88
|
+
}
|
89
|
+
element.appendChild(overlay);
|
90
|
+
// Update size info
|
91
|
+
const updateSizeInfo = () => {
|
92
|
+
const rect = element.getBoundingClientRect();
|
93
|
+
sizeInfo.textContent = `${Math.round(rect.width)}×${Math.round(rect.height)}`;
|
94
|
+
};
|
95
|
+
updateSizeInfo();
|
96
|
+
// Update on resize
|
97
|
+
if ('ResizeObserver' in window) {
|
98
|
+
const resizeObserver = new ResizeObserver(updateSizeInfo);
|
99
|
+
resizeObserver.observe(element);
|
100
|
+
}
|
101
|
+
// Store cleanup function
|
102
|
+
element._proteusContainerCleanup = () => {
|
103
|
+
overlay.remove();
|
104
|
+
};
|
105
|
+
}
|
106
|
+
/**
|
107
|
+
* Helper to create container query CSS rules
|
108
|
+
*/
|
109
|
+
function createContainerQuery(containerName, condition, styles) {
|
110
|
+
const cssRules = Object.entries(styles)
|
111
|
+
.map(([property, value]) => ` ${property}: ${value};`)
|
112
|
+
.join('\n');
|
113
|
+
return `@container ${containerName} (${condition}) {\n${cssRules}\n}`;
|
114
|
+
}
|
115
|
+
/**
|
116
|
+
* Apply container query styles dynamically
|
117
|
+
*/
|
118
|
+
function applyContainerQuery(containerName, condition, styles) {
|
119
|
+
const css = createContainerQuery(containerName, condition, styles);
|
120
|
+
const styleElement = document.createElement('style');
|
121
|
+
styleElement.textContent = css;
|
122
|
+
styleElement.setAttribute('data-proteus-container', containerName);
|
123
|
+
document.head.appendChild(styleElement);
|
124
|
+
}
|
125
|
+
/**
|
126
|
+
* Remove container query styles
|
127
|
+
*/
|
128
|
+
function removeContainerQuery(containerName) {
|
129
|
+
const styleElements = document.querySelectorAll(`style[data-proteus-container="${containerName}"]`);
|
130
|
+
styleElements.forEach(element => element.remove());
|
131
|
+
}
|
132
|
+
/**
|
133
|
+
* Get container size information
|
134
|
+
*/
|
135
|
+
function getContainerSize(target) {
|
136
|
+
const targetEl = typeof target === 'string' ? document.querySelector(target) : target;
|
137
|
+
if (!targetEl) {
|
138
|
+
throw new Error('Target element not found');
|
139
|
+
}
|
140
|
+
const rect = targetEl.getBoundingClientRect();
|
141
|
+
return {
|
142
|
+
width: rect.width,
|
143
|
+
height: rect.height
|
144
|
+
};
|
145
|
+
}
|
146
|
+
/**
|
147
|
+
* Check if container queries are supported
|
148
|
+
*/
|
149
|
+
function isSupported() {
|
150
|
+
return CSS.supports('container-type', 'size');
|
151
|
+
}
|
152
|
+
/**
|
153
|
+
* Cleanup container overlays and observers
|
154
|
+
*/
|
155
|
+
function cleanup(target) {
|
156
|
+
const targetEl = typeof target === 'string' ? document.querySelector(target) : target;
|
157
|
+
if (!targetEl)
|
158
|
+
return;
|
159
|
+
// Call stored cleanup function if it exists
|
160
|
+
const elementWithCleanup = targetEl;
|
161
|
+
if (elementWithCleanup._proteusContainerCleanup) {
|
162
|
+
elementWithCleanup._proteusContainerCleanup();
|
163
|
+
delete elementWithCleanup._proteusContainerCleanup;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
/**
|
167
|
+
* Toggle dev overlay visibility
|
168
|
+
*/
|
169
|
+
function toggleDevOverlay(visible) {
|
170
|
+
const overlays = document.querySelectorAll('.proteus-container-overlay');
|
171
|
+
overlays.forEach(overlay => {
|
172
|
+
const element = overlay;
|
173
|
+
if (visible !== undefined) {
|
174
|
+
element.style.display = visible ? 'block' : 'none';
|
175
|
+
}
|
176
|
+
else {
|
177
|
+
element.style.display = element.style.display === 'none' ? 'block' : 'none';
|
178
|
+
}
|
179
|
+
});
|
180
|
+
}
|
181
|
+
// Export default object for convenience
|
182
|
+
var index = {
|
183
|
+
defineContainer,
|
184
|
+
createContainerQuery,
|
185
|
+
applyContainerQuery,
|
186
|
+
removeContainerQuery,
|
187
|
+
getContainerSize,
|
188
|
+
isSupported,
|
189
|
+
cleanup,
|
190
|
+
toggleDevOverlay
|
191
|
+
};
|
192
|
+
|
193
|
+
export { applyContainerQuery, cleanup, createContainerQuery, index as default, defineContainer, getContainerSize, isSupported, removeContainerQuery, toggleDevOverlay };
|
194
|
+
//# sourceMappingURL=container.esm.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"container.esm.js","sources":["../../src/modules/container/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAAA;;;;;;;AAOG;AAOH;;AAEG;AACG,SAAU,eAAe,CAC7B,MAAwB,EACxB,IAAa,EACb,OAAyB,EAAE,EAAA;AAE3B,IAAA,MAAM,QAAQ,GAAG,OAAO,MAAM,KAAK,QAAQ,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM;IACrF,IAAI,CAAC,QAAQ,EAAE;AACb,QAAA,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC;IAC7C;AAEA,IAAA,MAAM,EACJ,IAAI,GAAG,MAAM,EACb,UAAU,EAAE,WAAW,GAAG,IAAI,EAC/B,GAAG,IAAI;IAER,MAAM,aAAa,GAAG,IAAI,IAAI,aAAa,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA,CAAE;;IAGxF,MAAM,OAAO,GAAG,QAAuB;AACvC,IAAA,OAAO,CAAC,KAAK,CAAC,aAAa,GAAG,aAAa;AAC3C,IAAA,OAAO,CAAC,KAAK,CAAC,aAAa,GAAG,IAAI;;AAGlC,IAAA,MAAM,aAAa,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAC/C,IAAI,CAAC,aAAa,CAAC,OAAO,IAAI,aAAa,CAAC,OAAO,KAAK,MAAM,EAAE;AAC9D,QAAA,O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AAsB;AACtC,QAAA,IAAI,OAAO,KAAK,SAAS,EAAE;AACzB,YAAA,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM;QACpD;aAAO;YACL,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,KAAK,MAAM,GAAG,OAAO,GAAG,MAAM;QAC7E;AACF,IAAA,CAAC,CAAC;AACJ;AAEA;AACA,YAAe;IACb,eAAe;IACf,oBAAoB;IACpB,mBAAmB;IACnB,oBAAoB;IACpB,gBAAgB;IAChB,WAAW;IACX,OAAO;IACP;CACD;;;;"}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
/**
|
2
|
+
* @sc4rfurryx/proteusjs/perf
|
3
|
+
* Performance guardrails and CWV-friendly patterns
|
4
|
+
*
|
5
|
+
* @version 1.1.0
|
6
|
+
* @author sc4rfurry
|
7
|
+
* @license MIT
|
8
|
+
*/
|
9
|
+
interface SpeculationOptions {
|
10
|
+
prerender?: string[];
|
11
|
+
prefetch?: string[];
|
12
|
+
sameOriginOnly?: boolean;
|
13
|
+
}
|
14
|
+
interface ContentVisibilityOptions {
|
15
|
+
containIntrinsicSize?: string;
|
16
|
+
}
|
17
|
+
/**
|
18
|
+
* Apply content-visibility for performance optimization
|
19
|
+
*/
|
20
|
+
declare function contentVisibility(selector: string | Element, mode?: 'auto' | 'hidden', opts?: ContentVisibilityOptions): void;
|
21
|
+
/**
|
22
|
+
* Set fetch priority for resources
|
23
|
+
*/
|
24
|
+
declare function fetchPriority(selector: string | Element, priority: 'high' | 'low' | 'auto'): void;
|
25
|
+
/**
|
26
|
+
* Set up speculation rules for prerendering and prefetching
|
27
|
+
*/
|
28
|
+
declare function speculate(opts: SpeculationOptions): void;
|
29
|
+
/**
|
30
|
+
* Yield to browser using scheduler.yield or postTask when available
|
31
|
+
*/
|
32
|
+
declare function yieldToBrowser(): Promise<void>;
|
33
|
+
/**
|
34
|
+
* Optimize images with loading and decoding hints
|
35
|
+
*/
|
36
|
+
declare function optimizeImages(selector?: string | Element): void;
|
37
|
+
/**
|
38
|
+
* Preload critical resources
|
39
|
+
*/
|
40
|
+
declare function preloadCritical(resources: Array<{
|
41
|
+
href: string;
|
42
|
+
as: string;
|
43
|
+
type?: string;
|
44
|
+
}>): void;
|
45
|
+
/**
|
46
|
+
* Measure and report Core Web Vitals
|
47
|
+
*/
|
48
|
+
declare function measureCWV(): Promise<{
|
49
|
+
lcp?: number;
|
50
|
+
fid?: number;
|
51
|
+
cls?: number;
|
52
|
+
}>;
|
53
|
+
declare const boost: {
|
54
|
+
contentVisibility: typeof contentVisibility;
|
55
|
+
fetchPriority: typeof fetchPriority;
|
56
|
+
speculate: typeof speculate;
|
57
|
+
yieldToBrowser: typeof yieldToBrowser;
|
58
|
+
optimizeImages: typeof optimizeImages;
|
59
|
+
preloadCritical: typeof preloadCritical;
|
60
|
+
measureCWV: typeof measureCWV;
|
61
|
+
};
|
62
|
+
declare const _default: {
|
63
|
+
contentVisibility: typeof contentVisibility;
|
64
|
+
fetchPriority: typeof fetchPriority;
|
65
|
+
speculate: typeof speculate;
|
66
|
+
yieldToBrowser: typeof yieldToBrowser;
|
67
|
+
optimizeImages: typeof optimizeImages;
|
68
|
+
preloadCritical: typeof preloadCritical;
|
69
|
+
measureCWV: typeof measureCWV;
|
70
|
+
boost: {
|
71
|
+
contentVisibility: typeof contentVisibility;
|
72
|
+
fetchPriority: typeof fetchPriority;
|
73
|
+
speculate: typeof speculate;
|
74
|
+
yieldToBrowser: typeof yieldToBrowser;
|
75
|
+
optimizeImages: typeof optimizeImages;
|
76
|
+
preloadCritical: typeof preloadCritical;
|
77
|
+
measureCWV: typeof measureCWV;
|
78
|
+
};
|
79
|
+
};
|
80
|
+
|
81
|
+
export { boost, contentVisibility, _default as default, fetchPriority, measureCWV, optimizeImages, preloadCritical, speculate, yieldToBrowser };
|
82
|
+
export type { ContentVisibilityOptions, SpeculationOptions };
|
@@ -0,0 +1,257 @@
|
|
1
|
+
/*!
|
2
|
+
* ProteusJS v1.1.1
|
3
|
+
* Shape-shifting responsive design that adapts like the sea god himself
|
4
|
+
* (c) 2025 sc4rfurry
|
5
|
+
* Released under the MIT License
|
6
|
+
*/
|
7
|
+
/**
|
8
|
+
* @sc4rfurryx/proteusjs/perf
|
9
|
+
* Performance guardrails and CWV-friendly patterns
|
10
|
+
*
|
11
|
+
* @version 1.1.0
|
12
|
+
* @author sc4rfurry
|
13
|
+
* @license MIT
|
14
|
+
*/
|
15
|
+
/**
|
16
|
+
* Apply content-visibility for performance optimization
|
17
|
+
*/
|
18
|
+
function contentVisibility(selector, mode = 'auto', opts = {}) {
|
19
|
+
const elements = typeof selector === 'string'
|
20
|
+
? document.querySelectorAll(selector)
|
21
|
+
: [selector];
|
22
|
+
const { containIntrinsicSize = '1000px 400px' } = opts;
|
23
|
+
elements.forEach(element => {
|
24
|
+
const el = element;
|
25
|
+
el.style.contentVisibility = mode;
|
26
|
+
if (mode === 'auto') {
|
27
|
+
el.style.containIntrinsicSize = containIntrinsicSize;
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}
|
31
|
+
/**
|
32
|
+
* Set fetch priority for resources
|
33
|
+
*/
|
34
|
+
function fetchPriority(selector, priority) {
|
35
|
+
const elements = typeof selector === 'string'
|
36
|
+
? document.querySelectorAll(selector)
|
37
|
+
: [selector];
|
38
|
+
elements.forEach(element => {
|
39
|
+
if (element instanceof HTMLImageElement ||
|
40
|
+
element instanceof HTMLLinkElement ||
|
41
|
+
element instanceof HTMLScriptElement) {
|
42
|
+
element.fetchPriority = priority;
|
43
|
+
}
|
44
|
+
});
|
45
|
+
}
|
46
|
+
/**
|
47
|
+
* Set up speculation rules for prerendering and prefetching
|
48
|
+
*/
|
49
|
+
function speculate(opts) {
|
50
|
+
const { prerender = [], prefetch = [], sameOriginOnly = true } = opts;
|
51
|
+
// Check for Speculation Rules API support
|
52
|
+
if (!('supports' in HTMLScriptElement && HTMLScriptElement.supports('speculationrules'))) {
|
53
|
+
console.warn('Speculation Rules API not supported');
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
const rules = {};
|
57
|
+
if (prerender.length > 0) {
|
58
|
+
rules.prerender = prerender.map(url => {
|
59
|
+
const rule = { where: { href_matches: url } };
|
60
|
+
if (sameOriginOnly) {
|
61
|
+
rule.where.href_matches = new URL(url, window.location.origin).href;
|
62
|
+
}
|
63
|
+
return rule;
|
64
|
+
});
|
65
|
+
}
|
66
|
+
if (prefetch.length > 0) {
|
67
|
+
rules.prefetch = prefetch.map(url => {
|
68
|
+
const rule = { where: { href_matches: url } };
|
69
|
+
if (sameOriginOnly) {
|
70
|
+
rule.where.href_matches = new URL(url, window.location.origin).href;
|
71
|
+
}
|
72
|
+
return rule;
|
73
|
+
});
|
74
|
+
}
|
75
|
+
if (Object.keys(rules).length === 0)
|
76
|
+
return;
|
77
|
+
// Create and inject speculation rules script
|
78
|
+
const script = document.createElement('script');
|
79
|
+
script.type = 'speculationrules';
|
80
|
+
script.textContent = JSON.stringify(rules);
|
81
|
+
document.head.appendChild(script);
|
82
|
+
}
|
83
|
+
/**
|
84
|
+
* Yield to browser using scheduler.yield or postTask when available
|
85
|
+
*/
|
86
|
+
async function yieldToBrowser() {
|
87
|
+
// Use scheduler.yield if available (Chrome 115+)
|
88
|
+
if ('scheduler' in window && 'yield' in window.scheduler) {
|
89
|
+
return window.scheduler.yield();
|
90
|
+
}
|
91
|
+
// Use scheduler.postTask if available
|
92
|
+
if ('scheduler' in window && 'postTask' in window.scheduler) {
|
93
|
+
return new Promise(resolve => {
|
94
|
+
window.scheduler.postTask(resolve, { priority: 'user-blocking' });
|
95
|
+
});
|
96
|
+
}
|
97
|
+
// Fallback to setTimeout
|
98
|
+
return new Promise(resolve => {
|
99
|
+
setTimeout(resolve, 0);
|
100
|
+
});
|
101
|
+
}
|
102
|
+
/**
|
103
|
+
* Optimize images with loading and decoding hints
|
104
|
+
*/
|
105
|
+
function optimizeImages(selector = 'img') {
|
106
|
+
const images = typeof selector === 'string'
|
107
|
+
? document.querySelectorAll(selector)
|
108
|
+
: [selector];
|
109
|
+
images.forEach(img => {
|
110
|
+
if (!(img instanceof HTMLImageElement))
|
111
|
+
return;
|
112
|
+
// Set loading attribute if not already set
|
113
|
+
if (!img.hasAttribute('loading')) {
|
114
|
+
const rect = img.getBoundingClientRect();
|
115
|
+
const isAboveFold = rect.top < window.innerHeight;
|
116
|
+
img.loading = isAboveFold ? 'eager' : 'lazy';
|
117
|
+
}
|
118
|
+
// Set decoding hint
|
119
|
+
if (!img.hasAttribute('decoding')) {
|
120
|
+
img.decoding = 'async';
|
121
|
+
}
|
122
|
+
// Set fetch priority for above-fold images
|
123
|
+
if (!img.hasAttribute('fetchpriority')) {
|
124
|
+
const rect = img.getBoundingClientRect();
|
125
|
+
const isAboveFold = rect.top < window.innerHeight;
|
126
|
+
if (isAboveFold) {
|
127
|
+
img.fetchPriority = 'high';
|
128
|
+
}
|
129
|
+
}
|
130
|
+
});
|
131
|
+
}
|
132
|
+
/**
|
133
|
+
* Preload critical resources
|
134
|
+
*/
|
135
|
+
function preloadCritical(resources) {
|
136
|
+
resources.forEach(({ href, as, type }) => {
|
137
|
+
// Check if already preloaded
|
138
|
+
const existing = document.querySelector(`link[rel="preload"][href="${href}"]`);
|
139
|
+
if (existing)
|
140
|
+
return;
|
141
|
+
const link = document.createElement('link');
|
142
|
+
link.rel = 'preload';
|
143
|
+
link.href = href;
|
144
|
+
link.as = as;
|
145
|
+
if (type) {
|
146
|
+
link.type = type;
|
147
|
+
}
|
148
|
+
document.head.appendChild(link);
|
149
|
+
});
|
150
|
+
}
|
151
|
+
/**
|
152
|
+
* Measure and report Core Web Vitals
|
153
|
+
*/
|
154
|
+
function measureCWV() {
|
155
|
+
return new Promise(resolve => {
|
156
|
+
const metrics = {};
|
157
|
+
let metricsCount = 0;
|
158
|
+
const totalMetrics = 3;
|
159
|
+
const checkComplete = () => {
|
160
|
+
metricsCount++;
|
161
|
+
if (metricsCount >= totalMetrics) {
|
162
|
+
resolve(metrics);
|
163
|
+
}
|
164
|
+
};
|
165
|
+
// LCP (Largest Contentful Paint)
|
166
|
+
if ('PerformanceObserver' in window) {
|
167
|
+
try {
|
168
|
+
const lcpObserver = new PerformanceObserver(list => {
|
169
|
+
const entries = list.getEntries();
|
170
|
+
const lastEntry = entries[entries.length - 1];
|
171
|
+
metrics.lcp = lastEntry.startTime;
|
172
|
+
});
|
173
|
+
lcpObserver.observe({ entryTypes: ['largest-contentful-paint'] });
|
174
|
+
// Stop observing after 10 seconds
|
175
|
+
setTimeout(() => {
|
176
|
+
lcpObserver.disconnect();
|
177
|
+
checkComplete();
|
178
|
+
}, 10000);
|
179
|
+
}
|
180
|
+
catch {
|
181
|
+
checkComplete();
|
182
|
+
}
|
183
|
+
// FID (First Input Delay)
|
184
|
+
try {
|
185
|
+
const fidObserver = new PerformanceObserver(list => {
|
186
|
+
const entries = list.getEntries();
|
187
|
+
entries.forEach((entry) => {
|
188
|
+
metrics.fid = entry.processingStart - entry.startTime;
|
189
|
+
});
|
190
|
+
fidObserver.disconnect();
|
191
|
+
checkComplete();
|
192
|
+
});
|
193
|
+
fidObserver.observe({ entryTypes: ['first-input'] });
|
194
|
+
// If no input after 10 seconds, consider FID as 0
|
195
|
+
setTimeout(() => {
|
196
|
+
if (metrics.fid === undefined) {
|
197
|
+
metrics.fid = 0;
|
198
|
+
fidObserver.disconnect();
|
199
|
+
checkComplete();
|
200
|
+
}
|
201
|
+
}, 10000);
|
202
|
+
}
|
203
|
+
catch {
|
204
|
+
checkComplete();
|
205
|
+
}
|
206
|
+
// CLS (Cumulative Layout Shift)
|
207
|
+
try {
|
208
|
+
let clsValue = 0;
|
209
|
+
const clsObserver = new PerformanceObserver(list => {
|
210
|
+
list.getEntries().forEach((entry) => {
|
211
|
+
if (!entry.hadRecentInput) {
|
212
|
+
clsValue += entry.value;
|
213
|
+
}
|
214
|
+
});
|
215
|
+
metrics.cls = clsValue;
|
216
|
+
});
|
217
|
+
clsObserver.observe({ entryTypes: ['layout-shift'] });
|
218
|
+
// Stop observing after 10 seconds
|
219
|
+
setTimeout(() => {
|
220
|
+
clsObserver.disconnect();
|
221
|
+
checkComplete();
|
222
|
+
}, 10000);
|
223
|
+
}
|
224
|
+
catch {
|
225
|
+
checkComplete();
|
226
|
+
}
|
227
|
+
}
|
228
|
+
else {
|
229
|
+
// Fallback if PerformanceObserver is not supported
|
230
|
+
setTimeout(() => resolve(metrics), 100);
|
231
|
+
}
|
232
|
+
});
|
233
|
+
}
|
234
|
+
// Export boost object to match usage examples in upgrade spec
|
235
|
+
const boost = {
|
236
|
+
contentVisibility,
|
237
|
+
fetchPriority,
|
238
|
+
speculate,
|
239
|
+
yieldToBrowser,
|
240
|
+
optimizeImages,
|
241
|
+
preloadCritical,
|
242
|
+
measureCWV
|
243
|
+
};
|
244
|
+
// Export all functions as named exports and default object
|
245
|
+
var index = {
|
246
|
+
contentVisibility,
|
247
|
+
fetchPriority,
|
248
|
+
speculate,
|
249
|
+
yieldToBrowser,
|
250
|
+
optimizeImages,
|
251
|
+
preloadCritical,
|
252
|
+
measureCWV,
|
253
|
+
boost
|
254
|
+
};
|
255
|
+
|
256
|
+
export { boost, contentVisibility, index as default, fetchPriority, measureCWV, optimizeImages, preloadCritical, speculate, yieldToBrowser };
|
257
|
+
//# sourceMappingURL=perf.esm.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"perf.esm.js","sources":["../../src/modules/perf/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AAAA;;;;;;;AAOG;AAYH;;AAEG;AACG,SAAU,iBAAiB,CAC/B,QAA0B,EAC1B,IAAA,GAA0B,MAAM,EAChC,IAAA,GAAiC,EAAE,EAAA;AAEnC,IAAA,MAAM,QAAQ,GAAG,OAAO,QAAQ,KAAK;AACnC,UAAE,QAAQ,CAAC,gBAAgB,CAAC,QAAQ;AACpC,UAAE,CAAC,QAAQ,CAAC;AAEd,IAAA,MAAM,EAAE,oBA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AC,CAAC,KAAU,KAAI;AACvC,wBAAA,IAAI,CAAC,KAAK,CAAC,cAAc,EAAE;AACzB,4BAAA,QAAQ,IAAI,KAAK,CAAC,KAAK;wBACzB;AACF,oBAAA,CAAC,CAAC;AACF,oBAAA,OAAO,CAAC,GAAG,GAAG,QAAQ;AACxB,gBAAA,CAAC,CAAC;gBACF,WAAW,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC;;gBAGrD,UAAU,CAAC,MAAK;oBACd,WAAW,CAAC,UAAU,EAAE;AACxB,oBAAA,aAAa,EAAE;gBACjB,CAAC,EAAE,KAAK,CAAC;YACX;AAAE,YAAA,MAAM;AACN,gBAAA,aAAa,EAAE;YACjB;QACF;aAAO;;YAEL,UAAU,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC;QACzC;AACF,IAAA,CAAC,CAAC;AACJ;AAEA;AACO,MAAM,KAAK,GAAG;IACnB,iBAAiB;IACjB,aAAa;IACb,SAAS;IACT,cAAc;IACd,cAAc;IACd,eAAe;IACf;;AAGF;AACA,YAAe;IACb,iBAAiB;IACjB,aAAa;IACb,SAAS;IACT,cAAc;IACd,cAAc;IACd,eAAe;IACf,UAAU;IACV;CACD;;;;"}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/**
|
2
|
+
* @sc4rfurryx/proteusjs/popover
|
3
|
+
* HTML Popover API wrapper with robust focus/inert handling
|
4
|
+
*
|
5
|
+
* @version 1.1.0
|
6
|
+
* @author sc4rfurry
|
7
|
+
* @license MIT
|
8
|
+
*/
|
9
|
+
interface PopoverOptions {
|
10
|
+
type?: 'menu' | 'dialog' | 'tooltip';
|
11
|
+
trapFocus?: boolean;
|
12
|
+
restoreFocus?: boolean;
|
13
|
+
closeOnEscape?: boolean;
|
14
|
+
onOpen?: () => void;
|
15
|
+
onClose?: () => void;
|
16
|
+
}
|
17
|
+
interface PopoverController {
|
18
|
+
open(): void;
|
19
|
+
close(): void;
|
20
|
+
toggle(): void;
|
21
|
+
destroy(): void;
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* Unified API for menus, tooltips, and dialogs using the native Popover API
|
25
|
+
* with robust focus/inert handling
|
26
|
+
*/
|
27
|
+
declare function attach(trigger: Element | string, panel: Element | string, opts?: PopoverOptions): PopoverController;
|
28
|
+
declare const _default: {
|
29
|
+
attach: typeof attach;
|
30
|
+
};
|
31
|
+
|
32
|
+
export { attach, _default as default };
|
33
|
+
export type { PopoverController, PopoverOptions };
|