driftjs-shared 0.0.7 → 0.0.9
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/dist/index-cjs.js +2 -0
- package/dist/index-es.js +298 -51
- package/package.json +7 -3
- package/dist/index-umd.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=256,t=new Set([`area`,`base`,`br`,`col`,`embed`,`hr`,`img`,`input`,`link`,`meta`,`param`,`source`,`track`,`wbr`]);function n(e){return Array.isArray(e)?e:e&&typeof e[Symbol.iterator]==`function`?Array.from(e):[]}function r(e,t,r){return typeof e==`function`?e(t,r,f,p,n,m):typeof e.__drift_fn__==`function`?e.__drift_fn__(t,r,f,p,n,m):(e._executableFn||=typeof e.__drift_fn__==`string`?Function(`return (`+e.__drift_fn__+`)`)():e.__drift_fn__,e._executableFn(t,r,f,p,n,m))}function i(e,t,a){if(e==null)return e;if(typeof e==`function`)return e(t,a,f,p,n,m);if(typeof e==`object`&&e){if(`__drift_fn__`in e||typeof e._executableFn==`function`)return r(e,t,a);if(Array.isArray(e)){let n;for(let r of e)n=i(r,t,a);return n}}return e}function a(e){return!e||typeof e!=`object`?null:Array.isArray(e.bytecode)||ArrayBuffer.isView(e.bytecode)?e:e.program&&(Array.isArray(e.program.bytecode)||ArrayBuffer.isView(e.program.bytecode))?e.program:e.default?a(e.default):e.compiledModule?a(e.compiledModule):null}function o(e,t,n){if(!e||typeof e!=`object`)return{};let r={};for(let a of Object.keys(e)){if(a===`__drift_props__`||a===`__drift_children__`||a===`__proto__`||a===`constructor`||a===`prototype`)continue;let o=e[a];r[a]=i(o,t,n)}return r}function s(e,t){let n=t-1;for(;n>=0&&/\s/.test(e[n]);)n--;if(n<0)return!0;let r=e[n];return/[(,=:[!&|?+\-*/%^~<>]/.test(r)}function c(e,t){let n=0,r=0,i=0,a=null,o=!1,c=!1,l=!1,u=!1,d=!1,f=[];for(let p=0;p<e.length;p++){let m=e[p];if(a!==null){if(o){o=!1;continue}if(m===`\\`){o=!0;continue}if(a==="`"&&m===`$`&&e[p+1]===`{`){f.push(i),a=null,p++,i++;continue}if(m===a){a=null;continue}continue}if(c){m===`
|
|
2
|
+
`&&(c=!1);continue}if(l){m===`*`&&e[p+1]===`/`&&(l=!1,p++);continue}if(u){if(o){o=!1;continue}if(m===`\\`){o=!0;continue}if(d){m===`]`&&(d=!1);continue}if(m===`[`){d=!0;continue}if(m===`/`){u=!1;continue}continue}if(m===`/`&&e[p+1]===`/`){c=!0,p++;continue}if(m===`/`&&e[p+1]===`*`){l=!0,p++;continue}if(m===`/`&&s(e,p)){u=!0,d=!1;continue}if(m===`'`||m===`"`||m==="`"){a=m;continue}if(m===`(`){n++;continue}if(m===`)`){n=Math.max(0,n-1);continue}if(m===`[`){r++;continue}if(m===`]`){r=Math.max(0,r-1);continue}if(m===`{`){i++;continue}if(m===`}`){i=Math.max(0,i-1),f.length>0&&i===f[f.length-1]&&(f.pop(),a="`");continue}if(n===0&&r===0&&i===0&&a===null&&!c&&!l&&!u){let e=t(p,m);if(typeof e==`number`)return e;if(e===!0)return p}}return-1}function l(e,t){return c(e,(e,n)=>n===t)}function u(e,t=`,`){let n=[],r=0;c(e,(i,a)=>{if(a===t){let t=e.slice(r,i).trim();t&&n.push(t),r=i+1}});let i=e.slice(r).trim();return i&&n.push(i),n}function d(e){let t=e.trim();if(!t.startsWith(`(`)||!t.endsWith(`)`))return!1;let n=0,r=null,i=!1;for(let e=0;e<t.length-1;e++){let a=t[e];if(r!==null){i?i=!1:a===`\\`?i=!0:a===r&&(r=null);continue}if(a===`"`||a===`'`||a==="`"){r=a;continue}if(a===`(`?n++:a===`)`&&n--,n===0)return!1}return n===1}function f(e,t,n){if(!e||typeof e!=`object`||t===`__proto__`||t===`constructor`||t===`prototype`||t===`__drift_mark_dirty__`)return n;let r=e,i=null,a=new Set;for(;r&&r!==Object.prototype;){if(Object.prototype.hasOwnProperty.call(r,t)){r[t]=n,i=r;break}r=Object.getPrototypeOf(r)}i||=(e[t]=n,e);let o=e;for(;o&&o!==Object.prototype&&(typeof o.__drift_mark_dirty__==`function`&&a.add(o.__drift_mark_dirty__),o!==i);)o=Object.getPrototypeOf(o);if(!t.startsWith(`__drift_`))for(let e of a)try{e(t)}catch(e){console.error(`[DriftJS] Error notifying dirty update for "${t}":`,e)}return n}function p(e,t){if(!e||typeof e!=`object`)return!1;let n=e;for(;n&&n!==Object.prototype;){if(Object.prototype.hasOwnProperty.call(n,t))return!0;n=Object.getPrototypeOf(n)}return!1}function m(e,t){if(e&&p(e,t))return e[t];if(typeof globalThis<`u`&&globalThis){if(t===`__proto__`||t===`constructor`||t===`prototype`||t===`__drift_mark_dirty__`)return;let e=globalThis;for(;e&&e!==Object.prototype;){if(Object.prototype.hasOwnProperty.call(e,t))return globalThis[t];e=Object.getPrototypeOf(e)}}}var h=m;typeof globalThis<`u`&&!globalThis._get&&(globalThis._get=m);function g(e,t,n){!e||typeof e!=`object`||t===`__proto__`||t===`constructor`||t===`prototype`||t===`__drift_mark_dirty__`||(e[t]=n)}function _(e,t,r,i,a){if(g(e,t,r),i&&g(e,i,a),t.startsWith(`{`)&&t.endsWith(`}`)){let n=r&&typeof r==`object`?r:{},i=u(t.slice(1,-1));for(let t of i){let r=l(t,`:`);if(r!==-1){let i=t.slice(0,r).trim(),a=t.slice(r+1).trim(),o=l(a,`=`);if(o!==-1){let t=a.slice(0,o).trim(),r=a.slice(o+1).trim(),s=Object.prototype.hasOwnProperty.call(n,i)?n[i]:void 0;g(e,t,s===void 0?v(r,e):s)}else a.startsWith(`{`)||a.startsWith(`[`)?_(e,a,Object.prototype.hasOwnProperty.call(n,i)?n[i]:void 0,null,0):g(e,a,Object.prototype.hasOwnProperty.call(n,i)?n[i]:void 0)}else{let r=l(t,`=`);if(r!==-1){let i=t.slice(0,r).trim(),a=t.slice(r+1).trim(),o=Object.prototype.hasOwnProperty.call(n,i)?n[i]:void 0;g(e,i,o===void 0?v(a,e):o)}else g(e,t,Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0)}}}else if(t.startsWith(`[`)&&t.endsWith(`]`)){let i=n(r),a=u(t.slice(1,-1));for(let t=0;t<a.length;t++){let n=a[t],r=l(n,`=`);if(r!==-1){let a=n.slice(0,r).trim(),o=n.slice(r+1).trim(),s=i[t];g(e,a,s===void 0?v(o,e):s)}else n.startsWith(`{`)||n.startsWith(`[`)?_(e,n,i[t],null,0):g(e,n,i[t])}}}function v(e,t){let n=e.trim();if(n===`true`)return!0;if(n===`false`)return!1;if(n===`null`)return null;if(n!==`undefined`){if(n.startsWith(`"`)&&n.endsWith(`"`)||n.startsWith(`'`)&&n.endsWith(`'`)||n.startsWith("`")&&n.endsWith("`"))return n.slice(1,-1);if(!Number.isNaN(Number(n))&&n!==``)return Number(n);try{return JSON.parse(n)}catch{return t&&p(t,n)?m(t,n):n}}}var y=Symbol.for(`__drift_vm_stack__`);function b(){let e=globalThis;return e[y]||(e[y]=[]),e[y]}function x(e){b().push(e)}function S(){b().pop()}function C(){let e=b();return e.length>0?e[e.length-1]:null}function w(e,t){let n={id:Symbol(t||`DriftContext`),name:t,defaultValue:e,provide(e){T(n,e)},inject(e){return E(n,e)}};return n}function T(e,t){let n=C();if(!n||!n.contextMap)throw Error(`provide() can only be called inside the <script> block of a DriftJS component during instantiation.`);n.contextMap.set(e.id,t)}function E(e,t){let n=C();if(!n)return t===void 0?e.defaultValue:t;let r=n;for(;r;){if(r.contextMap&&r.contextMap.has(e.id))return r.contextMap.get(e.id);r=r.parentVM}return t===void 0?e.defaultValue:t}var D=T,O=E;function k(e){let t=C();t?(t.unmountCallbacks||=[],t.unmountCallbacks.push(e)):console.warn(`[DriftJS] onUnmount() was called outside a component execution context. Lifecycle hooks must be called synchronously during component setup.`)}var A=new Set(`animationIterationCount.borderImageOutset.borderImageSlice.borderImageWidth.boxFlex.boxFlexGroup.boxOrdinalGroup.columnCount.columns.flex.flexGrow.flexPositive.flexShrink.flexNegative.flexOrder.gridArea.gridRow.gridRowEnd.gridRowSpan.gridRowStart.gridColumn.gridColumnEnd.gridColumnSpan.gridColumnStart.fontWeight.lineClamp.lineHeight.opacity.order.orphans.tabSize.widows.zIndex.zoom.fillOpacity.floodOpacity.stopOpacity.strokeDasharray.strokeDashoffset.strokeMiterlimit.strokeOpacity.strokeWidth`.split(`.`));function j(e){return e.startsWith(`--`)?e:e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function M(e){if(e==null||e===!1||e===``)return``;if(typeof e==`string`)return e.trim();if(Array.isArray(e))return e.map(e=>M(e)).filter(e=>!!(e&&e.length>0)).join(`; `);if(typeof e==`object`){let t=[];for(let[n,r]of Object.entries(e)){if(r==null||r===!1||r===``)continue;let e=j(n),i=r;typeof r==`number`&&r!==0&&!A.has(n)&&(i=`${r}px`),t.push(`${e}: ${i}`)}return t.join(`; `)}return String(e)}exports.MAX_REGISTERS=e,exports.VOID_ELEMENTS=t,exports._get=h,exports.camelToKebab=j,exports.createContext=w,exports.evaluateExpression=i,exports.evaluatePropsSpec=o,exports.executePrecompiledFn=r,exports.findTopLevelChar=l,exports.getActiveVM=C,exports.getScopeValue=m,exports.hasMatchingOuterParens=d,exports.inScopeChain=p,exports.inject=O,exports.injectContext=E,exports.isRegexStartChar=s,exports.normalizeStyle=M,exports.onUnmount=k,exports.popActiveVM=S,exports.populateItemScope=_,exports.provide=D,exports.provideContext=T,exports.pushActiveVM=x,exports.resolveComponentModule=a,exports.resolveIterable=n,exports.scanBalancedDelimiters=c,exports.setScopeValue=f,exports.splitPatternEntries=u;
|
package/dist/index-es.js
CHANGED
|
@@ -1,9 +1,201 @@
|
|
|
1
1
|
//#region src/constants.ts
|
|
2
|
-
var e = 256
|
|
2
|
+
var e = 256, t = /* @__PURE__ */ new Set([
|
|
3
|
+
"area",
|
|
4
|
+
"base",
|
|
5
|
+
"br",
|
|
6
|
+
"col",
|
|
7
|
+
"embed",
|
|
8
|
+
"hr",
|
|
9
|
+
"img",
|
|
10
|
+
"input",
|
|
11
|
+
"link",
|
|
12
|
+
"meta",
|
|
13
|
+
"param",
|
|
14
|
+
"source",
|
|
15
|
+
"track",
|
|
16
|
+
"wbr"
|
|
17
|
+
]);
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/evaluator.ts
|
|
20
|
+
function n(e) {
|
|
21
|
+
return Array.isArray(e) ? e : e && typeof e[Symbol.iterator] == "function" ? Array.from(e) : [];
|
|
22
|
+
}
|
|
23
|
+
function r(e, t, r) {
|
|
24
|
+
return typeof e == "function" ? e(t, r, f, p, n, m) : typeof e.__drift_fn__ == "function" ? e.__drift_fn__(t, r, f, p, n, m) : (e._executableFn ||= typeof e.__drift_fn__ == "string" ? Function("return (" + e.__drift_fn__ + ")")() : e.__drift_fn__, e._executableFn(t, r, f, p, n, m));
|
|
25
|
+
}
|
|
26
|
+
function i(e, t, a) {
|
|
27
|
+
if (e == null) return e;
|
|
28
|
+
if (typeof e == "function") return e(t, a, f, p, n, m);
|
|
29
|
+
if (typeof e == "object" && e) {
|
|
30
|
+
if ("__drift_fn__" in e || typeof e._executableFn == "function") return r(e, t, a);
|
|
31
|
+
if (Array.isArray(e)) {
|
|
32
|
+
let n;
|
|
33
|
+
for (let r of e) n = i(r, t, a);
|
|
34
|
+
return n;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return e;
|
|
38
|
+
}
|
|
39
|
+
function a(e) {
|
|
40
|
+
return !e || typeof e != "object" ? null : Array.isArray(e.bytecode) || ArrayBuffer.isView(e.bytecode) ? e : e.program && (Array.isArray(e.program.bytecode) || ArrayBuffer.isView(e.program.bytecode)) ? e.program : e.default ? a(e.default) : e.compiledModule ? a(e.compiledModule) : null;
|
|
41
|
+
}
|
|
42
|
+
function o(e, t, n) {
|
|
43
|
+
if (!e || typeof e != "object") return {};
|
|
44
|
+
let r = {};
|
|
45
|
+
for (let a of Object.keys(e)) {
|
|
46
|
+
if (a === "__drift_props__" || a === "__drift_children__" || a === "__proto__" || a === "constructor" || a === "prototype") continue;
|
|
47
|
+
let o = e[a];
|
|
48
|
+
r[a] = i(o, t, n);
|
|
49
|
+
}
|
|
50
|
+
return r;
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/scanner.ts
|
|
54
|
+
function s(e, t) {
|
|
55
|
+
let n = t - 1;
|
|
56
|
+
for (; n >= 0 && /\s/.test(e[n]);) n--;
|
|
57
|
+
if (n < 0) return !0;
|
|
58
|
+
let r = e[n];
|
|
59
|
+
return /[(,=:[!&|?+\-*/%^~<>]/.test(r);
|
|
60
|
+
}
|
|
61
|
+
function c(e, t) {
|
|
62
|
+
let n = 0, r = 0, i = 0, a = null, o = !1, c = !1, l = !1, u = !1, d = !1, f = [];
|
|
63
|
+
for (let p = 0; p < e.length; p++) {
|
|
64
|
+
let m = e[p];
|
|
65
|
+
if (a !== null) {
|
|
66
|
+
if (o) {
|
|
67
|
+
o = !1;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (m === "\\") {
|
|
71
|
+
o = !0;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (a === "`" && m === "$" && e[p + 1] === "{") {
|
|
75
|
+
f.push(i), a = null, p++, i++;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (m === a) {
|
|
79
|
+
a = null;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (c) {
|
|
85
|
+
m === "\n" && (c = !1);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (l) {
|
|
89
|
+
m === "*" && e[p + 1] === "/" && (l = !1, p++);
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
if (u) {
|
|
93
|
+
if (o) {
|
|
94
|
+
o = !1;
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (m === "\\") {
|
|
98
|
+
o = !0;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (d) {
|
|
102
|
+
m === "]" && (d = !1);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (m === "[") {
|
|
106
|
+
d = !0;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (m === "/") {
|
|
110
|
+
u = !1;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (m === "/" && e[p + 1] === "/") {
|
|
116
|
+
c = !0, p++;
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (m === "/" && e[p + 1] === "*") {
|
|
120
|
+
l = !0, p++;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (m === "/" && s(e, p)) {
|
|
124
|
+
u = !0, d = !1;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (m === "'" || m === "\"" || m === "`") {
|
|
128
|
+
a = m;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (m === "(") {
|
|
132
|
+
n++;
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (m === ")") {
|
|
136
|
+
n = Math.max(0, n - 1);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (m === "[") {
|
|
140
|
+
r++;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (m === "]") {
|
|
144
|
+
r = Math.max(0, r - 1);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (m === "{") {
|
|
148
|
+
i++;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
if (m === "}") {
|
|
152
|
+
i = Math.max(0, i - 1), f.length > 0 && i === f[f.length - 1] && (f.pop(), a = "`");
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (n === 0 && r === 0 && i === 0 && a === null && !c && !l && !u) {
|
|
156
|
+
let e = t(p, m);
|
|
157
|
+
if (typeof e == "number") return e;
|
|
158
|
+
if (e === !0) return p;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return -1;
|
|
162
|
+
}
|
|
163
|
+
function l(e, t) {
|
|
164
|
+
return c(e, (e, n) => n === t);
|
|
165
|
+
}
|
|
166
|
+
function u(e, t = ",") {
|
|
167
|
+
let n = [], r = 0;
|
|
168
|
+
c(e, (i, a) => {
|
|
169
|
+
if (a === t) {
|
|
170
|
+
let t = e.slice(r, i).trim();
|
|
171
|
+
t && n.push(t), r = i + 1;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
let i = e.slice(r).trim();
|
|
175
|
+
return i && n.push(i), n;
|
|
176
|
+
}
|
|
177
|
+
function d(e) {
|
|
178
|
+
let t = e.trim();
|
|
179
|
+
if (!t.startsWith("(") || !t.endsWith(")")) return !1;
|
|
180
|
+
let n = 0, r = null, i = !1;
|
|
181
|
+
for (let e = 0; e < t.length - 1; e++) {
|
|
182
|
+
let a = t[e];
|
|
183
|
+
if (r !== null) {
|
|
184
|
+
i ? i = !1 : a === "\\" ? i = !0 : a === r && (r = null);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (a === "\"" || a === "'" || a === "`") {
|
|
188
|
+
r = a;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (a === "(" ? n++ : a === ")" && n--, n === 0) return !1;
|
|
192
|
+
}
|
|
193
|
+
return n === 1;
|
|
194
|
+
}
|
|
3
195
|
//#endregion
|
|
4
196
|
//#region src/scope.ts
|
|
5
|
-
function
|
|
6
|
-
if (!e || typeof e != "object") return;
|
|
197
|
+
function f(e, t, n) {
|
|
198
|
+
if (!e || typeof e != "object" || t === "__proto__" || t === "constructor" || t === "prototype" || t === "__drift_mark_dirty__") return n;
|
|
7
199
|
let r = e, i = null, a = /* @__PURE__ */ new Set();
|
|
8
200
|
for (; r && r !== Object.prototype;) {
|
|
9
201
|
if (Object.prototype.hasOwnProperty.call(r, t)) {
|
|
@@ -15,11 +207,14 @@ function t(e, t, n) {
|
|
|
15
207
|
i ||= (e[t] = n, e);
|
|
16
208
|
let o = e;
|
|
17
209
|
for (; o && o !== Object.prototype && (typeof o.__drift_mark_dirty__ == "function" && a.add(o.__drift_mark_dirty__), o !== i);) o = Object.getPrototypeOf(o);
|
|
18
|
-
for (let e of a) try {
|
|
210
|
+
if (!t.startsWith("__drift_")) for (let e of a) try {
|
|
19
211
|
e(t);
|
|
20
|
-
} catch {
|
|
212
|
+
} catch (e) {
|
|
213
|
+
console.error(`[DriftJS] Error notifying dirty update for "${t}":`, e);
|
|
214
|
+
}
|
|
215
|
+
return n;
|
|
21
216
|
}
|
|
22
|
-
function
|
|
217
|
+
function p(e, t) {
|
|
23
218
|
if (!e || typeof e != "object") return !1;
|
|
24
219
|
let n = e;
|
|
25
220
|
for (; n && n !== Object.prototype;) {
|
|
@@ -28,78 +223,105 @@ function n(e, t) {
|
|
|
28
223
|
}
|
|
29
224
|
return !1;
|
|
30
225
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
226
|
+
function m(e, t) {
|
|
227
|
+
if (e && p(e, t)) return e[t];
|
|
228
|
+
if (typeof globalThis < "u" && globalThis) {
|
|
229
|
+
if (t === "__proto__" || t === "constructor" || t === "prototype" || t === "__drift_mark_dirty__") return;
|
|
230
|
+
let e = globalThis;
|
|
231
|
+
for (; e && e !== Object.prototype;) {
|
|
232
|
+
if (Object.prototype.hasOwnProperty.call(e, t)) return globalThis[t];
|
|
233
|
+
e = Object.getPrototypeOf(e);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
35
236
|
}
|
|
36
|
-
|
|
37
|
-
|
|
237
|
+
var h = m;
|
|
238
|
+
typeof globalThis < "u" && !globalThis._get && (globalThis._get = m);
|
|
239
|
+
function g(e, t, n) {
|
|
240
|
+
!e || typeof e != "object" || t === "__proto__" || t === "constructor" || t === "prototype" || t === "__drift_mark_dirty__" || (e[t] = n);
|
|
38
241
|
}
|
|
39
|
-
function
|
|
40
|
-
if (e
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
242
|
+
function _(e, t, r, i, a) {
|
|
243
|
+
if (g(e, t, r), i && g(e, i, a), t.startsWith("{") && t.endsWith("}")) {
|
|
244
|
+
let n = r && typeof r == "object" ? r : {}, i = u(t.slice(1, -1));
|
|
245
|
+
for (let t of i) {
|
|
246
|
+
let r = l(t, ":");
|
|
247
|
+
if (r !== -1) {
|
|
248
|
+
let i = t.slice(0, r).trim(), a = t.slice(r + 1).trim(), o = l(a, "=");
|
|
249
|
+
if (o !== -1) {
|
|
250
|
+
let t = a.slice(0, o).trim(), r = a.slice(o + 1).trim(), s = Object.prototype.hasOwnProperty.call(n, i) ? n[i] : void 0;
|
|
251
|
+
g(e, t, s === void 0 ? v(r, e) : s);
|
|
252
|
+
} else a.startsWith("{") || a.startsWith("[") ? _(e, a, Object.prototype.hasOwnProperty.call(n, i) ? n[i] : void 0, null, 0) : g(e, a, Object.prototype.hasOwnProperty.call(n, i) ? n[i] : void 0);
|
|
253
|
+
} else {
|
|
254
|
+
let r = l(t, "=");
|
|
255
|
+
if (r !== -1) {
|
|
256
|
+
let i = t.slice(0, r).trim(), a = t.slice(r + 1).trim(), o = Object.prototype.hasOwnProperty.call(n, i) ? n[i] : void 0;
|
|
257
|
+
g(e, i, o === void 0 ? v(a, e) : o);
|
|
258
|
+
} else g(e, t, Object.prototype.hasOwnProperty.call(n, t) ? n[t] : void 0);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
} else if (t.startsWith("[") && t.endsWith("]")) {
|
|
262
|
+
let i = n(r), a = u(t.slice(1, -1));
|
|
263
|
+
for (let t = 0; t < a.length; t++) {
|
|
264
|
+
let n = a[t], r = l(n, "=");
|
|
265
|
+
if (r !== -1) {
|
|
266
|
+
let a = n.slice(0, r).trim(), o = n.slice(r + 1).trim(), s = i[t];
|
|
267
|
+
g(e, a, s === void 0 ? v(o, e) : s);
|
|
268
|
+
} else n.startsWith("{") || n.startsWith("[") ? _(e, n, i[t], null, 0) : g(e, n, i[t]);
|
|
48
269
|
}
|
|
49
270
|
}
|
|
50
|
-
return e;
|
|
51
|
-
}
|
|
52
|
-
function o(e) {
|
|
53
|
-
return !e || typeof e != "object" ? null : Array.isArray(e.bytecode) || ArrayBuffer.isView(e.bytecode) ? e : e.program && (Array.isArray(e.program.bytecode) || ArrayBuffer.isView(e.program.bytecode)) ? e.program : e.default ? o(e.default) : e.compiledModule ? o(e.compiledModule) : null;
|
|
54
271
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
272
|
+
function v(e, t) {
|
|
273
|
+
let n = e.trim();
|
|
274
|
+
if (n === "true") return !0;
|
|
275
|
+
if (n === "false") return !1;
|
|
276
|
+
if (n === "null") return null;
|
|
277
|
+
if (n !== "undefined") {
|
|
278
|
+
if (n.startsWith("\"") && n.endsWith("\"") || n.startsWith("'") && n.endsWith("'") || n.startsWith("`") && n.endsWith("`")) return n.slice(1, -1);
|
|
279
|
+
if (!Number.isNaN(Number(n)) && n !== "") return Number(n);
|
|
280
|
+
try {
|
|
281
|
+
return JSON.parse(n);
|
|
282
|
+
} catch {
|
|
283
|
+
return t && p(t, n) ? m(t, n) : n;
|
|
284
|
+
}
|
|
62
285
|
}
|
|
63
|
-
return r;
|
|
64
286
|
}
|
|
65
287
|
//#endregion
|
|
66
288
|
//#region src/context.ts
|
|
67
|
-
var
|
|
68
|
-
function
|
|
289
|
+
var y = Symbol.for("__drift_vm_stack__");
|
|
290
|
+
function b() {
|
|
69
291
|
let e = globalThis;
|
|
70
|
-
return e[
|
|
292
|
+
return e[y] || (e[y] = []), e[y];
|
|
71
293
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
294
|
+
function x(e) {
|
|
295
|
+
b().push(e);
|
|
74
296
|
}
|
|
75
|
-
function
|
|
76
|
-
|
|
297
|
+
function S() {
|
|
298
|
+
b().pop();
|
|
77
299
|
}
|
|
78
|
-
function
|
|
79
|
-
let e =
|
|
300
|
+
function C() {
|
|
301
|
+
let e = b();
|
|
80
302
|
return e.length > 0 ? e[e.length - 1] : null;
|
|
81
303
|
}
|
|
82
|
-
function
|
|
304
|
+
function w(e, t) {
|
|
83
305
|
let n = {
|
|
84
306
|
id: Symbol(t || "DriftContext"),
|
|
85
307
|
name: t,
|
|
86
308
|
defaultValue: e,
|
|
87
309
|
provide(e) {
|
|
88
|
-
|
|
310
|
+
T(n, e);
|
|
89
311
|
},
|
|
90
312
|
inject(e) {
|
|
91
|
-
return
|
|
313
|
+
return E(n, e);
|
|
92
314
|
}
|
|
93
315
|
};
|
|
94
316
|
return n;
|
|
95
317
|
}
|
|
96
|
-
function
|
|
97
|
-
let n =
|
|
318
|
+
function T(e, t) {
|
|
319
|
+
let n = C();
|
|
98
320
|
if (!n || !n.contextMap) throw Error("provide() can only be called inside the <script> block of a DriftJS component during instantiation.");
|
|
99
321
|
n.contextMap.set(e.id, t);
|
|
100
322
|
}
|
|
101
|
-
function
|
|
102
|
-
let n =
|
|
323
|
+
function E(e, t) {
|
|
324
|
+
let n = C();
|
|
103
325
|
if (!n) return t === void 0 ? e.defaultValue : t;
|
|
104
326
|
let r = n;
|
|
105
327
|
for (; r;) {
|
|
@@ -108,6 +330,31 @@ function h(e, t) {
|
|
|
108
330
|
}
|
|
109
331
|
return t === void 0 ? e.defaultValue : t;
|
|
110
332
|
}
|
|
111
|
-
var
|
|
333
|
+
var D = T, O = E;
|
|
334
|
+
function k(e) {
|
|
335
|
+
let t = C();
|
|
336
|
+
t ? (t.unmountCallbacks ||= [], t.unmountCallbacks.push(e)) : console.warn("[DriftJS] onUnmount() was called outside a component execution context. Lifecycle hooks must be called synchronously during component setup.");
|
|
337
|
+
}
|
|
338
|
+
//#endregion
|
|
339
|
+
//#region src/style.ts
|
|
340
|
+
var A = /* @__PURE__ */ new Set(/* @__PURE__ */ "animationIterationCount.borderImageOutset.borderImageSlice.borderImageWidth.boxFlex.boxFlexGroup.boxOrdinalGroup.columnCount.columns.flex.flexGrow.flexPositive.flexShrink.flexNegative.flexOrder.gridArea.gridRow.gridRowEnd.gridRowSpan.gridRowStart.gridColumn.gridColumnEnd.gridColumnSpan.gridColumnStart.fontWeight.lineClamp.lineHeight.opacity.order.orphans.tabSize.widows.zIndex.zoom.fillOpacity.floodOpacity.stopOpacity.strokeDasharray.strokeDashoffset.strokeMiterlimit.strokeOpacity.strokeWidth".split("."));
|
|
341
|
+
function j(e) {
|
|
342
|
+
return e.startsWith("--") ? e : e.replace(/[A-Z]/g, (e) => `-${e.toLowerCase()}`);
|
|
343
|
+
}
|
|
344
|
+
function M(e) {
|
|
345
|
+
if (e == null || e === !1 || e === "") return "";
|
|
346
|
+
if (typeof e == "string") return e.trim();
|
|
347
|
+
if (Array.isArray(e)) return e.map((e) => M(e)).filter((e) => !!(e && e.length > 0)).join("; ");
|
|
348
|
+
if (typeof e == "object") {
|
|
349
|
+
let t = [];
|
|
350
|
+
for (let [n, r] of Object.entries(e)) {
|
|
351
|
+
if (r == null || r === !1 || r === "") continue;
|
|
352
|
+
let e = j(n), i = r;
|
|
353
|
+
typeof r == "number" && r !== 0 && !A.has(n) && (i = `${r}px`), t.push(`${e}: ${i}`);
|
|
354
|
+
}
|
|
355
|
+
return t.join("; ");
|
|
356
|
+
}
|
|
357
|
+
return String(e);
|
|
358
|
+
}
|
|
112
359
|
//#endregion
|
|
113
|
-
export { e as MAX_REGISTERS,
|
|
360
|
+
export { e as MAX_REGISTERS, t as VOID_ELEMENTS, h as _get, j as camelToKebab, w as createContext, i as evaluateExpression, o as evaluatePropsSpec, r as executePrecompiledFn, l as findTopLevelChar, C as getActiveVM, m as getScopeValue, d as hasMatchingOuterParens, p as inScopeChain, O as inject, E as injectContext, s as isRegexStartChar, M as normalizeStyle, k as onUnmount, S as popActiveVM, _ as populateItemScope, D as provide, T as provideContext, x as pushActiveVM, a as resolveComponentModule, n as resolveIterable, c as scanBalancedDelimiters, f as setScopeValue, u as splitPatternEntries };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "driftjs-shared",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Shared utilities, Context API, scope resolution helpers, and runtime evaluators for DriftJS.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"driftjs",
|
|
@@ -16,11 +16,15 @@
|
|
|
16
16
|
"dist",
|
|
17
17
|
"README.md"
|
|
18
18
|
],
|
|
19
|
-
"main": "./dist/index-
|
|
19
|
+
"main": "./dist/index-cjs.js",
|
|
20
|
+
"module": "./dist/index-es.js",
|
|
21
|
+
"types": "./src/index.ts",
|
|
20
22
|
"exports": {
|
|
21
23
|
".": {
|
|
24
|
+
"types": "./src/index.ts",
|
|
22
25
|
"import": "./dist/index-es.js",
|
|
23
|
-
"require": "./dist/index-cjs.js"
|
|
26
|
+
"require": "./dist/index-cjs.js",
|
|
27
|
+
"default": "./dist/index-es.js"
|
|
24
28
|
}
|
|
25
29
|
},
|
|
26
30
|
"license": "MIT",
|
package/dist/index-umd.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.DriftUtils={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=256;function n(e,t,n){if(!e||typeof e!=`object`)return;let r=e,i=null,a=new Set;for(;r&&r!==Object.prototype;){if(Object.prototype.hasOwnProperty.call(r,t)){r[t]=n,i=r;break}r=Object.getPrototypeOf(r)}i||=(e[t]=n,e);let o=e;for(;o&&o!==Object.prototype&&(typeof o.__drift_mark_dirty__==`function`&&a.add(o.__drift_mark_dirty__),o!==i);)o=Object.getPrototypeOf(o);for(let e of a)try{e(t)}catch{}}function r(e,t){if(!e||typeof e!=`object`)return!1;let n=e;for(;n&&n!==Object.prototype;){if(Object.prototype.hasOwnProperty.call(n,t))return!0;n=Object.getPrototypeOf(n)}return!1}function i(e){return Array.isArray(e)?e:e&&typeof e[Symbol.iterator]==`function`?Array.from(e):[]}function a(e,t,a){return typeof e==`function`?e(t,a,n,r,i):typeof e.__drift_fn__==`function`?e.__drift_fn__(t,a,n,r,i):(e._executableFn||=typeof e.__drift_fn__==`string`?Function(`return (`+e.__drift_fn__+`)`)():e.__drift_fn__,e._executableFn(t,a,n,r,i))}function o(e,t,s){if(e==null)return e;if(typeof e==`function`)return e(t,s,n,r,i);if(typeof e==`object`&&e){if(`__drift_fn__`in e||typeof e._executableFn==`function`)return a(e,t,s);if(Array.isArray(e)){let n;for(let r of e)n=o(r,t,s);return n}}return e}function s(e){return!e||typeof e!=`object`?null:Array.isArray(e.bytecode)||ArrayBuffer.isView(e.bytecode)?e:e.program&&(Array.isArray(e.program.bytecode)||ArrayBuffer.isView(e.program.bytecode))?e.program:e.default?s(e.default):e.compiledModule?s(e.compiledModule):null}function c(e,t,n){if(!e||typeof e!=`object`)return{};let r={};for(let i of Object.keys(e)){if(i===`__drift_props__`)continue;let a=e[i];r[i]=o(a,t,n)}return r}var l=Symbol.for(`__drift_vm_stack__`);function u(){let e=globalThis;return e[l]||(e[l]=[]),e[l]}function d(e){u().push(e)}function f(){u().pop()}function p(){let e=u();return e.length>0?e[e.length-1]:null}function m(e,t){let n={id:Symbol(t||`DriftContext`),name:t,defaultValue:e,provide(e){h(n,e)},inject(e){return g(n,e)}};return n}function h(e,t){let n=p();if(!n||!n.contextMap)throw Error(`provide() can only be called inside the <script> block of a DriftJS component during instantiation.`);n.contextMap.set(e.id,t)}function g(e,t){let n=p();if(!n)return t===void 0?e.defaultValue:t;let r=n;for(;r;){if(r.contextMap&&r.contextMap.has(e.id))return r.contextMap.get(e.id);r=r.parentVM}return t===void 0?e.defaultValue:t}var _=h,v=g;e.MAX_REGISTERS=t,e.createContext=m,e.evaluateExpression=o,e.evaluatePropsSpec=c,e.executePrecompiledFn=a,e.getActiveVM=p,e.inScopeChain=r,e.inject=v,e.injectContext=g,e.popActiveVM=f,e.provide=_,e.provideContext=h,e.pushActiveVM=d,e.resolveComponentModule=s,e.resolveIterable=i,e.setScopeValue=n});
|