svelte-ag 0.0.2-dev.84 → 1.0.4

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.
@@ -1,3 +1,3 @@
1
- import type { UseFloatingOptions, UseFloatingReturn } from "./types.js";
1
+ import type { UseFloatingOptions, UseFloatingReturn } from './types.js';
2
2
  export declare function useFloating(options: UseFloatingOptions): UseFloatingReturn;
3
3
  //# sourceMappingURL=use-floating.svelte.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-floating.svelte.d.ts","sourceRoot":"","sources":["../../../../../src/lib/bits/internal/floating-svelte/use-floating.svelte.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGxE,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CA+H1E"}
1
+ {"version":3,"file":"use-floating.svelte.d.ts","sourceRoot":"","sources":["../../../../../src/lib/bits/internal/floating-svelte/use-floating.svelte.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGxE,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CA6H1E"}
@@ -1,28 +1,30 @@
1
- import { computePosition } from "@floating-ui/dom";
2
- import { box } from "svelte-toolbelt";
3
- import { get, getDPR, roundByDPR } from "./floating-utils.svelte.js";
1
+ import { computePosition } from '@floating-ui/dom';
2
+ import { box } from 'svelte-toolbelt';
3
+ import { get, getDPR, roundByDPR } from './floating-utils.svelte.js';
4
4
  export function useFloating(options) {
5
5
  /** Options */
6
6
  const whileElementsMountedOption = options.whileElementsMounted;
7
7
  const openOption = $derived(get(options.open) ?? true);
8
8
  const middlewareOption = $derived(get(options.middleware));
9
9
  const transformOption = $derived(get(options.transform) ?? true);
10
- const placementOption = $derived(get(options.placement) ?? "bottom");
11
- const strategyOption = $derived(get(options.strategy) ?? "absolute");
10
+ const placementOption = $derived(get(options.placement) ?? 'bottom');
11
+ const strategyOption = $derived(get(options.strategy) ?? 'absolute');
12
12
  const reference = options.reference;
13
13
  /** State */
14
14
  let x = $state(0);
15
15
  let y = $state(0);
16
16
  const floating = box(null);
17
+ // svelte-ignore state_referenced_locally
17
18
  let strategy = $state(strategyOption);
19
+ // svelte-ignore state_referenced_locally
18
20
  let placement = $state(placementOption);
19
21
  let middlewareData = $state({});
20
22
  let isPositioned = $state(false);
21
23
  const floatingStyles = $derived.by(() => {
22
24
  const initialStyles = {
23
25
  position: strategy,
24
- left: "0",
25
- top: "0",
26
+ left: '0',
27
+ top: '0'
26
28
  };
27
29
  if (!floating.current) {
28
30
  return initialStyles;
@@ -34,14 +36,14 @@ export function useFloating(options) {
34
36
  ...initialStyles,
35
37
  transform: `translate(${xVal}px, ${yVal}px)`,
36
38
  ...(getDPR(floating.current) >= 1.5 && {
37
- willChange: "transform",
38
- }),
39
+ willChange: 'transform'
40
+ })
39
41
  };
40
42
  }
41
43
  return {
42
44
  position: strategy,
43
45
  left: `${xVal}px`,
44
- top: `${yVal}px`,
46
+ top: `${yVal}px`
45
47
  };
46
48
  });
47
49
  /** Effects */
@@ -52,7 +54,7 @@ export function useFloating(options) {
52
54
  computePosition(reference.current, floating.current, {
53
55
  middleware: middlewareOption,
54
56
  placement: placementOption,
55
- strategy: strategyOption,
57
+ strategy: strategyOption
56
58
  }).then((position) => {
57
59
  x = position.x;
58
60
  y = position.y;
@@ -63,7 +65,7 @@ export function useFloating(options) {
63
65
  });
64
66
  }
65
67
  function cleanup() {
66
- if (typeof whileElementsMountedCleanup === "function") {
68
+ if (typeof whileElementsMountedCleanup === 'function') {
67
69
  whileElementsMountedCleanup();
68
70
  whileElementsMountedCleanup = undefined;
69
71
  }
@@ -107,6 +109,6 @@ export function useFloating(options) {
107
109
  },
108
110
  get update() {
109
111
  return update;
110
- },
112
+ }
111
113
  };
112
114
  }
@@ -11,6 +11,10 @@ interface Options {
11
11
  */
12
12
  include?: RegExp | RegExp[];
13
13
  run: boolean;
14
+ /**
15
+ * node_modules packages that can be added to the component list
16
+ */
17
+ safePackages: string[];
14
18
  }
