ember-container-query 3.1.0 → 4.0.0-alpha.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/README.md +33 -12
- package/addon-main.js +5 -0
- package/dist/_app_/components/container-query.js +1 -0
- package/dist/_app_/helpers/aspect-ratio.js +1 -0
- package/dist/_app_/helpers/height.js +1 -0
- package/dist/_app_/helpers/width.js +1 -0
- package/dist/_app_/modifiers/container-query.js +1 -0
- package/dist/applyDecoratedDescriptor-fa858ac4.js +77 -0
- package/dist/applyDecoratedDescriptor-fa858ac4.js.map +1 -0
- package/{addon/styles → dist/components}/container-query.css +0 -0
- package/{components → dist/components}/container-query.d.ts +4 -4
- package/dist/components/container-query.d.ts.map +1 -0
- package/dist/components/container-query.js +40 -0
- package/dist/components/container-query.js.map +1 -0
- package/dist/helpers/aspect-ratio.d.ts +13 -0
- package/dist/helpers/aspect-ratio.js +15 -0
- package/dist/helpers/aspect-ratio.js.map +1 -0
- package/dist/helpers/height.d.ts +13 -0
- package/dist/helpers/height.js +15 -0
- package/dist/helpers/height.js.map +1 -0
- package/dist/helpers/width.d.ts +13 -0
- package/dist/helpers/width.js +15 -0
- package/dist/helpers/width.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/{modifiers → dist/modifiers}/container-query.d.ts +5 -5
- package/dist/modifiers/container-query.js +106 -0
- package/dist/modifiers/container-query.js.map +1 -0
- package/dist/template-registry.d.ts +13 -0
- package/dist/template-registry.js +2 -0
- package/dist/template-registry.js.map +1 -0
- package/package.json +48 -107
- package/.netlifyredirects +0 -1
- package/.stylelintcache +0 -1
- package/.stylelintrc.js +0 -64
- package/CHANGELOG.md +0 -410
- package/addon/components/container-query.hbs +0 -21
- package/addon/components/container-query.ts +0 -48
- package/addon/helpers/cq-aspect-ratio.ts +0 -25
- package/addon/helpers/cq-height.ts +0 -23
- package/addon/helpers/cq-width.ts +0 -23
- package/addon/modifiers/container-query.ts +0 -179
- package/addon/template-registry.ts +0 -13
- package/app/components/container-query.js +0 -1
- package/app/helpers/cq-aspect-ratio.js +0 -1
- package/app/helpers/cq-height.js +0 -1
- package/app/helpers/cq-width.js +0 -1
- package/app/modifiers/container-query.js +0 -1
- package/helpers/cq-aspect-ratio.d.ts +0 -13
- package/helpers/cq-height.d.ts +0 -13
- package/helpers/cq-width.d.ts +0 -13
- package/index.js +0 -5
- package/template-registry.d.ts +0 -13
- package/tsconfig.json +0 -47
- package/types/dummy/index.d.ts +0 -33
- package/types/global.d.ts +0 -6
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { registerDestructor } from '@ember/destroyable';
|
|
2
|
-
import { action } from '@ember/object';
|
|
3
|
-
import { debounce as _debounce } from '@ember/runloop';
|
|
4
|
-
import { inject as service } from '@ember/service';
|
|
5
|
-
import Modifier, { ArgsFor, NamedArgs, PositionalArgs } from 'ember-modifier';
|
|
6
|
-
|
|
7
|
-
type IndexSignatureParameter = string | number | symbol;
|
|
8
|
-
|
|
9
|
-
type Dimensions = {
|
|
10
|
-
aspectRatio: number;
|
|
11
|
-
height: number;
|
|
12
|
-
width: number;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type Metadata = {
|
|
16
|
-
dimension: 'aspectRatio' | 'height' | 'width';
|
|
17
|
-
max: number;
|
|
18
|
-
min: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type Features<T extends IndexSignatureParameter> = Record<T, Metadata>;
|
|
22
|
-
|
|
23
|
-
type QueryResults<T extends IndexSignatureParameter> = Record<T, boolean>;
|
|
24
|
-
|
|
25
|
-
interface ContainerQueryModifierSignature<T extends IndexSignatureParameter> {
|
|
26
|
-
Args: {
|
|
27
|
-
Named: {
|
|
28
|
-
dataAttributePrefix?: string;
|
|
29
|
-
debounce?: number;
|
|
30
|
-
features?: Features<T>;
|
|
31
|
-
onQuery?: ({
|
|
32
|
-
dimensions,
|
|
33
|
-
queryResults,
|
|
34
|
-
}: {
|
|
35
|
-
dimensions: Dimensions;
|
|
36
|
-
queryResults: QueryResults<T>;
|
|
37
|
-
}) => void;
|
|
38
|
-
};
|
|
39
|
-
Positional: [];
|
|
40
|
-
};
|
|
41
|
-
Element: Element;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export default class ContainerQueryModifier<
|
|
45
|
-
T extends IndexSignatureParameter
|
|
46
|
-
> extends Modifier<ContainerQueryModifierSignature<T>> {
|
|
47
|
-
@service private declare readonly resizeObserver;
|
|
48
|
-
|
|
49
|
-
dimensions!: Dimensions;
|
|
50
|
-
queryResults!: QueryResults<T>;
|
|
51
|
-
|
|
52
|
-
private _dataAttributes: string[] = [];
|
|
53
|
-
private _element?: Element;
|
|
54
|
-
private _named!: NamedArgs<ContainerQueryModifierSignature<T>>;
|
|
55
|
-
|
|
56
|
-
get dataAttributePrefix(): string {
|
|
57
|
-
return this._named.dataAttributePrefix ?? 'container-query';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get debounce(): number {
|
|
61
|
-
return this._named.debounce ?? 0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
get features(): Features<T> {
|
|
65
|
-
return this._named.features ?? ({} as Features<T>);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
constructor(
|
|
69
|
-
owner: unknown,
|
|
70
|
-
args: ArgsFor<ContainerQueryModifierSignature<T>>
|
|
71
|
-
) {
|
|
72
|
-
super(owner, args);
|
|
73
|
-
|
|
74
|
-
registerDestructor(this, () => {
|
|
75
|
-
this.resizeObserver.unobserve(this._element, this.onResize);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
modify(
|
|
80
|
-
element: Element,
|
|
81
|
-
_positional: PositionalArgs<ContainerQueryModifierSignature<T>>,
|
|
82
|
-
named: NamedArgs<ContainerQueryModifierSignature<T>>
|
|
83
|
-
): void {
|
|
84
|
-
this._named = named;
|
|
85
|
-
|
|
86
|
-
this.registerResizeObserver(element);
|
|
87
|
-
this.queryContainer(element);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
@action private onResize(resizeObserverEntry: ResizeObserverEntry): void {
|
|
91
|
-
const element = resizeObserverEntry.target;
|
|
92
|
-
|
|
93
|
-
if (this.debounce > 0) {
|
|
94
|
-
_debounce(this, this.queryContainer, element, this.debounce);
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
this.queryContainer(element);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
private registerResizeObserver(element: Element): void {
|
|
102
|
-
this.resizeObserver.unobserve(this._element, this.onResize);
|
|
103
|
-
|
|
104
|
-
this._element = element;
|
|
105
|
-
this.resizeObserver.observe(this._element, this.onResize);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private queryContainer(element: Element): void {
|
|
109
|
-
this.measureDimensions(element);
|
|
110
|
-
this.evaluateQueries();
|
|
111
|
-
this.resetDataAttributes(element);
|
|
112
|
-
this.setDataAttributes(element);
|
|
113
|
-
|
|
114
|
-
this._named.onQuery?.({
|
|
115
|
-
dimensions: this.dimensions,
|
|
116
|
-
queryResults: this.queryResults,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private measureDimensions(element: Element): void {
|
|
121
|
-
const height = element.clientHeight;
|
|
122
|
-
const width = element.clientWidth;
|
|
123
|
-
|
|
124
|
-
this.dimensions = {
|
|
125
|
-
aspectRatio: width / height,
|
|
126
|
-
height,
|
|
127
|
-
width,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private evaluateQueries(): void {
|
|
132
|
-
const queryResults = {} as QueryResults<T>;
|
|
133
|
-
|
|
134
|
-
for (const [featureName, metadata] of Object.entries(this.features)) {
|
|
135
|
-
const { dimension, min, max } = metadata as Metadata;
|
|
136
|
-
const value = this.dimensions[dimension];
|
|
137
|
-
|
|
138
|
-
queryResults[featureName as T] = min <= value && value < max;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
this.queryResults = queryResults;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private resetDataAttributes(element: Element): void {
|
|
145
|
-
this._dataAttributes.forEach((dataAttribute) => {
|
|
146
|
-
element.removeAttribute(dataAttribute);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
this._dataAttributes = [];
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
private setDataAttributes(element: Element): void {
|
|
153
|
-
const prefix = this.dataAttributePrefix;
|
|
154
|
-
|
|
155
|
-
for (const [featureName, meetsFeature] of Object.entries(
|
|
156
|
-
this.queryResults
|
|
157
|
-
)) {
|
|
158
|
-
if (!meetsFeature) {
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const dataAttribute = prefix
|
|
163
|
-
? `data-${prefix}-${featureName}`
|
|
164
|
-
: `data-${featureName}`;
|
|
165
|
-
|
|
166
|
-
element.setAttribute(dataAttribute, '');
|
|
167
|
-
|
|
168
|
-
this._dataAttributes.push(dataAttribute);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export {
|
|
174
|
-
Dimensions,
|
|
175
|
-
Features,
|
|
176
|
-
IndexSignatureParameter,
|
|
177
|
-
Metadata,
|
|
178
|
-
QueryResults,
|
|
179
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type ContainerQueryComponent from 'ember-container-query/components/container-query';
|
|
2
|
-
import type CqAspectRatioHelper from 'ember-container-query/helpers/cq-aspect-ratio';
|
|
3
|
-
import type CqHeightHelper from 'ember-container-query/helpers/cq-height';
|
|
4
|
-
import type CqWidthHelper from 'ember-container-query/helpers/cq-width';
|
|
5
|
-
import type ContainerQueryModifier from 'ember-container-query/modifiers/container-query';
|
|
6
|
-
|
|
7
|
-
export default interface EmberContainerQueryRegistry {
|
|
8
|
-
ContainerQuery: typeof ContainerQueryComponent;
|
|
9
|
-
'container-query': typeof ContainerQueryModifier;
|
|
10
|
-
'cq-aspect-ratio': typeof CqAspectRatioHelper;
|
|
11
|
-
'cq-height': typeof CqHeightHelper;
|
|
12
|
-
'cq-width': typeof CqWidthHelper;
|
|
13
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from 'ember-container-query/components/container-query';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from 'ember-container-query/helpers/cq-aspect-ratio';
|
package/app/helpers/cq-height.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from 'ember-container-query/helpers/cq-height';
|
package/app/helpers/cq-width.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from 'ember-container-query/helpers/cq-width';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from 'ember-container-query/modifiers/container-query';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Metadata } from 'ember-container-query/modifiers/container-query';
|
|
2
|
-
declare const CqAspectRatioHelper: import("@ember/component/helper").FunctionBasedHelper<{
|
|
3
|
-
Args: {
|
|
4
|
-
Positional: [];
|
|
5
|
-
Named: {
|
|
6
|
-
max?: number | undefined;
|
|
7
|
-
min?: number | undefined;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
Return: Metadata;
|
|
11
|
-
}>;
|
|
12
|
-
export default CqAspectRatioHelper;
|
|
13
|
-
//# sourceMappingURL=cq-aspect-ratio.d.ts.map
|
package/helpers/cq-height.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Metadata } from 'ember-container-query/modifiers/container-query';
|
|
2
|
-
declare const CqHeightHelper: import("@ember/component/helper").FunctionBasedHelper<{
|
|
3
|
-
Args: {
|
|
4
|
-
Positional: [];
|
|
5
|
-
Named: {
|
|
6
|
-
max?: number | undefined;
|
|
7
|
-
min?: number | undefined;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
Return: Metadata;
|
|
11
|
-
}>;
|
|
12
|
-
export default CqHeightHelper;
|
|
13
|
-
//# sourceMappingURL=cq-height.d.ts.map
|
package/helpers/cq-width.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Metadata } from 'ember-container-query/modifiers/container-query';
|
|
2
|
-
declare const CqWidthHelper: import("@ember/component/helper").FunctionBasedHelper<{
|
|
3
|
-
Args: {
|
|
4
|
-
Positional: [];
|
|
5
|
-
Named: {
|
|
6
|
-
max?: number | undefined;
|
|
7
|
-
min?: number | undefined;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
Return: Metadata;
|
|
11
|
-
}>;
|
|
12
|
-
export default CqWidthHelper;
|
|
13
|
-
//# sourceMappingURL=cq-width.d.ts.map
|
package/index.js
DELETED
package/template-registry.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type ContainerQueryComponent from 'ember-container-query/components/container-query';
|
|
2
|
-
import type CqAspectRatioHelper from 'ember-container-query/helpers/cq-aspect-ratio';
|
|
3
|
-
import type CqHeightHelper from 'ember-container-query/helpers/cq-height';
|
|
4
|
-
import type CqWidthHelper from 'ember-container-query/helpers/cq-width';
|
|
5
|
-
import type ContainerQueryModifier from 'ember-container-query/modifiers/container-query';
|
|
6
|
-
export default interface EmberContainerQueryRegistry {
|
|
7
|
-
ContainerQuery: typeof ContainerQueryComponent;
|
|
8
|
-
'container-query': typeof ContainerQueryModifier;
|
|
9
|
-
'cq-aspect-ratio': typeof CqAspectRatioHelper;
|
|
10
|
-
'cq-height': typeof CqHeightHelper;
|
|
11
|
-
'cq-width': typeof CqWidthHelper;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=template-registry.d.ts.map
|
package/tsconfig.json
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@tsconfig/ember/tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
// Don't check the types of dependencies
|
|
5
|
-
"skipLibCheck": true,
|
|
6
|
-
|
|
7
|
-
// The combination of `baseUrl` with `paths` allows Ember's classic package
|
|
8
|
-
// layout, which is not resolveable with the Node resolution algorithm, to
|
|
9
|
-
// work with TypeScript.
|
|
10
|
-
"baseUrl": ".",
|
|
11
|
-
"paths": {
|
|
12
|
-
"dummy/tests/*": [
|
|
13
|
-
"tests/*"
|
|
14
|
-
],
|
|
15
|
-
"dummy/*": [
|
|
16
|
-
"tests/dummy/app/*",
|
|
17
|
-
"app/*"
|
|
18
|
-
],
|
|
19
|
-
"ember-container-query": [
|
|
20
|
-
"addon"
|
|
21
|
-
],
|
|
22
|
-
"ember-container-query/*": [
|
|
23
|
-
"addon/*"
|
|
24
|
-
],
|
|
25
|
-
"ember-container-query/test-support": [
|
|
26
|
-
"addon-test-support"
|
|
27
|
-
],
|
|
28
|
-
"ember-container-query/test-support/*": [
|
|
29
|
-
"addon-test-support/*"
|
|
30
|
-
],
|
|
31
|
-
"*": [
|
|
32
|
-
"types/*"
|
|
33
|
-
]
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
"include": [
|
|
37
|
-
"app/**/*",
|
|
38
|
-
"addon/**/*",
|
|
39
|
-
"tests/**/*",
|
|
40
|
-
"types/**/*",
|
|
41
|
-
"test-support/**/*",
|
|
42
|
-
"addon-test-support/**/*"
|
|
43
|
-
],
|
|
44
|
-
"glint": {
|
|
45
|
-
"environment": "ember-loose"
|
|
46
|
-
}
|
|
47
|
-
}
|
package/types/dummy/index.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
// Add any types here that you need for local development only.
|
|
2
|
-
// These will *not* be published as part of your addon, so be careful that your published code does not rely on them!
|
|
3
|
-
|
|
4
|
-
import '@glint/environment-ember-loose';
|
|
5
|
-
|
|
6
|
-
import SvgJarHelper from '@gavant/glint-template-types/types/ember-svg-jar/helpers/svg-jar';
|
|
7
|
-
import AndHelper from '@gavant/glint-template-types/types/ember-truth-helpers/helpers/and';
|
|
8
|
-
import OrHelper from '@gavant/glint-template-types/types/ember-truth-helpers/helpers/or';
|
|
9
|
-
import { ComponentLike, HelperLike } from '@glint/template';
|
|
10
|
-
import type EmberContainerQueryRegistry from 'ember-container-query/template-registry';
|
|
11
|
-
|
|
12
|
-
type NavigationNarratorComponent = ComponentLike<{
|
|
13
|
-
Args: {
|
|
14
|
-
skipTo: string;
|
|
15
|
-
};
|
|
16
|
-
}>;
|
|
17
|
-
|
|
18
|
-
type PageTitleHelper = HelperLike<{
|
|
19
|
-
Args: { Positional: [title: string] };
|
|
20
|
-
Return: void;
|
|
21
|
-
}>;
|
|
22
|
-
|
|
23
|
-
declare module '@glint/environment-ember-loose/registry' {
|
|
24
|
-
export default interface Registry extends EmberContainerQueryRegistry {
|
|
25
|
-
// Add any registry entries from other addons here that your addon itself uses (in non-strict mode templates)
|
|
26
|
-
// See https://typed-ember.gitbook.io/glint/using-glint/ember/using-addons
|
|
27
|
-
NavigationNarrator: NavigationNarratorComponent;
|
|
28
|
-
and: typeof AndHelper;
|
|
29
|
-
or: typeof OrHelper;
|
|
30
|
-
'page-title': PageTitleHelper;
|
|
31
|
-
'svg-jar': typeof SvgJarHelper;
|
|
32
|
-
}
|
|
33
|
-
}
|