@symbo.ls/shorthand 3.8.9 → 3.14.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.
package/dist/cjs/index.js CHANGED
@@ -30,6 +30,7 @@ __export(index_exports, {
30
30
  parseFurther: () => import_further.parseFurther,
31
31
  propToAbbr: () => import_registry.propToAbbr,
32
32
  shorten: () => import_encode.shorten,
33
+ shorthandPlugin: () => import_plugin.shorthandPlugin,
33
34
  stringify: () => import_encode.stringify,
34
35
  stringifyFurther: () => import_further.stringifyFurther
35
36
  });
@@ -37,4 +38,5 @@ module.exports = __toCommonJS(index_exports);
37
38
  var import_encode = require("./encode.js");
38
39
  var import_decode = require("./decode.js");
39
40
  var import_further = require("./further.js");
41
+ var import_plugin = require("./plugin.js");
40
42
  var import_registry = require("./registry.js");
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var plugin_exports = {};
20
+ __export(plugin_exports, {
21
+ shorthandPlugin: () => shorthandPlugin
22
+ });
23
+ module.exports = __toCommonJS(plugin_exports);
24
+ var import_decode = require("./decode.js");
25
+ var import_further = require("./further.js");
26
+ const EXPAND_MODES = {
27
+ shorten: import_decode.expand,
28
+ stringify: import_decode.parse,
29
+ stringifyFurther: import_further.parseFurther
30
+ };
31
+ function expandSection(section, decoder) {
32
+ if (!section || typeof section !== "object") return section;
33
+ if (Array.isArray(section)) return section.map((item) => decoder(item));
34
+ const out = {};
35
+ for (const key in section) {
36
+ const val = section[key];
37
+ out[key] = val && typeof val === "object" ? decoder(val) : val;
38
+ }
39
+ return out;
40
+ }
41
+ const EXPANDABLE_SECTIONS = ["components", "pages", "snippets"];
42
+ const shorthandPlugin = {
43
+ name: "shorthand",
44
+ /**
45
+ * Called during prepareContext to expand shorthand data in-place.
46
+ * This is not a standard lifecycle hook — it's invoked explicitly
47
+ * by createDomql's prepareContext.
48
+ */
49
+ prepareContext(context) {
50
+ const mode = context.shorthand;
51
+ if (!mode) return;
52
+ const decoderKey = mode === true ? "shorten" : mode;
53
+ const decoder = EXPAND_MODES[decoderKey];
54
+ if (!decoder) return;
55
+ for (const section of EXPANDABLE_SECTIONS) {
56
+ if (context[section]) {
57
+ context[section] = expandSection(context[section], decoder);
58
+ }
59
+ }
60
+ if (context.app && typeof context.app === "object") {
61
+ context.app = decoder(context.app);
62
+ }
63
+ }
64
+ };
@@ -42,7 +42,7 @@ const propToAbbr = {
42
42
  hide: "hd",
43
43
  html: "htm",
44
44
  if: "if",
45
- ignoreChildExtend: "icex",
45
+ ignoreChildExtends: "icex",
46
46
  key: "ky",
47
47
  query: "qy",
48
48
  routes: "rt",
package/dist/esm/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { encode, shorten, stringify } from "./encode.js";
2
2
  import { decode, expand, parse } from "./decode.js";
3
3
  import { stringifyFurther, parseFurther } from "./further.js";
4
+ import { shorthandPlugin } from "./plugin.js";
4
5
  import {
5
6
  propToAbbr,
6
7
  abbrToProp,
@@ -22,6 +23,7 @@ export {
22
23
  parseFurther,
23
24
  propToAbbr,
24
25
  shorten,
26
+ shorthandPlugin,
25
27
  stringify,
26
28
  stringifyFurther
27
29
  };
@@ -0,0 +1,44 @@
1
+ import { expand, parse } from "./decode.js";
2
+ import { parseFurther } from "./further.js";
3
+ const EXPAND_MODES = {
4
+ shorten: expand,
5
+ stringify: parse,
6
+ stringifyFurther: parseFurther
7
+ };
8
+ function expandSection(section, decoder) {
9
+ if (!section || typeof section !== "object") return section;
10
+ if (Array.isArray(section)) return section.map((item) => decoder(item));
11
+ const out = {};
12
+ for (const key in section) {
13
+ const val = section[key];
14
+ out[key] = val && typeof val === "object" ? decoder(val) : val;
15
+ }
16
+ return out;
17
+ }
18
+ const EXPANDABLE_SECTIONS = ["components", "pages", "snippets"];
19
+ const shorthandPlugin = {
20
+ name: "shorthand",
21
+ /**
22
+ * Called during prepareContext to expand shorthand data in-place.
23
+ * This is not a standard lifecycle hook — it's invoked explicitly
24
+ * by createDomql's prepareContext.
25
+ */
26
+ prepareContext(context) {
27
+ const mode = context.shorthand;
28
+ if (!mode) return;
29
+ const decoderKey = mode === true ? "shorten" : mode;
30
+ const decoder = EXPAND_MODES[decoderKey];
31
+ if (!decoder) return;
32
+ for (const section of EXPANDABLE_SECTIONS) {
33
+ if (context[section]) {
34
+ context[section] = expandSection(context[section], decoder);
35
+ }
36
+ }
37
+ if (context.app && typeof context.app === "object") {
38
+ context.app = decoder(context.app);
39
+ }
40
+ }
41
+ };
42
+ export {
43
+ shorthandPlugin
44
+ };
@@ -14,7 +14,7 @@ const propToAbbr = {
14
14
  hide: "hd",
15
15
  html: "htm",
16
16
  if: "if",
17
- ignoreChildExtend: "icex",
17
+ ignoreChildExtends: "icex",
18
18
  key: "ky",
19
19
  query: "qy",
20
20
  routes: "rt",
@@ -33,6 +33,7 @@ var SmblsShorthand = (() => {
33
33
  parseFurther: () => parseFurther,
34
34
  propToAbbr: () => propToAbbr,
35
35
  shorten: () => shorten,
36
+ shorthandPlugin: () => shorthandPlugin,
36
37
  stringify: () => stringify,
37
38
  stringifyFurther: () => stringifyFurther
38
39
  });
@@ -54,7 +55,7 @@ var SmblsShorthand = (() => {
54
55
  hide: "hd",
55
56
  html: "htm",
56
57
  if: "if",
57
- ignoreChildExtend: "icex",
58
+ ignoreChildExtends: "icex",
58
59
  key: "ky",
59
60
  query: "qy",
60
61
  routes: "rt",
@@ -1176,5 +1177,46 @@ var SmblsShorthand = (() => {
1176
1177
  if (typeof val === "object") return parseFurther(val);
1177
1178
  return val;
1178
1179
  }
1180
+
1181
+ // src/plugin.js
1182
+ var EXPAND_MODES = {
1183
+ shorten: expand,
1184
+ stringify: parse,
1185
+ stringifyFurther: parseFurther
1186
+ };
1187
+ function expandSection(section, decoder) {
1188
+ if (!section || typeof section !== "object") return section;
1189
+ if (Array.isArray(section)) return section.map((item) => decoder(item));
1190
+ const out = {};
1191
+ for (const key in section) {
1192
+ const val = section[key];
1193
+ out[key] = val && typeof val === "object" ? decoder(val) : val;
1194
+ }
1195
+ return out;
1196
+ }
1197
+ var EXPANDABLE_SECTIONS = ["components", "pages", "snippets"];
1198
+ var shorthandPlugin = {
1199
+ name: "shorthand",
1200
+ /**
1201
+ * Called during prepareContext to expand shorthand data in-place.
1202
+ * This is not a standard lifecycle hook — it's invoked explicitly
1203
+ * by createDomql's prepareContext.
1204
+ */
1205
+ prepareContext(context) {
1206
+ const mode = context.shorthand;
1207
+ if (!mode) return;
1208
+ const decoderKey = mode === true ? "shorten" : mode;
1209
+ const decoder = EXPAND_MODES[decoderKey];
1210
+ if (!decoder) return;
1211
+ for (const section of EXPANDABLE_SECTIONS) {
1212
+ if (context[section]) {
1213
+ context[section] = expandSection(context[section], decoder);
1214
+ }
1215
+ }
1216
+ if (context.app && typeof context.app === "object") {
1217
+ context.app = decoder(context.app);
1218
+ }
1219
+ }
1220
+ };
1179
1221
  return __toCommonJS(index_exports);
1180
1222
  })();
package/package.json CHANGED
@@ -2,16 +2,14 @@
2
2
  "name": "@symbo.ls/shorthand",
3
3
  "description": "Shorthand syntax transpiler for Symbols properties",
4
4
  "author": "symbo.ls",
5
- "version": "3.8.9",
5
+ "version": "3.14.0",
6
6
  "repository": "https://github.com/symbo-ls/smbls",
7
7
  "type": "module",
8
- "module": "./dist/esm/index.js",
9
- "main": "./dist/cjs/index.js",
8
+ "module": "./src/index.js",
9
+ "main": "./src/index.js",
10
10
  "exports": {
11
- ".": {
12
- "import": "./dist/esm/index.js",
13
- "require": "./dist/cjs/index.js"
14
- }
11
+ ".": "./src/index.js",
12
+ "./package.json": "./package.json"
15
13
  },
16
14
  "source": "src/index.js",
17
15
  "publishConfig": {
@@ -20,11 +18,11 @@
20
18
  "scripts": {
21
19
  "test": "node --experimental-vm-modules ../../node_modules/.bin/jest",
22
20
  "copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
23
- "build:cjs": "cross-env NODE_ENV=$NODE_ENV esbuild src/*.js --target=node18 --format=cjs --outdir=dist/cjs --define:process.env.NODE_ENV=process.env.NODE_ENV",
21
+ "build:cjs": "NODE_ENV=$NODE_ENV esbuild src/*.js --target=node18 --format=cjs --outdir=dist/cjs --define:process.env.NODE_ENV=process.env.NODE_ENV",
24
22
  "build": "node ../../build/build.js",
25
23
  "prepublish": "npm run build && npm run copy:package:cjs",
26
- "build:esm": "cross-env NODE_ENV=$NODE_ENV esbuild src/*.js --target=es2020 --format=esm --outdir=dist/esm --define:process.env.NODE_ENV=process.env.NODE_ENV",
27
- "build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild src/index.js --bundle --target=es2020 --format=iife --global-name=SmblsShorthand --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV"
24
+ "build:esm": "NODE_ENV=$NODE_ENV esbuild src/*.js --target=es2020 --format=esm --outdir=dist/esm --define:process.env.NODE_ENV=process.env.NODE_ENV",
25
+ "build:iife": "NODE_ENV=$NODE_ENV esbuild src/index.js --bundle --target=es2020 --format=iife --global-name=SmblsShorthand --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV"
28
26
  },
29
27
  "files": [
30
28
  "dist",
@@ -33,7 +31,7 @@
33
31
  ],
34
32
  "license": "CC-BY-NC-4.0",
35
33
  "gitHead": "0be12bcdd99c265fdeded6d756a1a3616a943ffc",
36
- "browser": "./dist/esm/index.js",
34
+ "browser": "./src/index.js",
37
35
  "unpkg": "./dist/iife/index.js",
38
36
  "jsdelivr": "./dist/iife/index.js",
39
37
  "sideEffects": false
package/src/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  export { encode, shorten, stringify } from './encode.js'
4
4
  export { decode, expand, parse } from './decode.js'
5
5
  export { stringifyFurther, parseFurther } from './further.js'
6
+ export { shorthandPlugin } from './plugin.js'
6
7
  export {
7
8
  propToAbbr,
8
9
  abbrToProp,
package/src/plugin.js ADDED
@@ -0,0 +1,75 @@
1
+ 'use strict'
2
+
3
+ import { expand, parse } from './decode.js'
4
+ import { parseFurther } from './further.js'
5
+
6
+ const EXPAND_MODES = {
7
+ shorten: expand,
8
+ stringify: parse,
9
+ stringifyFurther: parseFurther
10
+ }
11
+
12
+ /**
13
+ * Expand shorthand keys/values on a section of the context.
14
+ * Walks every top-level entry and applies the decoder.
15
+ */
16
+ function expandSection (section, decoder) {
17
+ if (!section || typeof section !== 'object') return section
18
+ if (Array.isArray(section)) return section.map(item => decoder(item))
19
+ const out = {}
20
+ for (const key in section) {
21
+ const val = section[key]
22
+ out[key] = val && typeof val === 'object' ? decoder(val) : val
23
+ }
24
+ return out
25
+ }
26
+
27
+ /**
28
+ * Sections of the context that contain component-like objects
29
+ * and should be expanded at runtime.
30
+ */
31
+ const EXPANDABLE_SECTIONS = ['components', 'pages', 'snippets']
32
+
33
+ /**
34
+ * Shorthand runtime plugin for smbls.
35
+ *
36
+ * When context.shorthand is set, this plugin expands abbreviated
37
+ * property names back to their full form before the framework
38
+ * processes them.
39
+ *
40
+ * context.shorthand can be:
41
+ * - true or 'shorten' → expand abbreviated keys (inverse of shorten())
42
+ * - 'stringify' → parse inline `in` strings (inverse of stringify())
43
+ * - 'stringifyFurther' → parse further-compressed form (inverse of stringifyFurther())
44
+ *
45
+ * The expansion runs once in prepareContext via the plugin's `prepareContext` hook,
46
+ * so individual element creation pays no per-element cost.
47
+ */
48
+ export const shorthandPlugin = {
49
+ name: 'shorthand',
50
+
51
+ /**
52
+ * Called during prepareContext to expand shorthand data in-place.
53
+ * This is not a standard lifecycle hook — it's invoked explicitly
54
+ * by createDomql's prepareContext.
55
+ */
56
+ prepareContext (context) {
57
+ const mode = context.shorthand
58
+ if (!mode) return
59
+
60
+ const decoderKey = mode === true ? 'shorten' : mode
61
+ const decoder = EXPAND_MODES[decoderKey]
62
+ if (!decoder) return
63
+
64
+ for (const section of EXPANDABLE_SECTIONS) {
65
+ if (context[section]) {
66
+ context[section] = expandSection(context[section], decoder)
67
+ }
68
+ }
69
+
70
+ // Expand app-level element if present
71
+ if (context.app && typeof context.app === 'object') {
72
+ context.app = decoder(context.app)
73
+ }
74
+ }
75
+ }
package/src/registry.js CHANGED
@@ -23,7 +23,7 @@ const propToAbbr = {
23
23
  hide: 'hd',
24
24
  html: 'htm',
25
25
  if: 'if',
26
- ignoreChildExtend: 'icex',
26
+ ignoreChildExtends: 'icex',
27
27
  key: 'ky',
28
28
  query: 'qy',
29
29
  routes: 'rt',