@mlut/core 2.1.3 → 2.3.0

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,4 @@
1
+ export declare const fileURLToPath: typeof import("url").fileURLToPath;
1
2
  export declare class JitEngine {
2
3
  private utils;
3
4
  private breakpoints;
@@ -1,12 +1,23 @@
1
- import path from 'node:path';
2
- import { fileURLToPath } from 'node:url';
1
+ import { path } from '../utils/path.js';
3
2
  import { logger } from '../utils/index.js';
3
+ const isNode = globalThis.process?.env != undefined;
4
+ const isTestEnv = globalThis.process?.env?.NODE_ENV === 'test';
4
5
  const sass = await import('sass-embedded')
5
6
  .catch(() => import('sass'))
7
+ .catch(() => import('https://jspm.dev/sass'))
6
8
  .catch(() => {
7
9
  throw new Error('The Sass package is not installed. You can do this with `npm i -D sass-embedded`');
8
10
  });
9
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
11
+ const sassImporters = !isTestEnv && isNode ? [] :
12
+ await import('./importerFromMemory.js')
13
+ .then((r) => [r.importer])
14
+ .catch(() => []);
15
+ export const fileURLToPath = isNode ?
16
+ await import('node:url').then((r) => r.fileURLToPath) :
17
+ ((str) => str.toString());
18
+ const __dirname = isNode ?
19
+ path.dirname(fileURLToPath(import.meta.url)) :
20
+ globalThis.location?.origin ?? 'http://localhost';
10
21
  export class JitEngine {
11
22
  utils = new Set();
12
23
  breakpoints = [];
@@ -37,7 +48,9 @@ export class JitEngine {
37
48
  }
38
49
  let sassConfig = this.defaultSassConfig;
39
50
  if (inputPath && inputContent) {
40
- this.inputFileDir = path.dirname(path.resolve(process.cwd(), inputPath));
51
+ if (isNode) {
52
+ this.inputFileDir = path.dirname(path.resolve(process.cwd(), inputPath));
53
+ }
41
54
  this.inputFileCache = inputContent;
42
55
  sassConfig = this.extractUserSassConfig(inputContent);
43
56
  }
@@ -77,7 +90,11 @@ export class JitEngine {
77
90
  const sortedAtRuleUtils = atRuleUtils.flat().sort(this.compareUtilsWithAtRule);
78
91
  const allUniqueUtils = [...new Set(mainUtils.flat().concat(sortedAtRuleUtils))];
79
92
  const applyStr = `\n@include ${this.sassModuleName}.apply(${JSON.stringify(allUniqueUtils)},(),true);`;
80
- return sass.compileStringAsync(this.inputFileCache + applyStr, { loadPaths: [this.inputFileDir, 'node_modules'] }).then(({ css }) => css, (e) => (logger.error('Sass compilation error.', e), ''));
93
+ return sass.compileStringAsync(this.inputFileCache + applyStr, {
94
+ loadPaths: [this.inputFileDir, 'node_modules'],
95
+ importers: sassImporters,
96
+ silenceDeprecations: ['if-function',]
97
+ }).then(({ css }) => css, (e) => (logger.error('Sass compilation error.', e), ''));
81
98
  }
82
99
  extractUtils(content) {
83
100
  let fixedContent = content.replace(this.utilsRegexps.escapedQuotes, '');
@@ -168,6 +185,8 @@ export class JitEngine {
168
185
  const { css } = (await sass.compileStringAsync(userConfig + placeholderRules, {
169
186
  style: 'compressed',
170
187
  loadPaths: [__dirname, 'node_modules'],
188
+ importers: sassImporters,
189
+ silenceDeprecations: ['if-function',]
171
190
  }));
172
191
  const [, rawUtils, rawBreakpoints] = css.split('all:');
173
192
  const rawUtilsStrEnd = rawUtils.lastIndexOf('"') - rawUtils.length + 1;
@@ -0,0 +1,17 @@
1
+ declare global {
2
+ var mlut: {
3
+ githubToken?: string;
4
+ };
5
+ }
6
+ export declare class SassSourcesLoader {
7
+ private readonly kit;
8
+ private readonly owner;
9
+ private readonly repo;
10
+ private readonly unusedPath;
11
+ private readonly dirs;
12
+ readonly initPath = "packages/core/src/sass";
13
+ loadDir(dirPath: string): Promise<string[]>;
14
+ isDir(dirPath: string): boolean;
15
+ loadFile(filePath: string): Promise<string>;
16
+ }
17
+ export declare const sassSourcesLoader: SassSourcesLoader;
@@ -0,0 +1,58 @@
1
+ const retryPromise = import('https://esm.sh/@octokit/plugin-retry')
2
+ .catch(() => import('@octokit/plugin-retry'))
3
+ .then((r) => r.retry);
4
+ const octokit = await import('https://esm.sh/@octokit/rest')
5
+ .catch(() => import('@octokit/rest'))
6
+ .then(async (r) => {
7
+ const retry = await retryPromise;
8
+ const ctr = r.Octokit.plugin(retry);
9
+ return new ctr({
10
+ auth: globalThis.mlut?.githubToken ?? process.env.GITHUB_TOKEN,
11
+ });
12
+ });
13
+ export class SassSourcesLoader {
14
+ kit = octokit;
15
+ owner = 'mlutcss';
16
+ repo = 'mlut';
17
+ unusedPath = 'packages/core/src/sass/css/utils';
18
+ dirs = new Set();
19
+ initPath = 'packages/core/src/sass';
20
+ async loadDir(dirPath) {
21
+ if (dirPath.includes(this.unusedPath)) {
22
+ return [];
23
+ }
24
+ return this.kit.repos.getContent({
25
+ owner: this.owner,
26
+ repo: this.repo,
27
+ path: dirPath,
28
+ }).then((r) => {
29
+ if (!Array.isArray(r.data)) {
30
+ return [];
31
+ }
32
+ const result = [];
33
+ for (const item of r.data) {
34
+ if (item.type === 'dir') {
35
+ this.dirs.add(item.path);
36
+ }
37
+ result.push(item.name);
38
+ }
39
+ return result;
40
+ });
41
+ }
42
+ isDir(dirPath) {
43
+ return this.dirs.has(dirPath);
44
+ }
45
+ async loadFile(filePath) {
46
+ return this.kit.repos.getContent({
47
+ owner: this.owner,
48
+ repo: this.repo,
49
+ path: filePath,
50
+ }).then((r) => {
51
+ if (Array.isArray(r.data) || r.data.type !== 'file') {
52
+ return '';
53
+ }
54
+ return globalThis.atob(r.data.content);
55
+ });
56
+ }
57
+ }
58
+ export const sassSourcesLoader = new SassSourcesLoader();
@@ -0,0 +1,8 @@
1
+ import type { Importer, ImporterResult } from 'sass';
2
+ export declare class ModuleImporter implements Importer<'async'> {
3
+ private modules;
4
+ private aliases;
5
+ canonicalize: (initUrl: string) => URL | null;
6
+ load: (canonicalUrl: URL) => ImporterResult;
7
+ }
8
+ export declare const importer: ModuleImporter;
@@ -0,0 +1,66 @@
1
+ import { path } from '../utils/path.js';
2
+ import { sassSourcesLoader } from './SassSourcesLoader.js';
3
+ const locationOrigin = globalThis.location?.origin ?? 'http://localhost';
4
+ const sassIndexFileName = '_index.scss';
5
+ async function loadSourcesRecursive(loader) {
6
+ const result = new Map();
7
+ const pathPrefix = locationOrigin + '/';
8
+ const doLoadRecursive = async (entry, map) => {
9
+ const files = await loader.loadDir(entry);
10
+ await Promise.all(files.map(async (item) => {
11
+ const itemPath = path.join(entry, item);
12
+ const isDir = loader.isDir(itemPath);
13
+ if (isDir) {
14
+ await doLoadRecursive(itemPath, map);
15
+ }
16
+ else {
17
+ const pathObj = path.parse(itemPath);
18
+ if (pathObj.base !== sassIndexFileName && pathObj.base.startsWith('_')) {
19
+ pathObj.base = pathObj.base.slice(1);
20
+ }
21
+ const finalPath = pathPrefix + path.format(pathObj);
22
+ map.set(finalPath, (await loader.loadFile(itemPath)));
23
+ }
24
+ }));
25
+ return map;
26
+ };
27
+ return doLoadRecursive(sassSourcesLoader.initPath, result);
28
+ }
29
+ const modulesMap = await loadSourcesRecursive(sassSourcesLoader);
30
+ export class ModuleImporter {
31
+ modules = modulesMap;
32
+ aliases = {
33
+ '@mlut/core': '../sass/index',
34
+ '@mlut/core/tools': '../sass/tools',
35
+ };
36
+ canonicalize = (initUrl) => {
37
+ let url = initUrl;
38
+ if (!url.includes('/sass/')) {
39
+ if (url in this.aliases) {
40
+ url = this.aliases[url];
41
+ }
42
+ else if (!url.startsWith('@mlut/core')) {
43
+ return null;
44
+ }
45
+ }
46
+ const isEntryUrl = !url.startsWith('http');
47
+ let newUrl = url + '.scss';
48
+ if (isEntryUrl) {
49
+ newUrl = new URL(path.join(locationOrigin, sassSourcesLoader.initPath, url.split('sass')[1]) + '.scss').href;
50
+ }
51
+ if (!this.modules.has(newUrl)) {
52
+ newUrl = path.join(newUrl.replace('.scss', ''), sassIndexFileName);
53
+ }
54
+ return new URL(newUrl);
55
+ };
56
+ load = (canonicalUrl) => {
57
+ if (!this.modules.has(canonicalUrl.href)) {
58
+ throw new Error('Unknown module');
59
+ }
60
+ return {
61
+ contents: this.modules.get(canonicalUrl.href),
62
+ syntax: 'scss'
63
+ };
64
+ };
65
+ }
66
+ export const importer = new ModuleImporter();
@@ -575,6 +575,27 @@ $utils-db: (
575
575
  ),
576
576
  ),
577
577
  'Txuo': text-underline-offset,
578
+ 'Txwm': (
579
+ 'properties': text-wrap-mode,
580
+ 'keywords': (
581
+ '': nowrap,
582
+ 'w': wrap,
583
+ 'n': nowrap,
584
+ ),
585
+ ),
586
+ 'Txws': (
587
+ 'properties': text-wrap-style,
588
+ 'keywords': (
589
+ 'b': balance,
590
+ 's': stable,
591
+ 'p': pretty,
592
+ ),
593
+ ),
594
+ 'Txw': (
595
+ 'properties': text-wrap,
596
+ 'keywords': (Txwm, Txws),
597
+ ),
598
+
578
599
  'Txi': (
579
600
  'properties': text-indent,
580
601
  'keywords': (
@@ -726,6 +747,7 @@ $utils-db: (
726
747
  ),
727
748
  'Bgr': (
728
749
  'properties': background-repeat,
750
+ 'multi-list-separator': ml.$tULs1,
729
751
  'keywords': (
730
752
  '': no-repeat,
731
753
  'nr': no-repeat,
@@ -738,10 +760,12 @@ $utils-db: (
738
760
  ),
739
761
  'Bgp': (
740
762
  'properties': background-position,
763
+ 'multi-list-separator': ml.$tULs1,
741
764
  'keywords': 'position'
742
765
  ),
743
766
  'Bgs': (
744
767
  'properties': background-size,
768
+ 'multi-list-separator': ml.$tULs1,
745
769
  'keywords': (
746
770
  'ct': contain,
747
771
  'cv': cover,
@@ -749,21 +773,30 @@ $utils-db: (
749
773
  ),
750
774
  'Bga': (
751
775
  'properties': background-attachment,
776
+ 'multi-list-separator': ml.$tULs1,
752
777
  'keywords': (
753
778
  'f': fixed,
754
779
  'l': local,
755
780
  's': scroll,
756
781
  ),
757
782
  ),
783
+ 'Bgbm': (
784
+ 'properties': background-blend-mode,
785
+ 'keywords': 'blend-mode',
786
+ 'multi-list-separator': ml.$tULs1,
787
+ ),
758
788
  'Bgcl': (
759
789
  'properties': background-clip,
790
+ 'multi-list-separator': ml.$tULs1,
760
791
  'keywords': 'box-ext',
761
792
  ),
762
793
  'Bgo': (
763
794
  'properties': background-origin,
795
+ 'multi-list-separator': ml.$tULs1,
764
796
  'keywords': 'box-ext',
765
797
  ),
766
798
  'Bgi': (
799
+ 'multi-list-separator': ml.$tULs1,
767
800
  'properties': background-image,
768
801
  ),
769
802
  '-Gdl': (
@@ -1373,6 +1406,15 @@ $utils-db: (
1373
1406
  'multi-list-separator': ml.$tULs1,
1374
1407
  'keywords': 'transition-props'
1375
1408
  ),
1409
+ 'Tsb':(
1410
+ 'properties':'transition-behavior',
1411
+ 'multi-list-separator':ml.$tULs1,
1412
+ 'keywords':(
1413
+ '': allow-discrete,
1414
+ 'n': normal,
1415
+ 'ad': allow-discrete,
1416
+ ),
1417
+ ),
1376
1418
  'Tsd': (
1377
1419
  'properties': transition-duration,
1378
1420
  'multi-list-separator': ml.$tULs1,
@@ -1470,6 +1512,10 @@ $utils-db: (
1470
1512
  '': none,
1471
1513
  ),
1472
1514
  ),
1515
+ 'Mibm': (
1516
+ 'properties': mix-blend-mode,
1517
+ 'keywords': 'blend-mode'
1518
+ ),
1473
1519
  'Us': (
1474
1520
  'properties': user-select,
1475
1521
  'keywords': (
@@ -1712,6 +1758,26 @@ $utils-db: (
1712
1758
  'pb': padding-box,
1713
1759
  't': text,
1714
1760
  ),
1761
+ 'blend-mode': (
1762
+ 'n': normal,
1763
+ 'm': multiply,
1764
+ 's': screen,
1765
+ 'o': overlay,
1766
+ 'd': darken,
1767
+ 'l': lighten,
1768
+ 'cd': color-dodge,
1769
+ 'cb': color-burn,
1770
+ 'hrl': hard-light,
1771
+ 'sfl': soft-light,
1772
+ 'e': exclusion,
1773
+ 'h': hue,
1774
+ 'st': saturation,
1775
+ 'c': color,
1776
+ 'lm': luminosity,
1777
+ 'pl': plus-lighter,
1778
+ 'pd': plus-darker,
1779
+
1780
+ ),
1715
1781
  'grid-area': (
1716
1782
  's': span,
1717
1783
  ),
@@ -0,0 +1,2 @@
1
+ import type { PlatformPath } from 'node:path';
2
+ export declare const path: PlatformPath;
@@ -0,0 +1,3 @@
1
+ export const path = await import('https://esm.sh/path-browserify-esm')
2
+ .catch(() => import('node:path'))
3
+ .then((r) => r.default);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mlut/core",
3
- "version": "2.1.3",
3
+ "version": "2.3.0",
4
4
  "description": "Atomic CSS toolkit with Sass and ergonomics for creating styles of any complexity",
5
5
  "author": "mr150",
6
6
  "type": "module",
@@ -40,9 +40,12 @@
40
40
  "dist"
41
41
  ],
42
42
  "devDependencies": {
43
+ "@octokit/plugin-retry": "^8.0.1",
44
+ "@octokit/rest": "^22.0.0",
43
45
  "@types/node": "^20.10.5",
46
+ "path-browserify-esm": "^1.0.6",
44
47
  "sass": "^1.93.0",
45
48
  "sass-embedded": "^1.93.0",
46
- "typescript": "^4.8.0"
49
+ "typescript": "^5.8.0"
47
50
  }
48
51
  }