@drawnagency/primitives 0.1.29 → 0.1.31

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.
@@ -6,12 +6,12 @@ import {
6
6
  setSessionCookie,
7
7
  signSessionToken,
8
8
  verifySessionToken
9
- } from "../chunk-F32I6ZZV.js";
9
+ } from "../chunk-PKMPRW7T.js";
10
10
  import {
11
11
  isSameOriginRequest,
12
12
  requireSessionSecret,
13
13
  safeNextPath
14
- } from "../chunk-F3Z6RISI.js";
14
+ } from "../chunk-EUNJDXYX.js";
15
15
  export {
16
16
  AUDIENCE_COOKIE,
17
17
  LastOwnerError,
@@ -1,6 +1,6 @@
1
1
  // src/auth/security.ts
2
2
  function env(key) {
3
- return import.meta.env?.[key] ?? process.env?.[key] ?? "";
3
+ return import.meta.env?.[key] ?? (typeof process !== "undefined" ? process.env?.[key] : void 0) ?? "";
4
4
  }
5
5
  function requireSessionSecret() {
6
6
  const secret = env("SESSION_SECRET");
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  requireSessionSecret
3
- } from "./chunk-F3Z6RISI.js";
3
+ } from "./chunk-EUNJDXYX.js";
4
4
 
5
5
  // src/auth/cookies.ts
6
6
  import * as jose from "jose";
@@ -249,15 +249,17 @@ function generateVideoPoster(blob, quality) {
249
249
  }
250
250
 
251
251
  // src/media/index.ts
252
- var _provider = null;
252
+ var MEDIA_KEY = /* @__PURE__ */ Symbol.for("@drawnagency/primitives/media");
253
+ var _g = globalThis;
253
254
  function setMediaProvider(p) {
254
- _provider = p;
255
+ _g[MEDIA_KEY] = p;
255
256
  }
