@dinoreic/fez 0.2.0 → 0.2.2

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/src/log.js ADDED
@@ -0,0 +1,154 @@
1
+ // pretty print HTML
2
+ const LOG_PP = (html) => {
3
+ const parts = html
4
+ .split(/(<\/?[^>]+>)/g)
5
+ .map(p => p.trim())
6
+ .filter(p => p);
7
+
8
+ let indent = 0;
9
+ const lines = [];
10
+
11
+ for (let i = 0; i < parts.length; i++) {
12
+ const part = parts[i];
13
+ const nextPart = parts[i + 1];
14
+ const nextNextPart = parts[i + 2];
15
+
16
+ // Check if it's a tag
17
+ if (part.startsWith('<')) {
18
+ // Check if this is an opening tag followed by text and then its closing tag
19
+ if (!part.startsWith('</') && !part.endsWith('/>') && nextPart && !nextPart.startsWith('<') && nextNextPart && nextNextPart.startsWith('</')) {
20
+ // Combine them on one line
21
+ const actualIndent = Math.max(0, indent);
22
+ lines.push(' '.repeat(actualIndent) + part + nextPart + nextNextPart);
23
+ i += 2; // Skip the next two parts
24
+ }
25
+ // Closing tag
26
+ else if (part.startsWith('</')) {
27
+ indent--;
28
+ const actualIndent = Math.max(0, indent);
29
+ lines.push(' '.repeat(actualIndent) + part);
30
+ }
31
+ // Self-closing tag
32
+ else if (part.endsWith('/>') || part.includes(' />')) {
33
+ const actualIndent = Math.max(0, indent);
34
+ lines.push(' '.repeat(actualIndent) + part);
35
+ }
36
+ // Opening tag
37
+ else {
38
+ const actualIndent = Math.max(0, indent);
39
+ lines.push(' '.repeat(actualIndent) + part);
40
+ indent++;
41
+ }
42
+ }
43
+ // Text node
44
+ else if (part) {
45
+ const actualIndent = Math.max(0, indent);
46
+ lines.push(' '.repeat(actualIndent) + part);
47
+ }
48
+ }
49
+
50
+ return lines.join('\n');
51
+ }
52
+
53
+ const LOG = (() => {
54
+ const logs = [];
55
+ const logTypes = []; // Track the original type of each log
56
+ let currentIndex = 0;
57
+
58
+ return o => {
59
+ if (!document.body) {
60
+ window.requestAnimationFrame( () => LOG(o) )
61
+ return
62
+ }
63
+
64
+ if (o instanceof Node) {
65
+ o = LOG_PP(o.outerHTML)
66
+ }
67
+
68
+ // Store the original type
69
+ let originalType = typeof o;
70
+
71
+ if (o === undefined) { o = 'undefined' }
72
+ if (o === null) { o = 'null' }
73
+
74
+ if (Array.isArray(o)) {
75
+ originalType = 'array';
76
+ } else if (typeof o === 'object' && o !== null) {
77
+ originalType = 'object';
78
+ }
79
+
80
+ if (typeof o != 'string') {
81
+ o = JSON.stringify(o, (key, value) => {
82
+ if (typeof value === 'function') {
83
+ return String(value);
84
+ }
85
+ return value;
86
+ }, 2).replaceAll('<', '&lt;')
87
+ }
88
+
89
+ o = o.trim()
90
+
91
+ logs.push(o + `\n\ntype: ${originalType}`);
92
+ logTypes.push(originalType);
93
+
94
+ let d = document.getElementById('dump-dialog');
95
+ if (!d) {
96
+ d = document.body.appendChild(document.createElement('div'));
97
+ d.id = 'dump-dialog';
98
+ d.style.cssText =
99
+ 'position:fixed;top:30px;left:30px;right:50px;bottom:50px;' +
100
+ 'background:#fff;border:1px solid#333;box-shadow:0 0 10px rgba(0,0,0,0.5);' +
101
+ 'padding:20px;overflow:auto;z-index:9999;font:13px/1.4 monospace;white-space:pre';
102
+ }
103
+
104
+ // Check if we have a saved index and it's still valid
105
+ const savedIndex = parseInt(localStorage.getItem('_LOG_INDEX'));
106
+ if (!isNaN(savedIndex) && savedIndex >= 0 && savedIndex < logs.length) {
107
+ currentIndex = savedIndex;
108
+ } else {
109
+ currentIndex = logs.length - 1;
110
+ }
111
+
112
+ const renderContent = () => {
113
+ const buttons = logs.map((_, i) => {
114
+ let bgColor = '#f0f0f0'; // default
115
+ if (i !== currentIndex) {
116
+ if (logTypes[i] === 'object') {
117
+ bgColor = '#d6e3ef'; // super light blue
118
+ } else if (logTypes[i] === 'array') {
119
+ bgColor = '#d8d5ef'; // super light indigo
120
+ }
121
+ }
122
+ return `<button style="padding:4px 8px;margin:0;cursor:pointer;background:${i === currentIndex ? '#333' : bgColor};color:${i === currentIndex ? '#fff' : '#000'}" data-index="${i}">${i + 1}</button>`
123
+ }).join('');
124
+
125
+ d.innerHTML =
126
+ '<div style="display:flex;flex-direction:column;height:100%">' +
127
+ '<div style="display:flex;justify-content:space-between;align-items:flex-start;margin-bottom:10px">' +
128
+ '<div style="display:flex;flex-wrap:wrap;gap:4px;flex:1;margin-right:10px">' + buttons + '</div>' +
129
+ '<button style="padding:4px 8px;cursor:pointer;flex-shrink:0">&times;</button>' +
130
+ '</div>' +
131
+ '<xmp style="flex:1;overflow:auto;margin:0;padding:0;color:#000;background:#fff;font-size:14px;line-height:22px">' + logs[currentIndex] + '</xmp>' +
132
+ '</div>';
133
+
134
+ d.querySelector('button[style*="flex-shrink:0"]').onclick = () => d.remove();
135
+
136
+ d.querySelectorAll('button[data-index]').forEach(btn => {
137
+ btn.onclick = () => {
138
+ currentIndex = parseInt(btn.dataset.index);
139
+ localStorage.setItem('_LOG_INDEX', currentIndex);
140
+ renderContent();
141
+ };
142
+ });
143
+ };
144
+
145
+ renderContent();
146
+ };
147
+ })();
148
+
149
+ if (typeof window !== 'undefined') {
150
+ window.LOG = LOG
151
+ window.LOG_PP = LOG_PP
152
+ }
153
+
154
+ export default LOG
package/src/rollup.js CHANGED
@@ -22,10 +22,4 @@ function fezPlugin() {
22
22
  };
23
23
  }
24
24
 
25
- // Export for ES modules
26
25
  export default fezPlugin;
27
-
28
- // Export for CommonJS
29
- // if (typeof module !== 'undefined') {
30
- // module.exports = fezPlugin;
31
- // }