Skip to content

Commit

Permalink
another attempts at module packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
1cg committed Dec 19, 2023
1 parent d343318 commit 6cc541f
Show file tree
Hide file tree
Showing 11 changed files with 4,059 additions and 1,394 deletions.
1,416 changes: 741 additions & 675 deletions dist/idiomorph-ext.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/idiomorph-ext.min.js

Large diffs are not rendered by default.

28 changes: 20 additions & 8 deletions dist/idiomorph-htmx.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
htmx.defineExtension('morph', {
isInlineSwap: function(swapStyle) {
return swapStyle === 'morph';
},
handleSwap: function (swapStyle, target, fragment) {
(function(){
function createMorphConfig(swapStyle) {
if (swapStyle === 'morph' || swapStyle === 'morph:outerHTML') {
return Idiomorph.morph(target, fragment.children);
return {morphStyle: 'outerHTML'}
} else if (swapStyle === 'morph:innerHTML') {
return Idiomorph.morph(target, fragment.children, {morphStyle:'innerHTML'});
return {morphStyle: 'innerHTML'}
} else if (swapStyle.startsWith("morph:")) {
return Function("return (" + swapStyle.slice(6) + ")")();
}
}
});

htmx.defineExtension('morph', {
isInlineSwap: function(swapStyle) {
let config = createMorphConfig(swapStyle);
return config.swapStyle === "outerHTML" || config.swapStyle == null;
},
handleSwap: function (swapStyle, target, fragment) {
let config = createMorphConfig(swapStyle);
if (config) {
return Idiomorph.morph(target, fragment.children, config);
}
}
});
})()
850 changes: 850 additions & 0 deletions dist/idiomorph.amd.js

Large diffs are not rendered by default.

850 changes: 850 additions & 0 deletions dist/idiomorph.cjs.js

Large diffs are not rendered by default.

850 changes: 850 additions & 0 deletions dist/idiomorph.esm.js

Large diffs are not rendered by default.

1,422 changes: 738 additions & 684 deletions dist/idiomorph.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/idiomorph.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/idiomorph.min.js.gz
Binary file not shown.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
"unpkg": "dist/idiomorph.min.js",
"scripts": {
"test": "mocha-chrome test/index.html",
"dist": "cp -r src/* dist/ && cat src/idiomorph.js src/idiomorph-htmx.js > dist/idiomorph-ext.js && npm run-script uglify && gzip -9 -k -f dist/idiomorph.min.js > dist/idiomorph.min.js.gz && exit",
"amd" : "(cat src/idiomorph.js && echo \"\ndefine([], Idiomorph);\") > dist/idiomorph.amd.js",
"cjs" : "(cat src/idiomorph.js && echo \"\nmodule.exports = Idiomorph;\") > dist/idiomorph.cjs.js",
"esm" : "(cat src/idiomorph.js && echo \"\nexport default {Idiomorph};\") > dist/idiomorph.esm.js",
"gen-modules" : "npm run-script amd && npm run-script cjs && npm run-script esm",
"dist": "cp -r src/* dist/ && cat src/idiomorph.js src/idiomorph-htmx.js > dist/idiomorph-ext.js && npm run-script gen-modules && npm run-script uglify && gzip -9 -k -f dist/idiomorph.min.js > dist/idiomorph.min.js.gz && exit",
"uglify": "uglifyjs -m eval -o dist/idiomorph.min.js dist/idiomorph.js && uglifyjs -m eval -o dist/idiomorph-ext.min.js dist/idiomorph-ext.js"
},
"repository": {
Expand Down
27 changes: 3 additions & 24 deletions src/idiomorph.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
//=============================================================================
// UMD insanity... i hate javascript so much
//
// IGNORE EVERYTHING FROM HERE UNTIL THE COMMENT SAYING 'AND NOW IT BEGINS..."
//=============================================================================
(function (root, factory) {
//@ts-ignore
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
//@ts-ignore
define([], factory);
} else if (typeof module === 'object' && module.exports) {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals
root.Idiomorph = root.Idiomorph || factory();
}
}(typeof self !== 'undefined' ? self : this,
function () {
// base IIFE to define idiomorph
var Idiomorph = (function () {
'use strict';

//=============================================================================
Expand Down Expand Up @@ -865,5 +845,4 @@
morph,
defaults
}
}));

})();

0 comments on commit 6cc541f

Please sign in to comment.