256
257
  function getMediaProvider() {
257
- if (!_provider) {
258
+ const provider = _g[MEDIA_KEY];
259
+ if (!provider) {
258
260
  throw new Error("No MediaProvider registered. Call setMediaProvider() before using getMediaProvider().");
259
261
  }
260
- return _provider;
262
+ return provider;
261
263
  }
262
264
 
263
265
  export {
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-V43WVSVS.js";
7
7
  import {
8
8
  safeNextPath
9
- } from "./chunk-F3Z6RISI.js";
9
+ } from "./chunk-EUNJDXYX.js";
10
10
 
11
11
  // src/lib/cn.ts
12
12
  import { clsx } from "clsx";
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ import {
27
27
  safeRedirect,
28
28
  sanitizeHtml,
29
29
  toSectionId
30
- } from "./chunk-HXXZBTPF.js";
30
+ } from "./chunk-ZDKSJY2K.js";
31
31
  import {
32
32
  ColorItemSchema,
33
33
  ColorSpaceSchema,
@@ -57,12 +57,12 @@ import {
57
57
  setSessionCookie,
58
58
  signSessionToken,
59
59
  verifySessionToken
60
- } from "./chunk-F32I6ZZV.js";
60
+ } from "./chunk-PKMPRW7T.js";
61
61
  import {
62
62
  isSameOriginRequest,
63
63
  requireSessionSecret,
64
64
  safeNextPath
65
- } from "./chunk-F3Z6RISI.js";
65
+ } from "./chunk-EUNJDXYX.js";
66
66
  import {
67
67
  EXT_TO_MIME,
68
68
  MIME_TO_EXT,
@@ -76,7 +76,7 @@ import {
76
76
  resolveMedia,
77
77
  sanitizeMediaName,
78
78
  setMediaProvider
79
- } from "./chunk-JHSYLVKI.js";
79
+ } from "./chunk-VCZBZMXU.js";
80
80
  import {
81
81
  ImageManifestSchema,
82
82
  MediaConfigSchema,
package/dist/lib/index.js CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  safeRedirect,
18
18
  sanitizeHtml,
19
19
  toSectionId
20
- } from "../chunk-HXXZBTPF.js";
20
+ } from "../chunk-ZDKSJY2K.js";
21
21
  import {
22
22
  clearRegistry,
23
23
  createRegistry,
@@ -29,7 +29,7 @@ import {
29
29
  registerSchema,
30
30
  registerSection
31
31
  } from "../chunk-V43WVSVS.js";
32
- import "../chunk-F3Z6RISI.js";
32
+ import "../chunk-EUNJDXYX.js";
33
33
  import "../chunk-DKOUFIP6.js";
34
34
  export {
35
35
  buildGoogleFontsUrl,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/media/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAIpD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,aAAa,GAAG,IAAI,CAEvD;AAED,wBAAgB,gBAAgB,IAAI,aAAa,CAKhD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/media/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAKpD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,aAAa,GAAG,IAAI,CAEvD;AAED,wBAAgB,gBAAgB,IAAI,aAAa,CAMhD"}
@@ -11,7 +11,7 @@ import {
11
11
  resolveMedia,
12
12
  sanitizeMediaName,
13
13
  setMediaProvider
14
- } from "../chunk-JHSYLVKI.js";
14
+ } from "../chunk-VCZBZMXU.js";
15
15
  import {
16
16
  ImageManifestSchema,
17
17
  MediaConfigSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drawnagency/primitives",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  function env(key: string): string {
7
- return import.meta.env?.[key] ?? process.env?.[key] ?? "";
7
+ return import.meta.env?.[key] ?? (typeof process !== "undefined" ? process.env?.[key] : undefined) ?? "";
8
8
  }
9
9
 
10
10
  export function requireSessionSecret(): Uint8Array {
@@ -81,12 +81,23 @@ function ColorsView({
81
81
  showLabel?: boolean;
82
82
  }) {
83
83
  const [expanded, setExpanded] = useState(!collapsing);
84
- const [copiedValue, setCopiedValue] = useState<string | null>(null);
84
+ const [copiedIndex, setCopiedIndex] = useState<number | null>(null);
85
85
 
86
- const handleCopy = (value: string) => {
87
- navigator.clipboard.writeText(value);
88
- setCopiedValue(value);
89
- setTimeout(() => setCopiedValue(null), 1500);
86
+ const handleCopy = (value: string, colorIndex: number) => {
87
+ if (navigator.clipboard?.writeText) {
88
+ navigator.clipboard.writeText(value);
89
+ } else {
90
+ const ta = document.createElement("textarea");
91
+ ta.value = value;
92
+ ta.style.position = "fixed";
93
+ ta.style.opacity = "0";
94
+ document.body.appendChild(ta);
95
+ ta.select();
96
+ document.execCommand("copy");
97
+ document.body.removeChild(ta);
98
+ }
99
+ setCopiedIndex(colorIndex);
100
+ setTimeout(() => setCopiedIndex(null), 1500);
90
101
  };
91
102
 
92
103
  return (
@@ -114,17 +125,25 @@ function ColorsView({
114
125
  const contrast = getContrastClass(hex);
115
126
  return (
116
127
  <div key={i} className="overflow-hidden rounded-md border border-base-200">
117
- <div className={cn("flex min-h-[80px] items-end p-3", contrast)} style={{ backgroundColor: hex || "#ccc" }}>
128
+ <div className={cn("relative flex min-h-[80px] items-end p-3", contrast)} style={{ backgroundColor: hex || "#ccc" }}>
118
129
  {color.name && <span className="text-sm font-bold">{color.name}</span>}
130
+ {copiedIndex === i && (
131
+ <span className={cn(
132
+ "absolute top-2 right-2 rounded-full px-2.5 py-0.5 text-xs font-medium",
133
+ getContrastClass(hex) === "text-black" ? "bg-black/15 text-black" : "bg-white/25 text-white",
134
+ )}>
135
+ Copied!
136
+ </span>
137
+ )}
119
138
  </div>
120
139
  {expanded && (
121
140
  <div className="space-y-1 bg-base-accent p-3 text-sm">
122
141
  {color.spaces.map((space, j) =>
123
142
  Object.entries(space).map(([key, value]) =>
124
143
  value ? (
125
- <button key={`${j}-${key}`} onClick={() => handleCopy(value)} className="cursor-pointer flex w-full justify-between hover:text-primary">
144
+ <button key={`${j}-${key}`} onClick={() => handleCopy(value, i)} className="cursor-pointer flex w-full justify-between hover:text-primary">
126
145
  <span className="font-medium uppercase">{key}</span>
127
- <span>{copiedValue === value ? "Copied!" : value}</span>
146
+ <span>{value}</span>
128
147
  </button>
129
148
  ) : null
130
149
  )
@@ -7,15 +7,17 @@ export * from "./queue";
7
7
  export * from "./resolve";
8
8
  export { generateVideoPoster } from "./videoPoster";
9
9
 
10
- let _provider: MediaProvider | null = null;
10
+ const MEDIA_KEY = Symbol.for("@drawnagency/primitives/media");
11
+ const _g = globalThis as Record<symbol, MediaProvider | null>;
11
12
 
12
13
  export function setMediaProvider(p: MediaProvider): void {
13
- _provider = p;
14
+ _g[MEDIA_KEY] = p;
14
15
  }
15
16
 
16
17
  export function getMediaProvider(): MediaProvider {
17
- if (!_provider) {
18
+ const provider = _g[MEDIA_KEY];
19
+ if (!provider) {
18
20
  throw new Error("No MediaProvider registered. Call setMediaProvider() before using getMediaProvider().");
19
21
  }
20
- return _provider;
22
+ return provider;
21
23
  }