@hanzogui/z-index-stack 2.0.0-rc.41-hanzoai.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 +21 -0
- package/dist/cjs/StackZIndex.cjs +47 -0
- package/dist/cjs/StackZIndex.native.js +51 -0
- package/dist/cjs/StackZIndex.native.js.map +1 -0
- package/dist/cjs/context.cjs +31 -0
- package/dist/cjs/context.native.js +34 -0
- package/dist/cjs/context.native.js.map +1 -0
- package/dist/cjs/index.cjs +22 -0
- package/dist/cjs/index.native.js +25 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/types.cjs +18 -0
- package/dist/cjs/types.native.js +21 -0
- package/dist/cjs/types.native.js.map +1 -0
- package/dist/cjs/useStackedZIndex.cjs +94 -0
- package/dist/cjs/useStackedZIndex.native.js +102 -0
- package/dist/cjs/useStackedZIndex.native.js.map +1 -0
- package/dist/esm/StackZIndex.mjs +22 -0
- package/dist/esm/StackZIndex.mjs.map +1 -0
- package/dist/esm/StackZIndex.native.js +23 -0
- package/dist/esm/StackZIndex.native.js.map +1 -0
- package/dist/esm/context.mjs +5 -0
- package/dist/esm/context.mjs.map +1 -0
- package/dist/esm/context.native.js +5 -0
- package/dist/esm/context.native.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +4 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +4 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/types.mjs +2 -0
- package/dist/esm/types.mjs.map +1 -0
- package/dist/esm/types.native.js +2 -0
- package/dist/esm/types.native.js.map +1 -0
- package/dist/esm/useStackedZIndex.mjs +69 -0
- package/dist/esm/useStackedZIndex.mjs.map +1 -0
- package/dist/esm/useStackedZIndex.native.js +74 -0
- package/dist/esm/useStackedZIndex.native.js.map +1 -0
- package/package.json +45 -0
- package/src/StackZIndex.tsx +28 -0
- package/src/context.ts +7 -0
- package/src/index.ts +4 -0
- package/src/types.ts +16 -0
- package/src/useStackedZIndex.tsx +91 -0
- package/types/StackZIndex.d.ts +5 -0
- package/types/StackZIndex.d.ts.map +1 -0
- package/types/context.d.ts +3 -0
- package/types/context.d.ts.map +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.d.ts.map +1 -0
- package/types/types.d.ts +17 -0
- package/types/types.d.ts.map +1 -0
- package/types/useStackedZIndex.d.ts +6 -0
- package/types/useStackedZIndex.d.ts.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: true
|
|
22
|
+
}), mod);
|
|
23
|
+
var StackZIndex_exports = {};
|
|
24
|
+
__export(StackZIndex_exports, {
|
|
25
|
+
StackZIndexContext: () => StackZIndexContext
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(StackZIndex_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_context = require("./context.cjs");
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
const StackZIndexContext = ({
|
|
32
|
+
children,
|
|
33
|
+
zIndex
|
|
34
|
+
}) => {
|
|
35
|
+
const existing = (0, import_react.useContext)(import_context.ZIndexStackContext);
|
|
36
|
+
let content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.ZIndexStackContext.Provider, {
|
|
37
|
+
value: existing + 1,
|
|
38
|
+
children
|
|
39
|
+
});
|
|
40
|
+
if (typeof zIndex !== "undefined") {
|
|
41
|
+
content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.ZIndexHardcodedContext.Provider, {
|
|
42
|
+
value: zIndex,
|
|
43
|
+
children: content
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return content;
|
|
47
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var StackZIndex_exports = {};
|
|
26
|
+
__export(StackZIndex_exports, {
|
|
27
|
+
StackZIndexContext: () => StackZIndexContext
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(StackZIndex_exports);
|
|
30
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
var import_context = require("./context.native.js");
|
|
33
|
+
var StackZIndexContext = function (param) {
|
|
34
|
+
var {
|
|
35
|
+
children,
|
|
36
|
+
zIndex
|
|
37
|
+
} = param;
|
|
38
|
+
var existing = (0, import_react.useContext)(import_context.ZIndexStackContext);
|
|
39
|
+
var content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.ZIndexStackContext.Provider, {
|
|
40
|
+
value: existing + 1,
|
|
41
|
+
children
|
|
42
|
+
});
|
|
43
|
+
if (typeof zIndex !== "undefined") {
|
|
44
|
+
content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_context.ZIndexHardcodedContext.Provider, {
|
|
45
|
+
value: zIndex,
|
|
46
|
+
children: content
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return content;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=StackZIndex.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","StackZIndex_exports","__export","StackZIndexContext","module","exports","import_jsx_runtime","require","import_react","import_context","param","children","zIndex","existing","useContext","ZIndexStackContext","content","jsx","Provider","ZIndexHardcodedContext"],"sources":["../../src/StackZIndex.tsx"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,mBAAA;AAAAC,QAAA,CAAAD,mBAAA;EAAAE,kBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAA2B,CAAAK,mBAAA;AAC3B,IAAAK,kBAA2D,GAAAC,OAAA;AAYvD,IAAAC,YAAA,GAAAD,OAAA;AAVG,IAAAE,cAAM,GAAAF,OAAsB;AAAA,IACjCJ,kBAAA,YAAAA,CAAAO,KAAA;EACA;IAAAC,QAAA;IAAAC;EAAA,IAAAF,KAAA;EACF,IAGMG,QAAA,OAAAL,YAAA,CAAAM,UAAA,EAAAL,cAAA,CAAAM,kBAAA;EACJ,IAAAC,OAAM,kBAAW,IAAAV,kBAAW,CAAAW,GAAA,EAAAR,cAAA,CAAAM,kBAAkB,CAAAG,QAAA;IAE9ClB,KAAI,EAAAa,QACF;IAKFF;EACE;EAKF,WAAAC,MAAA;IAEAI,OAAO,sBAAAV,kBAAA,CAAAW,GAAA,EAAAR,cAAA,CAAAU,sBAAA,CAAAD,QAAA;MACTlB,KAAA,EAAAY,MAAA","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: true
|
|
22
|
+
}), mod);
|
|
23
|
+
var context_exports = {};
|
|
24
|
+
__export(context_exports, {
|
|
25
|
+
ZIndexHardcodedContext: () => ZIndexHardcodedContext,
|
|
26
|
+
ZIndexStackContext: () => ZIndexStackContext
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(context_exports);
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
const ZIndexStackContext = (0, import_react.createContext)(1);
|
|
31
|
+
const ZIndexHardcodedContext = (0, import_react.createContext)(void 0);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var context_exports = {};
|
|
26
|
+
__export(context_exports, {
|
|
27
|
+
ZIndexHardcodedContext: () => ZIndexHardcodedContext,
|
|
28
|
+
ZIndexStackContext: () => ZIndexStackContext
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(context_exports);
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
var ZIndexStackContext = (0, import_react.createContext)(1);
|
|
33
|
+
var ZIndexHardcodedContext = (0, import_react.createContext)(void 0);
|
|
34
|
+
//# sourceMappingURL=context.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","context_exports","__export","ZIndexHardcodedContext","ZIndexStackContext","module","exports","import_react","require","createContext"],"sources":["../../src/context.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,eAAA;AAAAC,QAAA,CAAAD,eAAA;EAAAE,sBAAA,EAAAA,CAAA,KAAAA,sBAAA;EAAAC,kBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAV,YAA8B,CAAAK,eAAA;AAGvB,IAAAM,YAAM,GAAAC,OAAA,QAAqB;AAG3B,IAAAJ,kBAAM,OAAAG,YAAyB,CAAAE,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
8
|
+
get: () => from[key],
|
|
9
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
16
|
+
value: true
|
|
17
|
+
}), mod);
|
|
18
|
+
var index_exports = {};
|
|
19
|
+
module.exports = __toCommonJS(index_exports);
|
|
20
|
+
__reExport(index_exports, require("./useStackedZIndex.cjs"), module.exports);
|
|
21
|
+
__reExport(index_exports, require("./StackZIndex.cjs"), module.exports);
|
|
22
|
+
__reExport(index_exports, require("./context.cjs"), module.exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
10
|
+
get: () => from[key],
|
|
11
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
17
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
18
|
+
value: true
|
|
19
|
+
}), mod);
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
module.exports = __toCommonJS(index_exports);
|
|
22
|
+
__reExport(index_exports, require("./useStackedZIndex.native.js"), module.exports);
|
|
23
|
+
__reExport(index_exports, require("./StackZIndex.native.js"), module.exports);
|
|
24
|
+
__reExport(index_exports, require("./context.native.js"), module.exports);
|
|
25
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","module","exports","__reExport","require"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAP,YAAc,CAAAK,aAAA;AACdG,UAAA,CAAAH,aAAA,EAAcI,OAAA,+BADd,GAAAH,MAAA,CAAAC,OAAA;AAEAC,UAAA,CAAAH,aAAA,EAAcI,OAAA,0BAFd,GAAAH,MAAA,CAAAC,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
8
|
+
get: () => from[key],
|
|
9
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
}), mod);
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
10
|
+
get: () => from[key],
|
|
11
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
}), mod);
|
|
19
|
+
var types_exports = {};
|
|
20
|
+
module.exports = __toCommonJS(types_exports);
|
|
21
|
+
//# sourceMappingURL=types.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","types_exports"],"sources":["../../src/types.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA","ignoreList":[]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: true
|
|
22
|
+
}), mod);
|
|
23
|
+
var useStackedZIndex_exports = {};
|
|
24
|
+
__export(useStackedZIndex_exports, {
|
|
25
|
+
useStackedZIndex: () => useStackedZIndex
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(useStackedZIndex_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_context = require("./context.cjs");
|
|
30
|
+
const ZIndicesByContext = {};
|
|
31
|
+
const CurrentPortalZIndices = {};
|
|
32
|
+
const useStackedZIndex = props => {
|
|
33
|
+
if (process.env.TAMAGUI_STACK_Z_INDEX_GLOBAL) {
|
|
34
|
+
const {
|
|
35
|
+
stackZIndex,
|
|
36
|
+
zIndex: zIndexProp
|
|
37
|
+
} = props;
|
|
38
|
+
const id = (0, import_react.useId)();
|
|
39
|
+
const zIndex = (0, import_react.useMemo)(() => {
|
|
40
|
+
if (stackZIndex && stackZIndex !== "global" && zIndexProp === void 0) {
|
|
41
|
+
const highest = Object.values(CurrentPortalZIndices).reduce((acc, cur) => Math.max(acc, cur), 0);
|
|
42
|
+
return Math.max(stackZIndex === true ? 1 : stackZIndex, highest + 1);
|
|
43
|
+
}
|
|
44
|
+
return zIndexProp ?? 1e3;
|
|
45
|
+
}, [stackZIndex]);
|
|
46
|
+
(0, import_react.useEffect)(() => {
|
|
47
|
+
if (typeof stackZIndex === "number") {
|
|
48
|
+
CurrentPortalZIndices[id] = stackZIndex;
|
|
49
|
+
return () => {
|
|
50
|
+
delete CurrentPortalZIndices[id];
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}, [stackZIndex]);
|
|
54
|
+
return zIndex;
|
|
55
|
+
} else {
|
|
56
|
+
const {
|
|
57
|
+
stackZIndex,
|
|
58
|
+
zIndex: zIndexProp
|
|
59
|
+
} = props;
|
|
60
|
+
const id = (0, import_react.useId)();
|
|
61
|
+
const stackingContextLevel = (0, import_react.useContext)(import_context.ZIndexStackContext);
|
|
62
|
+
const stackLayer = stackZIndex === "global" ? 0 : stackingContextLevel;
|
|
63
|
+
const hardcoded = (0, import_react.useContext)(import_context.ZIndexHardcodedContext);
|
|
64
|
+
ZIndicesByContext[stackLayer] ||= {};
|
|
65
|
+
const stackContext = ZIndicesByContext[stackLayer];
|
|
66
|
+
const zIndex = (0, import_react.useMemo)(() => {
|
|
67
|
+
if (typeof zIndexProp === "number") {
|
|
68
|
+
return zIndexProp;
|
|
69
|
+
}
|
|
70
|
+
if (stackZIndex) {
|
|
71
|
+
if (hardcoded) {
|
|
72
|
+
return hardcoded + 1;
|
|
73
|
+
}
|
|
74
|
+
const entries = Object.values(stackContext);
|
|
75
|
+
const baseForLayer = stackLayer * 5e3;
|
|
76
|
+
const nextLayerBase = (stackLayer + 1) * 5e3;
|
|
77
|
+
const validEntries = entries.filter(z => z < nextLayerBase);
|
|
78
|
+
const highest = validEntries.length > 0 ? Math.max(...validEntries) : baseForLayer;
|
|
79
|
+
const nextZIndex = highest === baseForLayer ? baseForLayer + 1 : highest + 1;
|
|
80
|
+
return typeof stackZIndex === "number" ? stackZIndex + nextZIndex : nextZIndex;
|
|
81
|
+
}
|
|
82
|
+
return 1;
|
|
83
|
+
}, [stackLayer, zIndexProp, stackZIndex]);
|
|
84
|
+
(0, import_react.useEffect)(() => {
|
|
85
|
+
if (stackZIndex) {
|
|
86
|
+
stackContext[id] = zIndex;
|
|
87
|
+
return () => {
|
|
88
|
+
delete stackContext[id];
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}, [zIndex]);
|
|
92
|
+
return zIndex;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var useStackedZIndex_exports = {};
|
|
26
|
+
__export(useStackedZIndex_exports, {
|
|
27
|
+
useStackedZIndex: () => useStackedZIndex
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(useStackedZIndex_exports);
|
|
30
|
+
var import_react = require("react");
|
|
31
|
+
var import_context = require("./context.native.js");
|
|
32
|
+
var ZIndicesByContext = {};
|
|
33
|
+
var CurrentPortalZIndices = {};
|
|
34
|
+
var useStackedZIndex = function (props) {
|
|
35
|
+
if (process.env.TAMAGUI_STACK_Z_INDEX_GLOBAL) {
|
|
36
|
+
var {
|
|
37
|
+
stackZIndex,
|
|
38
|
+
zIndex: zIndexProp
|
|
39
|
+
} = props;
|
|
40
|
+
var id = (0, import_react.useId)();
|
|
41
|
+
var zIndex = (0, import_react.useMemo)(function () {
|
|
42
|
+
if (stackZIndex && stackZIndex !== "global" && zIndexProp === void 0) {
|
|
43
|
+
var highest = Object.values(CurrentPortalZIndices).reduce(function (acc, cur) {
|
|
44
|
+
return Math.max(acc, cur);
|
|
45
|
+
}, 0);
|
|
46
|
+
return Math.max(stackZIndex === true ? 1 : stackZIndex, highest + 1);
|
|
47
|
+
}
|
|
48
|
+
return zIndexProp !== null && zIndexProp !== void 0 ? zIndexProp : 1e3;
|
|
49
|
+
}, [stackZIndex]);
|
|
50
|
+
(0, import_react.useEffect)(function () {
|
|
51
|
+
if (typeof stackZIndex === "number") {
|
|
52
|
+
CurrentPortalZIndices[id] = stackZIndex;
|
|
53
|
+
return function () {
|
|
54
|
+
delete CurrentPortalZIndices[id];
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}, [stackZIndex]);
|
|
58
|
+
return zIndex;
|
|
59
|
+
} else {
|
|
60
|
+
var _ZIndicesByContext, _stackLayer;
|
|
61
|
+
var {
|
|
62
|
+
stackZIndex: stackZIndex1,
|
|
63
|
+
zIndex: zIndexProp1
|
|
64
|
+
} = props;
|
|
65
|
+
var id1 = (0, import_react.useId)();
|
|
66
|
+
var stackingContextLevel = (0, import_react.useContext)(import_context.ZIndexStackContext);
|
|
67
|
+
var stackLayer = stackZIndex1 === "global" ? 0 : stackingContextLevel;
|
|
68
|
+
var hardcoded = (0, import_react.useContext)(import_context.ZIndexHardcodedContext);
|
|
69
|
+
(_ZIndicesByContext = ZIndicesByContext)[_stackLayer = stackLayer] || (_ZIndicesByContext[_stackLayer] = {});
|
|
70
|
+
var stackContext = ZIndicesByContext[stackLayer];
|
|
71
|
+
var zIndex1 = (0, import_react.useMemo)(function () {
|
|
72
|
+
if (typeof zIndexProp1 === "number") {
|
|
73
|
+
return zIndexProp1;
|
|
74
|
+
}
|
|
75
|
+
if (stackZIndex1) {
|
|
76
|
+
if (hardcoded) {
|
|
77
|
+
return hardcoded + 1;
|
|
78
|
+
}
|
|
79
|
+
var entries = Object.values(stackContext);
|
|
80
|
+
var baseForLayer = stackLayer * 5e3;
|
|
81
|
+
var nextLayerBase = (stackLayer + 1) * 5e3;
|
|
82
|
+
var validEntries = entries.filter(function (z) {
|
|
83
|
+
return z < nextLayerBase;
|
|
84
|
+
});
|
|
85
|
+
var highest = validEntries.length > 0 ? Math.max(...validEntries) : baseForLayer;
|
|
86
|
+
var nextZIndex = highest === baseForLayer ? baseForLayer + 1 : highest + 1;
|
|
87
|
+
return typeof stackZIndex1 === "number" ? stackZIndex1 + nextZIndex : nextZIndex;
|
|
88
|
+
}
|
|
89
|
+
return 1;
|
|
90
|
+
}, [stackLayer, zIndexProp1, stackZIndex1]);
|
|
91
|
+
(0, import_react.useEffect)(function () {
|
|
92
|
+
if (stackZIndex1) {
|
|
93
|
+
stackContext[id1] = zIndex1;
|
|
94
|
+
return function () {
|
|
95
|
+
delete stackContext[id1];
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}, [zIndex1]);
|
|
99
|
+
return zIndex1;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=useStackedZIndex.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useStackedZIndex_exports","__export","useStackedZIndex","module","exports","import_react","require","import_context","ZIndicesByContext","CurrentPortalZIndices","props","process","env","TAMAGUI_STACK_Z_INDEX_GLOBAL","stackZIndex","zIndex","zIndexProp","id","useId","useMemo","highest","Object","values","reduce","acc","cur","Math","max","useEffect","_ZIndicesByContext","_stackLayer","stackZIndex1","zIndexProp1","id1","stackingContextLevel","useContext","ZIndexStackContext","stackLayer","hardcoded","ZIndexHardcodedContext","stackContext","zIndex1","entries","baseForLayer","nextLayerBase","validEntries","filter","z","length","nextZIndex"],"sources":["../../src/useStackedZIndex.tsx"],"sourcesContent":[null],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useContext } from "react";
|
|
2
|
+
import { ZIndexHardcodedContext, ZIndexStackContext } from "./context.mjs";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
const StackZIndexContext = ({
|
|
5
|
+
children,
|
|
6
|
+
zIndex
|
|
7
|
+
}) => {
|
|
8
|
+
const existing = useContext(ZIndexStackContext);
|
|
9
|
+
let content = /* @__PURE__ */jsx(ZIndexStackContext.Provider, {
|
|
10
|
+
value: existing + 1,
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
if (typeof zIndex !== "undefined") {
|
|
14
|
+
content = /* @__PURE__ */jsx(ZIndexHardcodedContext.Provider, {
|
|
15
|
+
value: zIndex,
|
|
16
|
+
children: content
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return content;
|
|
20
|
+
};
|
|
21
|
+
export { StackZIndexContext };
|
|
22
|
+
//# sourceMappingURL=StackZIndex.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useContext","ZIndexHardcodedContext","ZIndexStackContext","jsx","StackZIndexContext","children","zIndex","existing","content","Provider","value"],"sources":["../../src/StackZIndex.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAC3B,SAASC,sBAAA,EAAwBC,kBAAA,QAA0B;AAYvD,SAAAC,GAAA;AAVG,MAAMC,kBAAA,GAAqBA,CAAC;EACjCC,QAAA;EACAC;AACF,MAGM;EACJ,MAAMC,QAAA,GAAWP,UAAA,CAAWE,kBAAkB;EAE9C,IAAIM,OAAA,GACF,eAAAL,GAAA,CAACD,kBAAA,CAAmBO,QAAA,EAAnB;IAA4BC,KAAA,EAAOH,QAAA,GAAW;IAC5CF;EAAA,CACH;EAGF,IAAI,OAAOC,MAAA,KAAW,aAAa;IACjCE,OAAA,GACE,eAAAL,GAAA,CAACF,sBAAA,CAAuBQ,QAAA,EAAvB;MAAgCC,KAAA,EAAOJ,MAAA;MACrCD,QAAA,EAAAG;IAAA,CACH;EAEJ;EAEA,OAAOA,OAAA;AACT","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useContext } from "react";
|
|
3
|
+
import { ZIndexHardcodedContext, ZIndexStackContext } from "./context.native.js";
|
|
4
|
+
var StackZIndexContext = function (param) {
|
|
5
|
+
var {
|
|
6
|
+
children,
|
|
7
|
+
zIndex
|
|
8
|
+
} = param;
|
|
9
|
+
var existing = useContext(ZIndexStackContext);
|
|
10
|
+
var content = /* @__PURE__ */_jsx(ZIndexStackContext.Provider, {
|
|
11
|
+
value: existing + 1,
|
|
12
|
+
children
|
|
13
|
+
});
|
|
14
|
+
if (typeof zIndex !== "undefined") {
|
|
15
|
+
content = /* @__PURE__ */_jsx(ZIndexHardcodedContext.Provider, {
|
|
16
|
+
value: zIndex,
|
|
17
|
+
children: content
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return content;
|
|
21
|
+
};
|
|
22
|
+
export { StackZIndexContext };
|
|
23
|
+
//# sourceMappingURL=StackZIndex.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["jsx","_jsx","useContext","ZIndexHardcodedContext","ZIndexStackContext","StackZIndexContext","param","children","zIndex","existing","content","Provider","value"],"sources":["../../src/StackZIndex.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,GAAA,IAAAC,IAAA,QAAkB;AAC3B,SAASC,UAAA,eAAwB;AAY7B,SAAAC,sBAAA,EAAAC,kBAAA;AAVG,IAAAC,kBAAM,YAAAA,CAAsBC,KAAA;EACjC;IAAAC,QAAA;IAAAC;EAAA,IAAAF,KAAA;EACA,IAAAG,QAAA,GAAAP,UAAA,CAAAE,kBAAA;EACF,IAGMM,OAAA,kBAAAT,IAAA,CAAAG,kBAAA,CAAAO,QAAA;IACJC,KAAM,EAAAH,QAAW;IAEjBF;EAMA;EACE,WAAAC,MACE,gBAAC;IAILE,OAAA,kBAAAT,IAAA,CAAAE,sBAAA,CAAAQ,QAAA;MAEAC,KAAO,EAAAJ,MAAA;MACTD,QAAA,EAAAG","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","ZIndexStackContext","ZIndexHardcodedContext"],"sources":["../../src/context.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,aAAA,QAAqB;AAGvB,MAAMC,kBAAA,GAAqBD,aAAA,CAAc,CAAC;AAG1C,MAAME,sBAAA,GAAyBF,aAAA,CAAkC,MAAS","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["createContext","ZIndexStackContext","ZIndexHardcodedContext"],"sources":["../../src/context.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,aAAA,QAAqB;AAGvB,IAAAC,kBAAM,GAAAD,aAAqB,GAAc;AAGzC,IAAAE,sBAAM,GAAAF,aAAyB,MAAkC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":[],"sourcesContent":[],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useContext, useEffect, useId, useMemo } from "react";
|
|
2
|
+
import { ZIndexHardcodedContext, ZIndexStackContext } from "./context.mjs";
|
|
3
|
+
const ZIndicesByContext = {};
|
|
4
|
+
const CurrentPortalZIndices = {};
|
|
5
|
+
const useStackedZIndex = props => {
|
|
6
|
+
if (process.env.TAMAGUI_STACK_Z_INDEX_GLOBAL) {
|
|
7
|
+
const {
|
|
8
|
+
stackZIndex,
|
|
9
|
+
zIndex: zIndexProp
|
|
10
|
+
} = props;
|
|
11
|
+
const id = useId();
|
|
12
|
+
const zIndex = useMemo(() => {
|
|
13
|
+
if (stackZIndex && stackZIndex !== "global" && zIndexProp === void 0) {
|
|
14
|
+
const highest = Object.values(CurrentPortalZIndices).reduce((acc, cur) => Math.max(acc, cur), 0);
|
|
15
|
+
return Math.max(stackZIndex === true ? 1 : stackZIndex, highest + 1);
|
|
16
|
+
}
|
|
17
|
+
return zIndexProp ?? 1e3;
|
|
18
|
+
}, [stackZIndex]);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (typeof stackZIndex === "number") {
|
|
21
|
+
CurrentPortalZIndices[id] = stackZIndex;
|
|
22
|
+
return () => {
|
|
23
|
+
delete CurrentPortalZIndices[id];
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}, [stackZIndex]);
|
|
27
|
+
return zIndex;
|
|
28
|
+
} else {
|
|
29
|
+
const {
|
|
30
|
+
stackZIndex,
|
|
31
|
+
zIndex: zIndexProp
|
|
32
|
+
} = props;
|
|
33
|
+
const id = useId();
|
|
34
|
+
const stackingContextLevel = useContext(ZIndexStackContext);
|
|
35
|
+
const stackLayer = stackZIndex === "global" ? 0 : stackingContextLevel;
|
|
36
|
+
const hardcoded = useContext(ZIndexHardcodedContext);
|
|
37
|
+
ZIndicesByContext[stackLayer] ||= {};
|
|
38
|
+
const stackContext = ZIndicesByContext[stackLayer];
|
|
39
|
+
const zIndex = useMemo(() => {
|
|
40
|
+
if (typeof zIndexProp === "number") {
|
|
41
|
+
return zIndexProp;
|
|
42
|
+
}
|
|
43
|
+
if (stackZIndex) {
|
|
44
|
+
if (hardcoded) {
|
|
45
|
+
return hardcoded + 1;
|
|
46
|
+
}
|
|
47
|
+
const entries = Object.values(stackContext);
|
|
48
|
+
const baseForLayer = stackLayer * 5e3;
|
|
49
|
+
const nextLayerBase = (stackLayer + 1) * 5e3;
|
|
50
|
+
const validEntries = entries.filter(z => z < nextLayerBase);
|
|
51
|
+
const highest = validEntries.length > 0 ? Math.max(...validEntries) : baseForLayer;
|
|
52
|
+
const nextZIndex = highest === baseForLayer ? baseForLayer + 1 : highest + 1;
|
|
53
|
+
return typeof stackZIndex === "number" ? stackZIndex + nextZIndex : nextZIndex;
|
|
54
|
+
}
|
|
55
|
+
return 1;
|
|
56
|
+
}, [stackLayer, zIndexProp, stackZIndex]);
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (stackZIndex) {
|
|
59
|
+
stackContext[id] = zIndex;
|
|
60
|
+
return () => {
|
|
61
|
+
delete stackContext[id];
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}, [zIndex]);
|
|
65
|
+
return zIndex;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
export { useStackedZIndex };
|
|
69
|
+
//# sourceMappingURL=useStackedZIndex.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useContext","useEffect","useId","useMemo","ZIndexHardcodedContext","ZIndexStackContext","ZIndicesByContext","CurrentPortalZIndices","useStackedZIndex","props","process","env","TAMAGUI_STACK_Z_INDEX_GLOBAL","stackZIndex","zIndex","zIndexProp","id","highest","Object","values","reduce","acc","cur","Math","max","stackingContextLevel","stackLayer","hardcoded","stackContext","entries","baseForLayer","nextLayerBase","validEntries","filter","z","length","nextZIndex"],"sources":["../../src/useStackedZIndex.tsx"],"sourcesContent":[null],"mappings":"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","ignoreList":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { useContext, useEffect, useId, useMemo } from "react";
|
|
2
|
+
import { ZIndexHardcodedContext, ZIndexStackContext } from "./context.native.js";
|
|
3
|
+
var ZIndicesByContext = {};
|
|
4
|
+
var CurrentPortalZIndices = {};
|
|
5
|
+
var useStackedZIndex = function (props) {
|
|
6
|
+
if (process.env.TAMAGUI_STACK_Z_INDEX_GLOBAL) {
|
|
7
|
+
var {
|
|
8
|
+
stackZIndex,
|
|
9
|
+
zIndex: zIndexProp
|
|
10
|
+
} = props;
|
|
11
|
+
var id = useId();
|
|
12
|
+
var zIndex = useMemo(function () {
|
|
13
|
+
if (stackZIndex && stackZIndex !== "global" && zIndexProp === void 0) {
|
|
14
|
+
var highest = Object.values(CurrentPortalZIndices).reduce(function (acc, cur) {
|
|
15
|
+
return Math.max(acc, cur);
|
|
16
|
+
}, 0);
|
|
17
|
+
return Math.max(stackZIndex === true ? 1 : stackZIndex, highest + 1);
|
|
18
|
+
}
|
|
19
|
+
return zIndexProp !== null && zIndexProp !== void 0 ? zIndexProp : 1e3;
|
|
20
|
+
}, [stackZIndex]);
|
|
21
|
+
useEffect(function () {
|
|
22
|
+
if (typeof stackZIndex === "number") {
|
|
23
|
+
CurrentPortalZIndices[id] = stackZIndex;
|
|
24
|
+
return function () {
|
|
25
|
+
delete CurrentPortalZIndices[id];
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}, [stackZIndex]);
|
|
29
|
+
return zIndex;
|
|
30
|
+
} else {
|
|
31
|
+
var _ZIndicesByContext, _stackLayer;
|
|
32
|
+
var {
|
|
33
|
+
stackZIndex: stackZIndex1,
|
|
34
|
+
zIndex: zIndexProp1
|
|
35
|
+
} = props;
|
|
36
|
+
var id1 = useId();
|
|
37
|
+
var stackingContextLevel = useContext(ZIndexStackContext);
|
|
38
|
+
var stackLayer = stackZIndex1 === "global" ? 0 : stackingContextLevel;
|
|
39
|
+
var hardcoded = useContext(ZIndexHardcodedContext);
|
|
40
|
+
(_ZIndicesByContext = ZIndicesByContext)[_stackLayer = stackLayer] || (_ZIndicesByContext[_stackLayer] = {});
|
|
41
|
+
var stackContext = ZIndicesByContext[stackLayer];
|
|
42
|
+
var zIndex1 = useMemo(function () {
|
|
43
|
+
if (typeof zIndexProp1 === "number") {
|
|
44
|
+
return zIndexProp1;
|
|
45
|
+
}
|
|
46
|
+
if (stackZIndex1) {
|
|
47
|
+
if (hardcoded) {
|
|
48
|
+
return hardcoded + 1;
|
|
49
|
+
}
|
|
50
|
+
var entries = Object.values(stackContext);
|
|
51
|
+
var baseForLayer = stackLayer * 5e3;
|
|
52
|
+
var nextLayerBase = (stackLayer + 1) * 5e3;
|
|
53
|
+
var validEntries = entries.filter(function (z) {
|
|
54
|
+
return z < nextLayerBase;
|
|
55
|
+
});
|
|
56
|
+
var highest = validEntries.length > 0 ? Math.max(...validEntries) : baseForLayer;
|
|
57
|
+
var nextZIndex = highest === baseForLayer ? baseForLayer + 1 : highest + 1;
|
|
58
|
+
return typeof stackZIndex1 === "number" ? stackZIndex1 + nextZIndex : nextZIndex;
|
|
59
|
+
}
|
|
60
|
+
return 1;
|
|
61
|
+
}, [stackLayer, zIndexProp1, stackZIndex1]);
|
|
62
|
+
useEffect(function () {
|
|
63
|
+
if (stackZIndex1) {
|
|
64
|
+
stackContext[id1] = zIndex1;
|
|
65
|
+
return function () {
|
|
66
|
+
delete stackContext[id1];
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}, [zIndex1]);
|
|
70
|
+
return zIndex1;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
export { useStackedZIndex };
|
|
74
|
+
//# sourceMappingURL=useStackedZIndex.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useContext","useEffect","useId","useMemo","ZIndexHardcodedContext","ZIndexStackContext","ZIndicesByContext","CurrentPortalZIndices","useStackedZIndex","props","process","env","TAMAGUI_STACK_Z_INDEX_GLOBAL","stackZIndex","zIndex","zIndexProp","id","highest","Object","values","reduce","acc","cur","Math","max","_ZIndicesByContext","_stackLayer","stackZIndex1","zIndexProp1","id1","stackingContextLevel","stackLayer","hardcoded","stackContext","zIndex1","entries","baseForLayer","nextLayerBase","validEntries","filter","z","length","nextZIndex"],"sources":["../../src/useStackedZIndex.tsx"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,EAAYC,SAAA,EAAWC,KAAA,EAAOC,OAAA,QAAe;AACtD,SAASC,sBAAA,EAAwBC,kBAAA,QAA0B;AAI3D,IAAAC,iBAAM,KAA4D;AAGlE,IAAAC,qBAAM,KAAgD;AAE/C,IAAAC,gBAAM,YAAAA,CAAoBC,KAG3B;EACJ,IAAIC,OAAA,CAAQC,GAAA,CAAIC,4BAAA,EAA8B;IAC5C;MAAMC,WAAE;MAAAC,MAAa,EAAAC;IAAQ,IAAWN,KAAI;IAC5C,IAAAO,EAAM,GAAAd,KAAK;IAEX,IAAAY,MAAM,GAAAX,OAAS,aAAc;MAC3B,IAAIU,WAAA,IAAeA,WAAA,KAAgB,YAAYE,UAAA,KAAe,QAAW;QACvE,IAAAE,OAAM,GAAAC,MAAU,CAAAC,MAAO,CAAAZ,qBAAO,EAAqBa,MAAE,WAAAC,GAAA,EAAAC,GAAA;UACnD,OAAMC,IAAA,CAAAC,GAAQ,CAAAH,GAAK,EAAAC,GAAI;QAAQ,GAC/B;QACF,OAAAC,IAAA,CAAAC,GAAA,CAAAX,WAAA,gBAAAA,WAAA,EAAAI,OAAA;MACA;MACF,OAAAF,UAAA,aAAAA,UAAA,cAAAA,UAAA;IACA,IACFF,WAAI,CAEJ;IACEZ,SAAI,aAAO;MACT,WAAAY,WAAA,KAAwB,QAAI;QAC5BN,qBAAa,CAAAS,EAAA,IAAAH,WAAA;QACX,mBAAO;UACT,OAAAN,qBAAA,CAAAS,EAAA;QACF;MACF;IAEA,IACFH,WAAO,CACL;IACA,OAAMC,MAAK;EACX;IACA,IAAAW,kBAAmB,EAAAC,WAAgB;IACnC;MAAMb,WAAA,EAAYc,YAAW;MAAAb,MAAA,EAAAc;IAAsB,IAAAnB,KAAA;IAEnD,IAAAoB,GAAA,GAAA3B,KAAA;IACA,IAAA4B,oBAAqB,GAAA9B,UAAA,CAAAK,kBAA4B;IAEjD,IAAA0B,UAAM,GAASJ,YAAc,oBAAAG,oBAAA;IAC3B,IAAAE,SAAW,GAAAhC,UAAA,CAAAI,sBAAyB;IAClC,CAAAqB,kBAAO,GAAAnB,iBAAA,EAAAoB,WAAA,GAAAK,UAAA,MAAAN,kBAAA,CAAAC,WAAA;IAAA,IACTO,YAAA,GAAA3B,iBAAA,CAAAyB,UAAA;IAEA,IAAAG,OAAI,GAAA/B,OAAa;MACf,WAAIyB,WAAW;QACb,OAAAA,WAAO;MAAY;MAGrB,IAAAD,YAAM,EAAU;QAChB,IAAAK,SAAM;UACN,OAAMA,SAAA;QAIN;QAEA,IAAAG,OAAM,GAAAjB,MAAU,CAAAC,MAAA,CAAAc,YAAsB;QAGtC,IAAAG,YAAM,GAAaL,UAAA,GAAY;QAG/B,IAAAM,aAAc,IAAAN,UAAgB,WAAW;QAC3C,IAAAO,YAAA,GAAAH,OAAA,CAAAI,MAAA,WAAAC,CAAA;UAEA,OAAOA,CAAA,GAAAH,aAAA;QACL;QAEJ,IAAApB,OAAU,GAAMqB,YAAA,CAAAG,MAAA,OAAAlB,IAAA,CAAAC,GAAA,IAAAc,YAAA,IAAAF,YAAA;QACd,IAAIM,UAAA,GAAazB,OAAA,KAAAmB,YAAA,GAAAA,YAAA,OAAAnB,OAAA;QACf,cAAaU,YAAM,gBAAAA,YAAA,GAAAe,UAAA,GAAAA,UAAA;MACnB;MACE;IAAsB,IAE1BX,UAAA,EACFH,WAAW,EAEXD,YAAO,CACT;IACF1B,SAAA","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hanzogui/z-index-stack",
|
|
3
|
+
"version": "2.0.0-rc.41-hanzoai.1",
|
|
4
|
+
"source": "src/index.ts",
|
|
5
|
+
"files": [
|
|
6
|
+
"src",
|
|
7
|
+
"types",
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": [
|
|
12
|
+
"*.css"
|
|
13
|
+
],
|
|
14
|
+
"main": "dist/cjs",
|
|
15
|
+
"module": "dist/esm",
|
|
16
|
+
"types": "./types/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
"./package.json": "./package.json",
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./types/index.d.ts",
|
|
21
|
+
"react-native": "./dist/esm/index.native.js",
|
|
22
|
+
"browser": "./dist/esm/index.mjs",
|
|
23
|
+
"module": "./dist/esm/index.mjs",
|
|
24
|
+
"import": "./dist/esm/index.mjs",
|
|
25
|
+
"require": "./dist/cjs/index.cjs",
|
|
26
|
+
"default": "./dist/esm/index.mjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "hanzogui-build",
|
|
34
|
+
"watch": "hanzogui-build --watch",
|
|
35
|
+
"clean": "hanzogui-build clean",
|
|
36
|
+
"clean:build": "hanzogui-build clean:build"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@hanzogui/build": "2.0.0-rc.41-hanzoai.1",
|
|
40
|
+
"react": ">=19"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"react": ">=19"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useContext } from 'react'
|
|
2
|
+
import { ZIndexHardcodedContext, ZIndexStackContext } from './context'
|
|
3
|
+
|
|
4
|
+
export const StackZIndexContext = ({
|
|
5
|
+
children,
|
|
6
|
+
zIndex,
|
|
7
|
+
}: {
|
|
8
|
+
children: React.ReactNode
|
|
9
|
+
zIndex?: number
|
|
10
|
+
}) => {
|
|
11
|
+
const existing = useContext(ZIndexStackContext)
|
|
12
|
+
|
|
13
|
+
let content = (
|
|
14
|
+
<ZIndexStackContext.Provider value={existing + 1}>
|
|
15
|
+
{children}
|
|
16
|
+
</ZIndexStackContext.Provider>
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
if (typeof zIndex !== 'undefined') {
|
|
20
|
+
content = (
|
|
21
|
+
<ZIndexHardcodedContext.Provider value={zIndex}>
|
|
22
|
+
{content}
|
|
23
|
+
</ZIndexHardcodedContext.Provider>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return content
|
|
28
|
+
}
|
package/src/context.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createContext } from 'react'
|
|
2
|
+
|
|
3
|
+
// stacks vertically through tree, based on nesting
|
|
4
|
+
export const ZIndexStackContext = createContext(1)
|
|
5
|
+
|
|
6
|
+
// if setting to overriden z index
|
|
7
|
+
export const ZIndexHardcodedContext = createContext<number | undefined>(undefined)
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hanzogui will attempt to stack z-index in a smart way when true, it does this
|
|
3
|
+
* by automatically increasing z-index both horizontally and vertically in the component tree.
|
|
4
|
+
*
|
|
5
|
+
* Basically - if two stackable items are at the same level, then the order of mounting
|
|
6
|
+
* determines their z-index (later is higher). This is the horizontal logic.
|
|
7
|
+
*
|
|
8
|
+
* Below a stackable item, the z-index will always be above that specific item, but below
|
|
9
|
+
* other horizontal items that come after it.
|
|
10
|
+
*
|
|
11
|
+
* - false will avoid the stacking behavior.
|
|
12
|
+
* - number will keep the behavior, but add to the stacked z-index the given amount
|
|
13
|
+
* - 'global' will not stack things vertically and instead only stack them horizontally
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export type StackZIndexProp = boolean | number | 'global'
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useContext, useEffect, useId, useMemo } from 'react'
|
|
2
|
+
import { ZIndexHardcodedContext, ZIndexStackContext } from './context'
|
|
3
|
+
import type { StackZIndexProp } from './types'
|
|
4
|
+
|
|
5
|
+
// this stacks horizontally - just based on which mounted last within a stacking context
|
|
6
|
+
const ZIndicesByContext: Record<number, Record<string, number>> = {}
|
|
7
|
+
|
|
8
|
+
// old stacking style
|
|
9
|
+
const CurrentPortalZIndices: Record<string, number> = {}
|
|
10
|
+
|
|
11
|
+
export const useStackedZIndex = (props: {
|
|
12
|
+
zIndex?: number
|
|
13
|
+
stackZIndex?: StackZIndexProp
|
|
14
|
+
}) => {
|
|
15
|
+
if (process.env.TAMAGUI_STACK_Z_INDEX_GLOBAL) {
|
|
16
|
+
const { stackZIndex, zIndex: zIndexProp } = props
|
|
17
|
+
const id = useId()
|
|
18
|
+
|
|
19
|
+
const zIndex = useMemo(() => {
|
|
20
|
+
if (stackZIndex && stackZIndex !== 'global' && zIndexProp === undefined) {
|
|
21
|
+
const highest = Object.values(CurrentPortalZIndices).reduce(
|
|
22
|
+
(acc, cur) => Math.max(acc, cur),
|
|
23
|
+
0
|
|
24
|
+
)
|
|
25
|
+
return Math.max(stackZIndex === true ? 1 : stackZIndex, highest + 1)
|
|
26
|
+
}
|
|
27
|
+
return zIndexProp ?? 1000
|
|
28
|
+
}, [stackZIndex])
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (typeof stackZIndex === 'number') {
|
|
32
|
+
CurrentPortalZIndices[id] = stackZIndex
|
|
33
|
+
return () => {
|
|
34
|
+
delete CurrentPortalZIndices[id]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, [stackZIndex])
|
|
38
|
+
|
|
39
|
+
return zIndex
|
|
40
|
+
} else {
|
|
41
|
+
const { stackZIndex, zIndex: zIndexProp } = props
|
|
42
|
+
const id = useId()
|
|
43
|
+
const stackingContextLevel = useContext(ZIndexStackContext)
|
|
44
|
+
const stackLayer = stackZIndex === 'global' ? 0 : stackingContextLevel
|
|
45
|
+
const hardcoded = useContext(ZIndexHardcodedContext)
|
|
46
|
+
|
|
47
|
+
ZIndicesByContext[stackLayer] ||= {}
|
|
48
|
+
const stackContext = ZIndicesByContext[stackLayer]
|
|
49
|
+
|
|
50
|
+
const zIndex = useMemo(() => {
|
|
51
|
+
if (typeof zIndexProp === 'number') {
|
|
52
|
+
return zIndexProp
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (stackZIndex) {
|
|
56
|
+
if (hardcoded) {
|
|
57
|
+
return hardcoded + 1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const entries = Object.values(stackContext)
|
|
61
|
+
const baseForLayer = stackLayer * 5000
|
|
62
|
+
const nextLayerBase = (stackLayer + 1) * 5000
|
|
63
|
+
|
|
64
|
+
// Filter out values that belong to higher layers
|
|
65
|
+
// Any value >= next layer's base is definitely not from this layer
|
|
66
|
+
const validEntries = entries.filter((z) => z < nextLayerBase)
|
|
67
|
+
|
|
68
|
+
const highest = validEntries.length > 0 ? Math.max(...validEntries) : baseForLayer
|
|
69
|
+
|
|
70
|
+
// If we only have the base value or nothing, start fresh
|
|
71
|
+
const nextZIndex = highest === baseForLayer ? baseForLayer + 1 : highest + 1
|
|
72
|
+
|
|
73
|
+
// setting stackZIndex to a number lets you increase it further
|
|
74
|
+
return typeof stackZIndex === 'number' ? stackZIndex + nextZIndex : nextZIndex
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return 1
|
|
78
|
+
}, [stackLayer, zIndexProp, stackZIndex])
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (stackZIndex) {
|
|
82
|
+
stackContext[id] = zIndex
|
|
83
|
+
return () => {
|
|
84
|
+
delete stackContext[id]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}, [zIndex])
|
|
88
|
+
|
|
89
|
+
return zIndex
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StackZIndex.d.ts","sourceRoot":"","sources":["../src/StackZIndex.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,GAAI,uBAGhC;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,4CAkBA,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB,iCAAmB,CAAA;AAGlD,eAAO,MAAM,sBAAsB,6CAA+C,CAAA"}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,mBAAmB,SAAS,CAAA"}
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hanzogui will attempt to stack z-index in a smart way when true, it does this
|
|
3
|
+
* by automatically increasing z-index both horizontally and vertically in the component tree.
|
|
4
|
+
*
|
|
5
|
+
* Basically - if two stackable items are at the same level, then the order of mounting
|
|
6
|
+
* determines their z-index (later is higher). This is the horizontal logic.
|
|
7
|
+
*
|
|
8
|
+
* Below a stackable item, the z-index will always be above that specific item, but below
|
|
9
|
+
* other horizontal items that come after it.
|
|
10
|
+
*
|
|
11
|
+
* - false will avoid the stacking behavior.
|
|
12
|
+
* - number will keep the behavior, but add to the stacked z-index the given amount
|
|
13
|
+
* - 'global' will not stack things vertically and instead only stack them horizontally
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
export type StackZIndexProp = boolean | number | 'global';
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStackedZIndex.d.ts","sourceRoot":"","sources":["../src/useStackedZIndex.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAQ9C,eAAO,MAAM,gBAAgB,GAAI,OAAO;IACtC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,eAAe,CAAA;CAC9B,WA6EA,CAAA"}
|