@cocreate/plugins 1.0.3 → 1.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.1.1](https://github.com/CoCreate-app/CoCreate-plugins/compare/v1.1.0...v1.1.1) (2026-02-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * change init function to default export and update parameter handling ([654b623](https://github.com/CoCreate-app/CoCreate-plugins/commit/654b623760446cbd9db55cc216e25a07fe7865e3))
7
+
8
+ # [1.1.0](https://github.com/CoCreate-app/CoCreate-plugins/compare/v1.0.3...v1.1.0) (2026-01-15)
9
+
10
+
11
+ ### Features
12
+
13
+ * add marker to indicate where css files will be inserted ([6b4b030](https://github.com/CoCreate-app/CoCreate-plugins/commit/6b4b0301acdabff19b8cca5968cc67619e417c92))
14
+
1
15
  ## [1.0.3](https://github.com/CoCreate-app/CoCreate-plugins/compare/v1.0.2...v1.0.3) (2025-12-26)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/plugins",
3
- "version": "1.0.3",
3
+ "version": "1.1.1",
4
4
  "description": "CoCreate plugins",
5
5
  "author": "CoCreate LLC",
6
6
  "license": "AGPL-3.0",
package/src/index.js CHANGED
@@ -172,13 +172,15 @@ const plugins = {
172
172
 
173
173
  // Global Cache for script promises to prevent race conditions and duplicate loads
174
174
  const scriptCache = new Map();
175
+ // Cache the CSS marker once on load
176
+ const cssMarker = typeof document !== 'undefined' ? document.querySelector('link[plugins]') : null;
175
177
 
176
178
  /**
177
179
  * Global Initialization Function
178
180
  * Processes one or more elements to attach plugins.
179
181
  * @param {HTMLElement|NodeList|Array} elements - Element, or Collection of Elements
180
182
  */
181
- export function init(elements) {
183
+ function init(elements) {
182
184
  if (!elements) return;
183
185
 
184
186
  let collection = [];
@@ -211,7 +213,29 @@ async function processPlugin(el) {
211
213
  if (pluginDef.css) pluginDef.css.forEach(href => {
212
214
  if (!document.querySelector(`link[href="${href}"]`)) {
213
215
  const link = document.createElement("link");
214
- link.rel = "stylesheet"; link.href = href; document.head.appendChild(link);
216
+ link.rel = "stylesheet";
217
+ link.href = href;
218
+
219
+ // CSS INJECTION STRATEGY:
220
+ // 1. Priority: Check for a specific marker element <link plugin>
221
+ // (Cached globally in cssMarker)
222
+
223
+ if (cssMarker) {
224
+ // Insert before the marker
225
+ cssMarker.parentNode.insertBefore(link, cssMarker);
226
+ } else {
227
+ // 2. Fallback: Prepend before existing CSS
228
+ // To allow custom CSS to easily override plugin defaults, we must ensure
229
+ // plugin CSS loads BEFORE user CSS.
230
+ const firstStyle = document.head.querySelector('link[rel="stylesheet"], style');
231
+
232
+ if (firstStyle) {
233
+ document.head.insertBefore(link, firstStyle);
234
+ } else {
235
+ // If no CSS exists yet, appending is safe
236
+ document.head.appendChild(link);
237
+ }
238
+ }
215
239
  }
216
240
  });
217
241
 
@@ -327,10 +351,10 @@ function executeGenericPlugin(el, name) {
327
351
  * - $anime.stagger(100)
328
352
  */
329
353
  function processParams(el, params) {
330
- if (typeof params === 'string' && params.startsWith('$')) {
354
+ if (typeof params === 'string' && params.startsWith('\u0024')) {
331
355
  try {
332
356
  // 1. Check for Method Call: $root.path.to.func(arg)
333
- const callMatch = params.match(/^\$([^.]+)\.(.+)\((.*)\)$/);
357
+ const callMatch = params.match(/^\u0024([^.]+)\.(.+)\((.*)\)$/);
334
358
  if (callMatch) {
335
359
  const [_, root, path, arg] = callMatch;
336
360
  const obj = (root === 'this') ? el : window[root];
@@ -347,7 +371,7 @@ function processParams(el, params) {
347
371
  }
348
372
 
349
373
  // 2. Check for Property Access: $root.path.to.prop or just $root
350
- const propMatch = params.match(/^\$([^.]+)(?:\.(.+))?$/);
374
+ const propMatch = params.match(/^\u0024([^.]+)(?:\.(.+))?$/);
351
375
  if (propMatch) {
352
376
  const [_, root, path] = propMatch;
353
377
  const obj = (root === 'this') ? el : window[root];
@@ -386,4 +410,6 @@ Observer.init({
386
410
  // Auto-init for existing elements
387
411
  if (typeof document !== 'undefined') {
388
412
  init(document.querySelectorAll("[plugin]"));
389
- }
413
+ }
414
+
415
+ export default { init }