15
19
  export default function componentSourceCollector(opts?: Options): Plugin;
16
20
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"vite-plugin-component-source-collector.d.ts","sourceRoot":"","sources":["../../../src/lib/vite/vite-plugin-component-source-collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAInD,UAAU,OAAO;IACf;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE5B,GAAG,EAAE,OAAO,CAAC;CACd;AAED,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAAC,IAAI,GAAE,OAAuB,GAAG,MAAM,CA8GtF"}
1
+ {"version":3,"file":"vite-plugin-component-source-collector.d.ts","sourceRoot":"","sources":["../../../src/lib/vite/vite-plugin-component-source-collector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkB,MAAM,MAAM,CAAC;AAInD,UAAU,OAAO;IACf;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE5B,GAAG,EAAE,OAAO,CAAC;IAEb;;OAEG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAAC,IAAI,GAAE,OAAyC,GAAG,MAAM,CA8GxG"}
@@ -1,6 +1,6 @@
1
1
  import { writeIfDifferent } from 'ts-ag';
2
2
  import path from 'path';
3
- export default function componentSourceCollector(opts = { run: true }) {
3
+ export default function componentSourceCollector(opts = { run: true, safePackages: [] }) {
4
4
  if (opts.run === false)
5
5
  return { name: 'disabled' };
6
6
  const outFile = opts.outputFile ?? 'component-sources.css';
@@ -34,7 +34,7 @@ export default function componentSourceCollector(opts = { run: true }) {
34
34
  const classRegex = /class(?:=|:)/;
35
35
  const importRegex = /@import\s+['"]([^'"]+)['"]/g;
36
36
  function shouldAdd(fileName) {
37
- return !/\.pnpm|.vite/.test(fileName);
37
+ return !/\.pnpm|.vite/.test(fileName) || opts.safePackages.some((p) => fileName.includes(`node_modules/${p}`));
38
38
  }
39
39
  /** ---- plugin ----------------------------------------------------------- */
40
40
  return {
@@ -46,7 +46,7 @@ export default function componentSourceCollector(opts = { run: true }) {
46
46
  console.log('tailwind-sources:configResolved', config.command);
47
47
  },
48
48
  buildStart() {
49
- console.log('tailwind-sources:buildStart');
49
+ console.log('tailwind-sources:buildStart', componentFiles);
50
50
  // componentFiles.clear();
51
51
  },
52
52
  async transform(code, id) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "svelte-ag",
3
3
  "description": "Useful svelte components",
4
- "version": "0.0.2-dev.84",
4
+ "version": "1.0.4",
5
5
  "author": "Alexander Hornung",
6
6
  "bugs": "https://github.com/ageorgeh/svelte-ag/issues",
7
7
  "dependencies": {
@@ -25,7 +25,7 @@
25
25
  "radash": "12.1.1",
26
26
  "devalue": "5.1.1",
27
27
  "bottleneck": "2.19.5",
28
- "ts-ag": "0.0.1-dev.3"
28
+ "ts-ag": "1.0.4"
29
29
  },
30
30
  "peerDependencies": {
31
31
  "svelte": "^5.28.2",
@@ -92,6 +92,8 @@
92
92
  "svelte:sync": "svelte-kit sync",
93
93
  "publish:local": "pnpm version prerelease --preid dev --no-git-tag-version && pnpm publish --registry http://localhost:4873 --tag dev --access public --no-git-checks --json > ./publishLocal.json",
94
94
  "publish:prerelease": "pnpm publish --tag dev --access public --no-git-checks --registry=https://registry.npmjs.org/ --json > ./publish.json",
95
- "version:prerelease": "pnpm version prerelease --preid dev --no-git-tag-version"
95
+ "version:prerelease": "pnpm version prerelease --preid dev --no-git-tag-version",
96
+ "run-publish": "pnpm publish --access public --no-git-checks --registry=https://registry.npmjs.org/ --json > ./publish.json",
97
+ "run-version": "pnpm version patch --no-git-tag-version"
96
98
  }
97
99
  }
@@ -1,133 +1,131 @@
1
- import { computePosition } from "@floating-ui/dom";
2
- import { box } from "svelte-toolbelt";
3
- import type { UseFloatingOptions, UseFloatingReturn } from "./types.js";
4
- import { get, getDPR, roundByDPR } from "./floating-utils.svelte.js";
1
+ import { computePosition } from '@floating-ui/dom';
2
+ import { box } from 'svelte-toolbelt';
3
+ import type { UseFloatingOptions, UseFloatingReturn } from './types.js';
4
+ import { get, getDPR, roundByDPR } from './floating-utils.svelte.js';
5
5
 
6
6
  export function useFloating(options: UseFloatingOptions): UseFloatingReturn {
7
- /** Options */
8
- const whileElementsMountedOption = options.whileElementsMounted;
9
- const openOption = $derived(get(options.open) ?? true);
10
- const middlewareOption = $derived(get(options.middleware));
11
- const transformOption = $derived(get(options.transform) ?? true);
12
- const placementOption = $derived(get(options.placement) ?? "bottom");
13
- const strategyOption = $derived(get(options.strategy) ?? "absolute");
14
- const reference = options.reference;
15
-
16
- /** State */
17
- let x = $state(0);
18
- let y = $state(0);
19
-
20
- const floating = box<HTMLElement | null>(null);
21
-
22
- let strategy = $state(strategyOption);
23
- let placement = $state(placementOption);
24
- let middlewareData = $state({});
25
- let isPositioned = $state(false);
26
- const floatingStyles = $derived.by(() => {
27
- const initialStyles = {
28
- position: strategy,
29
- left: "0",
30
- top: "0",
31
- };
32
-
33
- if (!floating.current) {
34
- return initialStyles;
35
- }
36
-
37
- const xVal = roundByDPR(floating.current, x);
38
- const yVal = roundByDPR(floating.current, y);
39
-
40
- if (transformOption) {
41
- return {
42
- ...initialStyles,
43
- transform: `translate(${xVal}px, ${yVal}px)`,
44
- ...(getDPR(floating.current) >= 1.5 && {
45
- willChange: "transform",
46
- }),
47
- };
48
- }
49
-
50
- return {
51
- position: strategy,
52
- left: `${xVal}px`,
53
- top: `${yVal}px`,
54
- };
55
- });
56
-
57
- /** Effects */
58
- let whileElementsMountedCleanup: (() => void) | undefined;
59
-
60
- function update() {
61
- if (reference.current === null || floating.current === null) return;
62
- computePosition(reference.current, floating.current, {
63
- middleware: middlewareOption,
64
- placement: placementOption,
65
- strategy: strategyOption,
66
- }).then((position) => {
67
- x = position.x;
68
- y = position.y;
69
- strategy = position.strategy;
70
- placement = position.placement;
71
- middlewareData = position.middlewareData;
72
- isPositioned = true;
73
- });
74
- }
75
-
76
- function cleanup() {
77
- if (typeof whileElementsMountedCleanup === "function") {
78
- whileElementsMountedCleanup();
79
- whileElementsMountedCleanup = undefined;
80
- }
81
- }
82
-
83
- function attach() {
84
- cleanup();
85
-
86
- if (whileElementsMountedOption === undefined) {
87
- update();
88
- return;
89
- }
90
-
91
- if (reference.current === null || floating.current === null) return;
92
-
93
- whileElementsMountedCleanup = whileElementsMountedOption(
94
- reference.current,
95
- floating.current,
96
- update
97
- );
98
- }
99
-
100
- function reset() {
101
- if (!openOption) {
102
- isPositioned = false;
103
- }
104
- }
105
-
106
- $effect(update);
107
- $effect(attach);
108
- $effect(reset);
109
- $effect(() => cleanup);
110
-
111
- return {
112
- floating,
113
- reference,
114
- get strategy() {
115
- return strategy;
116
- },
117
- get placement() {
118
- return placement;
119
- },
120
- get middlewareData() {
121
- return middlewareData;
122
- },
123
- get isPositioned() {
124
- return isPositioned;
125
- },
126
- get floatingStyles() {
127
- return floatingStyles;
128
- },
129
- get update() {
130
- return update;
131
- },
132
- };
7
+ /** Options */
8
+ const whileElementsMountedOption = options.whileElementsMounted;
9
+ const openOption = $derived(get(options.open) ?? true);
10
+ const middlewareOption = $derived(get(options.middleware));
11
+ const transformOption = $derived(get(options.transform) ?? true);
12
+ const placementOption = $derived(get(options.placement) ?? 'bottom');
13
+ const strategyOption = $derived(get(options.strategy) ?? 'absolute');
14
+ const reference = options.reference;
15
+
16
+ /** State */
17
+ let x = $state(0);
18
+ let y = $state(0);
19
+
20
+ const floating = box<HTMLElement | null>(null);
21
+
22
+ // svelte-ignore state_referenced_locally
23
+ let strategy = $state(strategyOption);
24
+ // svelte-ignore state_referenced_locally
25
+ let placement = $state(placementOption);
26
+ let middlewareData = $state({});
27
+ let isPositioned = $state(false);
28
+ const floatingStyles = $derived.by(() => {
29
+ const initialStyles = {
30
+ position: strategy,
31
+ left: '0',
32
+ top: '0'
33
+ };
34
+
35
+ if (!floating.current) {
36
+ return initialStyles;
37
+ }
38
+
39
+ const xVal = roundByDPR(floating.current, x);
40
+ const yVal = roundByDPR(floating.current, y);
41
+
42
+ if (transformOption) {
43
+ return {
44
+ ...initialStyles,
45
+ transform: `translate(${xVal}px, ${yVal}px)`,
46
+ ...(getDPR(floating.current) >= 1.5 && {
47
+ willChange: 'transform'
48
+ })
49
+ };
50
+ }
51
+
52
+ return {
53
+ position: strategy,
54
+ left: `${xVal}px`,
55
+ top: `${yVal}px`
56
+ };
57
+ });
58
+
59
+ /** Effects */
60
+ let whileElementsMountedCleanup: (() => void) | undefined;
61
+
62
+ function update() {
63
+ if (reference.current === null || floating.current === null) return;
64
+ computePosition(reference.current, floating.current, {
65
+ middleware: middlewareOption,
66
+ placement: placementOption,
67
+ strategy: strategyOption
68
+ }).then((position) => {
69
+ x = position.x;
70
+ y = position.y;
71
+ strategy = position.strategy;
72
+ placement = position.placement;
73
+ middlewareData = position.middlewareData;
74
+ isPositioned = true;
75
+ });
76
+ }
77
+
78
+ function cleanup() {
79
+ if (typeof whileElementsMountedCleanup === 'function') {
80
+ whileElementsMountedCleanup();
81
+ whileElementsMountedCleanup = undefined;
82
+ }
83
+ }
84
+
85
+ function attach() {
86
+ cleanup();
87
+
88
+ if (whileElementsMountedOption === undefined) {
89
+ update();
90
+ return;
91
+ }
92
+
93
+ if (reference.current === null || floating.current === null) return;
94
+
95
+ whileElementsMountedCleanup = whileElementsMountedOption(reference.current, floating.current, update);
96
+ }
97
+
98
+ function reset() {
99
+ if (!openOption) {
100
+ isPositioned = false;
101
+ }
102
+ }
103
+
104
+ $effect(update);
105
+ $effect(attach);
106
+ $effect(reset);
107
+ $effect(() => cleanup);
108
+
109
+ return {
110
+ floating,
111
+ reference,
112
+ get strategy() {
113
+ return strategy;
114
+ },
115
+ get placement() {
116
+ return placement;
117
+ },
118
+ get middlewareData() {
119
+ return middlewareData;
120
+ },
121
+ get isPositioned() {
122
+ return isPositioned;
123
+ },
124
+ get floatingStyles() {
125
+ return floatingStyles;
126
+ },
127
+ get update() {
128
+ return update;
129
+ }
130
+ };
133
131
  }
@@ -15,9 +15,14 @@ interface Options {
15
15
  include?: RegExp | RegExp[];
16
16
 
17
17
  run: boolean;
18
+
19
+ /**
20
+ * node_modules packages that can be added to the component list
21
+ */
22
+ safePackages: string[];
18
23
  }
19
24
 
20
- export default function componentSourceCollector(opts: Options = { run: true }): Plugin {
25
+ export default function componentSourceCollector(opts: Options = { run: true, safePackages: [] }): Plugin {
21
26
  if (opts.run === false) return { name: 'disabled' };
22
27
 
23
28
  const outFile = opts.outputFile ?? 'component-sources.css';
@@ -57,7 +62,7 @@ export default function componentSourceCollector(opts: Options = { run: true }):
57
62
  const importRegex = /@import\s+['"]([^'"]+)['"]/g;
58
63
 
59
64
  function shouldAdd(fileName: string) {
60
- return !/\.pnpm|.vite/.test(fileName);
65
+ return !/\.pnpm|.vite/.test(fileName) || opts.safePackages.some((p) => fileName.includes(`node_modules/${p}`));
61
66
  }
62
67
 
63
68
  /** ---- plugin ----------------------------------------------------------- */
@@ -73,7 +78,7 @@ export default function componentSourceCollector(opts: Options = { run: true }):
73
78
  },
74
79
 
75
80
  buildStart() {
76
- console.log('tailwind-sources:buildStart');
81
+ console.log('tailwind-sources:buildStart', componentFiles);
77
82
  // componentFiles.clear();
78
83
  },
79
84