typewritingclass 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -138,16 +138,53 @@ function _cxCore(args) {
138
138
  }
139
139
  function warnConflicts(args) {
140
140
  const seen = /* @__PURE__ */ new Map();
141
+ const seenDeclCount = /* @__PURE__ */ new Map();
142
+ const warned = /* @__PURE__ */ new Set();
143
+ const propContexts = /* @__PURE__ */ new Map();
141
144
  for (let i = 0; i < args.length; i++) {
142
145
  const arg = args[i];
143
146
  if (typeof arg === "string" || typeof arg === "function") continue;
144
- for (const prop of Object.keys(arg.declarations)) {
145
- if (seen.has(prop)) {
146
- console.warn(
147
- `[typewritingclass] cx() conflict: "${prop}" is set by arguments at index ${seen.get(prop)} and ${i}. The later value will override. If intentional, this warning can be ignored.`
148
- );
147
+ const context = arg.mediaQueries.join("|") + "::" + arg.selectors.join("|");
148
+ const declKeys = Object.keys(arg.declarations);
149
+ for (const prop of declKeys) {
150
+ const key = context + "::" + prop;
151
+ if (seen.has(key)) {
152
+ const earlierCount = seenDeclCount.get(key);
153
+ if (earlierCount > 1 && declKeys.length === 1) {
154
+ seen.set(key, i);
155
+ seenDeclCount.set(key, declKeys.length);
156
+ continue;
157
+ }
158
+ const msg = `[typewritingclass] cx() conflict: "${prop}" is set by arguments at index ${seen.get(key)} and ${i}. The later value will override. If intentional, this warning can be ignored.`;
159
+ if (!warned.has(msg)) {
160
+ warned.add(msg);
161
+ console.warn(msg);
162
+ }
163
+ }
164
+ seen.set(key, i);
165
+ seenDeclCount.set(key, declKeys.length);
166
+ if (!propContexts.has(prop)) propContexts.set(prop, []);
167
+ propContexts.get(prop).push({ context, index: i, mediaQueries: arg.mediaQueries });
168
+ }
169
+ }
170
+ for (const [prop, entries] of propContexts) {
171
+ for (let j = 1; j < entries.length; j++) {
172
+ const later = entries[j];
173
+ if (later.mediaQueries.length === 0) continue;
174
+ for (let k = 0; k < j; k++) {
175
+ const earlier = entries[k];
176
+ if (earlier.context === later.context) continue;
177
+ if (earlier.mediaQueries.length === 0) continue;
178
+ const earlierSet = new Set(earlier.mediaQueries);
179
+ const laterSet = new Set(later.mediaQueries);
180
+ const isSubset = [...laterSet].every((q) => earlierSet.has(q)) || [...earlierSet].every((q) => laterSet.has(q));
181
+ if (isSubset) continue;
182
+ const msg = `[typewritingclass] cx() cascade hazard: "${prop}" is set by arg ${earlier.index} (${earlier.mediaQueries.join(" + ")}) and arg ${later.index} (${later.mediaQueries.join(" + ")}). When both queries match, arg ${later.index} wins due to source order. To fix, combine them: .sm(tw.dark(...)) instead of separate .sm(...).dark(...).`;
183
+ if (!warned.has(msg)) {
184
+ warned.add(msg);
185
+ console.warn(msg);
186
+ }
149
187
  }
150
- seen.set(prop, i);
151
188
  }
152
189
  }
153
190
  }
package/dist/index.js CHANGED
@@ -138,16 +138,53 @@ function _cxCore(args) {
138
138
  }
139
139
  function warnConflicts(args) {
140
140
  const seen = /* @__PURE__ */ new Map();
141
+ const seenDeclCount = /* @__PURE__ */ new Map();
142
+ const warned = /* @__PURE__ */ new Set();
143
+ const propContexts = /* @__PURE__ */ new Map();
141
144
  for (let i = 0; i < args.length; i++) {
142
145
  const arg = args[i];
143
146
  if (typeof arg === "string" || typeof arg === "function") continue;
144
- for (const prop of Object.keys(arg.declarations)) {
145
- if (seen.has(prop)) {
146
- console.warn(
147
- `[typewritingclass] cx() conflict: "${prop}" is set by arguments at index ${seen.get(prop)} and ${i}. The later value will override. If intentional, this warning can be ignored.`
148
- );
147
+ const context = arg.mediaQueries.join("|") + "::" + arg.selectors.join("|");
148
+ const declKeys = Object.keys(arg.declarations);
149
+ for (const prop of declKeys) {
150
+ const key = context + "::" + prop;
151
+ if (seen.has(key)) {
152
+ const earlierCount = seenDeclCount.get(key);
153
+ if (earlierCount > 1 && declKeys.length === 1) {
154
+ seen.set(key, i);
155
+ seenDeclCount.set(key, declKeys.length);
156
+ continue;
157
+ }
158
+ const msg = `[typewritingclass] cx() conflict: "${prop}" is set by arguments at index ${seen.get(key)} and ${i}. The later value will override. If intentional, this warning can be ignored.`;
159
+ if (!warned.has(msg)) {
160
+ warned.add(msg);
161
+ console.warn(msg);
162
+ }
163
+ }
164
+ seen.set(key, i);
165
+ seenDeclCount.set(key, declKeys.length);
166
+ if (!propContexts.has(prop)) propContexts.set(prop, []);
167
+ propContexts.get(prop).push({ context, index: i, mediaQueries: arg.mediaQueries });
168
+ }
169
+ }
170
+ for (const [prop, entries] of propContexts) {
171
+ for (let j = 1; j < entries.length; j++) {
172
+ const later = entries[j];
173
+ if (later.mediaQueries.length === 0) continue;
174
+ for (let k = 0; k < j; k++) {
175
+ const earlier = entries[k];
176
+ if (earlier.context === later.context) continue;
177
+ if (earlier.mediaQueries.length === 0) continue;
178
+ const earlierSet = new Set(earlier.mediaQueries);
179
+ const laterSet = new Set(later.mediaQueries);
180
+ const isSubset = [...laterSet].every((q) => earlierSet.has(q)) || [...earlierSet].every((q) => laterSet.has(q));
181
+ if (isSubset) continue;
182
+ const msg = `[typewritingclass] cx() cascade hazard: "${prop}" is set by arg ${earlier.index} (${earlier.mediaQueries.join(" + ")}) and arg ${later.index} (${later.mediaQueries.join(" + ")}). When both queries match, arg ${later.index} wins due to source order. To fix, combine them: .sm(tw.dark(...)) instead of separate .sm(...).dark(...).`;
183
+ if (!warned.has(msg)) {
184
+ warned.add(msg);
185
+ console.warn(msg);
186
+ }
149
187
  }
150
- seen.set(prop, i);
151
188
  }
152
189
  }
153
190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typewritingclass",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",